Map mentions to stable entity IDs while retaining ambiguity, alias provenance and out-of-catalog behavior.
Entity linking for retrieval: resolve aliases before searching facts
Separate mention from identity
Entity linking maps a surface mention in a query to a canonical entity ID. 'P-47' might identify a pump in one plant and a permit in another; spelling alone is not identity. Store type, tenant, site, active interval and reviewed aliases with each entity. Preserve the original mention in the search trace, and do not replace it with a canonical ID until context establishes the match. Multilingual retrieval may supply transliterated aliases, but an alias can still be shared by distinct entities.
Generate candidates then decide
Exact alias search produces candidates. Type constraints, nearby words, site and time narrow them; semantic similarity can rank the remainder. Keep a no-match outcome for an unknown entity instead of forcing every mention onto the closest catalog entry. If two candidates remain plausible, ask for a clarifier or search both as explicitly separate interpretations. Conversation state can supply an antecedent, but an old assistant answer is not authoritative identity evidence.
Carry identity through evidence
After linking, retrieve passages tagged with the stable entity ID and current authorization scope. A document can mention several entities, so a page-level tag may be too coarse: the cited span must actually refer to the selected entity. If an entity is renamed, maintain alias history and effective dates rather than rewriting old documents. If IDs are merged or split, preserve the mapping event; otherwise historical citations can point to a different object. Chunk identity and entity identity solve different problems and both belong in the trace.
Guard against alias poisoning
User-submitted content may claim that an unrelated part number is an alias for a restricted asset. Accept aliases only from reviewed catalog changes, not from retrieved passages or prompt text. Apply access checks to candidate IDs and to their associated documents; even an ambiguous candidate list can leak a private device name. Normalize Unicode carefully, but do not erase distinctions that matter in identifiers. Tool boundaries keep source text from changing the resolver's catalog.
Evaluate more than top-one accuracy
Judge exact aliases, spelling changes, transliterations, shared names, unknown entities and historical renames. Measure candidate recall, correct-ID selection, abstention for unknown mentions, and downstream supported answers. A top-one metric alone rewards a resolver that confidently guesses on every unknown name. Track entity type and language slices separately. Review cases where linking is correct but the retrieved passage refers to a different entity in the same document; that is an evidence-span error, not a linking success.
Worked contract
from dataclasses import dataclass
import unicodedata
@dataclass(frozen=True)
class CatalogEntity:
entity_id: str
tenant: str
kind: str
site: str
aliases: tuple[str, ...]
def alias_key(value: str) -> str:
return unicodedata.normalize("NFKC", value).casefold().strip()
def resolve_entity(catalog: list[CatalogEntity], tenant: str, kind: str,
site: str, mention: str) -> str | None:
matches = [entry.entity_id for entry in catalog
if entry.tenant == tenant and entry.kind == kind and entry.site == site
and alias_key(mention) in {alias_key(alias) for alias in entry.aliases}]
if len(matches) > 1:
raise ValueError("ambiguous alias; request clarification")
return matches[0] if matches else None
catalog = [CatalogEntity("pump-47-north", "north", "pump", "plant-a", ("P-47", "Pump 47")),
CatalogEntity("permit-47-north", "north", "permit", "plant-a", ("P-47",)),
CatalogEntity("pump-47-south", "south", "pump", "plant-b", ("P-47",))]
assert resolve_entity(catalog, "north", "pump", "plant-a", "P-47") == "pump-47-north"
assert resolve_entity(catalog, "north", "pump", "plant-a", "P-48") is NonePerformance and operating cost
The transparent scan checks N catalog entries and up to A aliases per entry, costing O(NA) time with temporary alias sets. An alias index keyed by normalized mention, tenant and type reduces candidate lookup, but it must update atomically with catalog changes. Preserve multiple candidates until context resolves them; forcing one ID can be cheaper per query but costlier in downstream incorrect answers.
Common Mistakes
- Treating a shared alias as a globally unique entity ID.
- Forcing unknown mentions onto the nearest catalog item.
- Letting retrieved text edit the trusted alias catalog.
- Tagging a whole document as support when its cited span refers to another entity.
Validation drill
Create 83 mentions across two tenants and three entity types, including 17 ambiguous aliases and nine unknowns. Score correct IDs, ambiguity handling, unknown abstention and supported downstream passages.
