Why a Code Hit Is Not Yet an Answer

Engineering retrieval has to bind results to a repository, a commit, and a symbol; a hit that is missing, stale, or from the wrong repository is only a locating lead.

On this page · 10 sections

The illusion semantic retrieval creates most easily is letting "very similar" pass for "this is it." A large engineering codebase contains same-named methods, copied modules, old paths that have since been deleted, and cross-repository contracts. A very high similarity score says only that the text is close; it does not say the hit belongs to the target repository or the current commit, and it does not prove a call relationship between two symbols.

The job of canonical resolution is to establish stable entities before retrieval, bind independent evidence to relationships, and, at query time, downgrade results whose version is uncertain to locators (that is, leads used only to find an entry point).

The Short Version

  • A high similarity score says only that the text is close; it does not say the hit belongs to the target repository or the current commit, and it does not prove a call relationship between two symbols.
  • Entity identity (the canonical ID) is stored apart from the evidence of "which version, and where it was seen"; every edge has at least one piece of evidence, and a VERIFIED edge needs evidence with verification=verified.
  • A hit diagnosed as missing, stale, wrong_repo, or unknown can be used only to find an entry point; if any graph path check fails, the query reports stale or evidence missing instead of a "mostly correct" call chain.
  • Known gap: the actual CPG _node_id() encodes the line into its hash, so a symbol that moves lines changes its node identity; full cross-version stability cannot be claimed yet.

Knowledge Map for This Article

Canonical resolution knowledge map: source keys merge into a canonical node, revision and location form an evidence locator, and together they make an evidence-backed edge; only VERIFIED reaches the verified path, the rest stay candidates or locators; open the full-size SVG

The core topics are stable entity identity, revision evidence, confidence tiers, exact identifiers, conflict handling, and the verified path.

Entity Identity and This Version's Evidence Must Be Kept Apart

The canonical key of the target code_symbol_id() is made up of the workspace, repository, language, relative path, kind, and qualified name. The commit SHA, line range, and content hash do not go into this helper's symbol ID; they go into the evidence revision/locator.

This lets the system express two things at once:

  • RebuildProjectionJob is a logical entity that stays stable across commits;
  • what I am citing right now is the one observation at path:line in commit x.

If the line were put into the entity ID, moving the code by one line would produce a new entity; if the commit were not stored at all, an old index would masquerade as the current implementation. Canonical identity is responsible for merging "the same object"; evidence is responsible for preserving "which version, and where it was seen."

The current implementation has not fully reached this target: the actual CPG (Code Property Graph) _node_id() encodes the line into its hash, so a symbol that moves to a different line changes its CPG/canonical node identity. The existing stable-ID tests cover the helper, which is not the same as the actual CPG nodes being stable.

This is a real identity gap. The CPG producer and the canonical helper will need to converge later; the answer is not to write the target contract up in this article as an accomplished fact.

The Canonical Graph Is Not a Web of Relationships Without Sources

The current SystemGraph separates nodes, edges, and evidence:

CanonicalNode: id / kind / name / source_keys / properties
CanonicalEdge: source / target / relation / confidence / evidence_ids
Evidence: source_record_id / locator / excerpt_hash / revision / cas_uri / verification

Every edge must have at least one piece of evidence. A VERIFIED edge must additionally be associated with at least one piece of evidence with verification=verified; when there is only candidate evidence, the code refuses to create a verified edge.

When the same canonical node appears from multiple source keys, its source keys and properties are merged; a kind conflict raises an error, so a page and a method are never fused into one object because they share a name. A duplicate evidence ID whose locator, excerpt hash, revision, or CAS URI is inconsistent likewise raises an identity conflict.

Evidence sketch: resolver CALLS provider, two repo + commit + file + line evidence records support the node and the edge, and Jira supplies context only; open the full-size SVG

Jira can prove the background of a requirement; it cannot substitute for code edge evidence. Confluence can explain a business rule; it cannot promote an AMBIGUOUS call to VERIFIED.

Why an Exact Match Still Has to Be Checked Against Repo and Commit

An exact hit on RebuildProjectionJob is stronger than a semantic hit on "the job that rebuilds projections," yet it still has three anchors:

  • Expected repo: did the hit come from the target repository?
  • Expected commit: does the index correspond to the revision I am currently trying to explain?
  • Exact symbol: does the payload really contain the target symbol, rather than merely mentioning it in a summary?

