src.dackar.RCA.ner.hybrid_ner.llm_disambiguator

Classes

LLMConfig

LLMDisambiguator

Module Contents

class src.dackar.RCA.ner.hybrid_ner.llm_disambiguator.LLMConfig[source]
use_cli: bool = False[source]
cli_binary: str = 'ollama'[source]
http_url: str = 'http://localhost:11434/v1/chat/completions'[source]
model: str = 'ollama/gpt-oss:20B'[source]
timeout: int = 10[source]
temperature: float = 0.0[source]
max_tokens: int = 64[source]
stop_sequences: List[str] | None = None[source]
min_confidence: float = 0.15[source]
cache_ttl_seconds: int = 3600[source]
dry_run: bool = False[source]
uncertain_score_floor: float = 0.4[source]
uncertain_score_ceiling: float = 0.65[source]
high_conf_bypass_score: float = 0.85[source]
class src.dackar.RCA.ner.hybrid_ner.llm_disambiguator.LLMDisambiguator(schema, config=LLMConfig())[source]
Parameters:
schema[source]
config[source]
_cache: Dict[str, Dict[str, Any]][source]
llm_ok = True[source]
should_call(c)[source]

Decide whether to invoke the LLM for this candidate span.

Decision logic (in priority order): 1. High-confidence gazetteer hit exists → bypass LLM entirely (trust deterministic match). 2. No proposed labels at all → ask LLM (span has no evidence). 3. All hypotheses lack a known schema group → ask LLM (labels are unrecognised). 4. Multiple competing schema groups → ask LLM (genuine ambiguity). 5. Best score in the uncertain confidence band → ask LLM (embed result is marginal). 6. Best score below the floor → do NOT ask LLM (span is too weak; LLM would speculate). 7. Best score above the ceiling → do NOT ask LLM (embed is confident enough).

Parameters:

c (src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan)

Return type:

bool

_build_prompt(doc_text, c, candidate_labels)[source]
Parameters:
Return type:

str

_label_short(lbl)[source]
Parameters:

lbl (str)

Return type:

str

_cache_key(c)[source]
Parameters:

c (src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan)

Return type:

str

_extract_json_object(s)[source]

Some models occasionally wrap JSON with extra text. Try to recover the first {…} object.

Parameters:

s (str)

Return type:

Optional[Dict[str, Any]]

disambiguate(doc_text, candidates)[source]
Parameters:
Return type:

None

_call_llm_for_candidate(doc_text, c)[source]
Parameters:
Return type:

Optional[Dict[str, Any]]

_parse_llm_response(resp, c)[source]
Parameters:
Return type:

Optional[src.dackar.RCA.ner.hybrid_ner.models.LabelHypothesis]

health_check()[source]
Return type:

bool