The read-only locating command can pass these constraints explicitly:

rtk uv run --frozen --offline --no-sync --python 3.11 \
  python -B -m mt_rag.cli retrieve-qdrant-policy "RebuildProjectionJob" \
  --source-type code --embedding-backend local-qwen \
  --local-files-only --no-write \
  --expected-repo "<target-repository>" --expected-commit "<current-head>" \
  --exact-symbol RebuildProjectionJob

--no-write creates no query log or result file, --local-files-only forbids ad hoc access to the model repository, and offline/no-sync avoids installing dependencies.

When the diagnosis is missing, stale, wrong_repo, or unknown, the result can be used only to find an entry point; it cannot support the conclusion that "this is how the current system works."

How a Graph Path Stays Fail-Closed

Before looking up a path, the system graph query verifies three layers of version:

  • the graph projection manifest must correspond to the current source manifest;
  • the graph consumer cursor must equal the current generation;
  • Neo4j must contain a complete marker with the same projection hash.

The Cypher path then requires that:

  • every node belongs to the active projection;
  • every relationship has confidence='VERIFIED';
  • every relationship has at least one evidence ID;
  • after the result returns, each SystemEvidenceV1 is loaded one by one to confirm that every required piece of evidence exists and is verified.

If any condition fails, the query reports stale or evidence missing; it does not return a call chain that is "mostly correct." The path also starts from the graph_ids of the highest-ranked retrieval entity, rather than borrowing a true but off-topic relationship from a secondary candidate.

After a Hit, the Real Verification Begins

Suppose retrieval returns a resolver:

  1. First look at the payload's repo, commit, file, line, and symbol;
  2. Go back to the current target commit, open the file, and confirm the signature and the actual body;
  3. Keep reading along the imports, provider, GraphQL schema, or HTTP contract;
  4. When the graph has a verified edge, check its evidence locator;
  5. When the question concerns production behavior, the static chain is still not enough at this point; deployment and runtime readback are needed.

A RAG hit is like a map; the canonical ID is the coordinates; revision evidence is the map's edition; the current source and the runtime are the actual site.

Failure Modes and Trade-offs

The left column below is the diagnosis or failure symptom; focus on the right column, the correct next step in each case.

Diagnosis Meaning Correct next step
missing The index does not have the expected entity Search the current repo; check for a rename or extractor coverage
stale The hit does not correspond to the expected commit Use the old path only for locating, and re-trace in the current commit
wrong_repo Same-named content comes from another repository Switch back to the target repo; do not stitch together a cross-repository conclusion
unknown Identity or currentness cannot be confirmed Mark it explicitly as unknown; do not raise confidence
AMBIGUOUS edge Static analysis saw only the call name Keep it as a candidate; it does not enter the verified chain
Graph cursor lag The vector side is new, the graph is old Text candidates can be shown; the call chain must report stale
Canonical kind conflict A source key was resolved to different entity types Block the merge and fix the resolver/schema, rather than letting the last write win
CPG node ID contains the line number A symbol that merely moves lines may also generate a new entity Currently a known identity gap; full cross-version stability cannot be claimed

Canonical resolution adds the cost of ID design, schema, and conflict handling, but it avoids the most dangerous error: writing up an object that really exists but belongs to the wrong version as the current answer.

Verifiable Project Evidence

  • src/mt_rag/core/stable_ids.py: stable IDs for sources, repositories, code files/symbols, and so on;
  • src/mt_rag/system_graph/canonical.py: canonical nodes/edges/evidence, conflicts, and the verified path;
  • src/mt_rag/retrieval/system_index.py: the source ID, locator, graph IDs, and commit currentness in the payload;
  • src/mt_rag/system_graph/query.py: the manifest/cursor/projection gate and verified-only Cypher;
  • docs/02-runbooks/retrieval-usage.md: expected repo/commit/exact symbol and locator-only diagnoses;
  • docs/03-reference/code-cpg-system-graph-v1.md: the full CPG, the semantic CPG, and the confidence contract.

References

The quality of engineering RAG depends not only on whether similar content was found, but even more on whether the system can prove which entity this is, which version was observed, which relationship holds, and where the evidence ends.

Related notes

Working on something similar?

I'm always happy to compare notes on distributed systems, delivery, and applied AI.

[email protected]