Turning Retrieval Candidates into an Engineering Conclusion You Can Deliver

Retrieval finds the entry point and the original source confirms the fact; the final answer must keep verified, inferred, and unknown apart.

On this page · 12 sections

After local RAG returns its results, the most dangerous move is to hand every fragment to a large model and ask it to “summarize more completely.” Fluency hides the differences between sources: a goal from Jira, an old design from Confluence, and a same-named method from a different commit get joined into a story with no obvious flaw.

mt_rag calls retrieval results evidence candidates. The job of developer output is not to polish the candidates. It is to turn them into an engineering conclusion that can be located, can be declined, and can be evaluated.

The Short Version

  • Retrieval results are only evidence candidates; deterministic code first produces DeveloperAnswerV1, and Codex may organize the wording but may not change the chain, the confidence, or the citation IDs.
  • The answer is complete only when a full verified path exists; otherwise it is partial or insufficient, and no call chain is generated.
  • There are at most 10 citations, spent first on covering every edge of the call chain; confidence comes from a fixed formula that the LLM cannot raise.
  • Evaluation is split into at least four layers: retrieval, graph, grounding, and citation. Production cutover has not been performed, and readiness must be reported separately from live effectiveness.

Knowledge Map for This Article

Retrieval hits pass through the verified path into the canonical DeveloperAnswerV1, which splits into six parts that feed the human-readable answer and then evaluation; open the full-size SVG

This chapter covers claim-to-evidence, deterministic confidence, the citation contract, human-first rendering, observability, and layered evaluation.

The Canonical Answer Comes Before the Visible Write-up

System Shadow first has deterministic code produce DeveloperAnswerV1:

status = complete | partial | insufficient
call_chain
code_with_chinese_comments
overall_confidence
citations (at most 10)
limitations
summary_facts

The evidence decides the value of status. A verified path here is a call path whose every edge has verified evidence:

  • complete: only when a full verified path exists.
  • partial: no path, but there is locatable material.
  • insufficient: not even a locatable citation.

When the controller's final action is neither answer nor rerank, force_insufficient is applied: even if retrieval hit plenty of similar text, no call chain is generated.

This structure is the factual contract. Codex may organize it into more natural Chinese prose; it may not change the chain, the confidence, or the citation IDs.

Why the First Two Sections of the Human-Readable Output Are Fixed

The visible answer currently requires:

  1. 业务 Summary (business summary): states concretely what it does, the input or trigger, the core processing logic, and the result or impact.
  2. 简约调用链 (compact call chain): one verified entry --> processing --> destination.
  3. Code, confidence, citations, limitations, and machine data.

Summary and chain come first so that an engineer reads the conclusion first. Machine diagnostics come later so that a screenful of retrieval counts does not stand in for a business explanation. But the summary may use only summary_facts; being written for people does not license adding new business rules.

When there is no verified chain, the second section states explicitly: “Insufficient evidence; no call chain was generated.” That sentence is not a failed experience. It is a correct completion state: the reader knows that what is missing is relationship evidence, rather than assuming the system forgot to show it.

Citations Must Cover the Chain, Not Decorate the Answer

Citations come from two kinds of source:

  • Article evidence: page/section/issue, with source record, URL, and locator.
  • Code evidence: repo, file, class/method, line, and commit.

System Shadow returns at most 10, ordered as follows:

  1. First, the first piece of evidence for each edge of the selected verified path.
  2. Then other path evidence.
  3. Only last, related retrieval hits.

The citation budget is thus spent first on supporting the call chain, not on displaying ten similar pages.

If the required evidence for an edge does not make it into the final citations, the answer is downgraded to partial and the gap is written into the limitations. If the locator, revision, or verification of any path evidence is incomplete, the entire path stays out of call_chain.

Confidence Is Not the Model's Self-Assessment

When a verified chain exists, the overall confidence in System Shadow is composed of four parts:

0.40 base for a verified chain
+ 0.25 * edge evidence coverage
+ 0.20 * retrieval quality
+ 0.15 * source currentness

Retrieval quality looks at whether the top ten hits come from both the vector and keyword lanes. Source currentness uses freshness for Confluence and commit currentness for code. Without a chain, confidence is capped at 0.49 and rises only slightly with the number of locatable citations.

This formula is not a probability-calibrated “answer accuracy.” It is a repeatable engineering signal. Its important properties are:

  • The LLM cannot raise it.
  • The same evidence input yields the same value.
  • There is an explicit ceiling when the verified path is missing.

Interpreting it as a probability later would still require reliability diagrams (that is, calibration plots of confidence against actual correctness) and calibration against a genuinely labeled set.

Why the Output Code Expresses Only Order

The current code section generates:

const verifiedCallChain = [
  "entrySymbol", // entry point
  "providerMethod", // reaches the final destination via CALLS
] as const; // expresses only the verified order

It deliberately does not generate parameters, return types, error handling, or runtime values, because a graph path proves only node order and relations. Unless those details are verified item by item in the code evidence, filling them in would widen the claim surface.

A real development task should still open the current repo to verify signatures, tests, and config. RAG output shortens the time to find the entry point; it does not replace a review of the current working tree.

Three Kinds of Observability Data Must Not Be Mixed

The current system distinguishes three kinds of observability data. Look at the last column: their retention and use differ.

Observability surface What it records Retention/use
Generation trace Inputs and outputs of each refresh step, checkpoints, adds/deletes/updates, errors Partitioned by run, with a retention policy on the order of months
Query log Rewrite, search, Neo4j, controller, rerank, and aggregate events Partitioned by query, with a retention policy on the order of months
Durable lineage Manifest, traceability, checkpoints, event journal Not cleaned up by runtime-log retention

Runtime logs answer “what happened this time.” Durable lineage answers “which inputs produced the current projection, and where to replay from next time.” Treating the query log as the source of truth means losing re-entrant state once the monthly retention policy cleans it up. Treating the durable journal as a UI log makes a single slow request hard to investigate.

Evaluation Must Separate Retriever, Graph, and Generator

A final answer can be correct by accident while resting on the wrong citation. Equally, the retriever can find the right document while the generator fails to cite the key claim. So there are at least four layers, each with its own metrics and focus:

Layer Suggested metrics Focus in this project
Retrieval Recall@K, MRR, exact top-1, repo/commit match The separate contributions of dense, keyword, and exact
Graph Anchor coverage, verified path coverage, false path rate No candidate edge may pose as a chain
Grounding Claim faithfulness, unsupported claim rate The summary uses only canonical facts
Citation Citation correctness, completeness, locator validity Whether edge evidence is covered

Unanswerable queries must also be part of the evaluation, to measure insufficient precision. Testing only “questions the system knows the answer to” encourages it to generate content for every input.

One recent complete shadow generation passed the local integrity checks, with both the vector and graph cursors at the current version. That is neither a permanent scale figure nor a production accuracy metric. Production cutover has not been performed, and readiness must be reported separately from live effectiveness.

That snapshot also exposed an evaluation gap worth preserving: the shadow's retrieval overlap did not reach the threshold of the general readiness gate, yet the production validator could still judge it ready, because it uses a different citation-coverage condition.

The two gates are inconsistent. The right response is not to pick the better-looking result. It is to unify the definition, and until then to scope ready=true to “the internal consistency check of the current production validator passed.”

Failure Modes and Trade-offs

Each row below is one failure. Look at the last column: what each output behavior costs.

Failure mode Output behavior Trade-off
Hits but no verified path Partial/insufficient; no chain is generated Fewer guesses, preserving the correctness of call relationships
Citation locator missing Not included as a citation May reduce the number of references, but each one can be traced back
Edge evidence exceeds 10 Cover the path first; mark the uncovered gap The citation budget is capped; complex branches need a separate in-depth report
Codex changes the chain/confidence Rejected; the deterministic renderer is used Readability drops; canonical facts are unchanged
Summary contains only source titles/statistics Treated as not concrete; fallback What is needed is better evidence, not fancier wording
Query log expired Returns an explicit expired status; durable lineage is retained Controls disk usage without breaking replay
Shadow ready Still no automatic cutover Release speed yields to independent authorization and production readback
The two readiness gates have different thresholds Report the specific validator, overlap, and citation coverage Avoids misreading an internal-integrity flag as a unified quality bar

Verifiable Project Evidence

  • src/mt_rag/query/answer.py: DeveloperAnswerV1, the verified chain, citations, confidence, and limitations.
  • src/mt_rag/query/runtime.py: the canonical answer, Codex organizer validation, and the fallback renderer.
  • src/mt_rag/core/observability.py: generation trace, query log, and retention.
  • src/mt_rag/system_graph/query.py: path evidence completeness.
  • docs/02-runbooks/local-llm-service.md: external strict output, streaming progress, and the query log contract.
  • Local readiness artifacts: the generation, cursor, and blocker state of one shadow run.
  • docs/05-reports/phase-2-through-11-completion-report.md: tests, re-entry, rollback, and the not-yet-cut-over boundary.

References

What local RAG ultimately saves is the time spent finding evidence, not the time spent verifying. An answer can be incomplete, but every conclusion it does write down should know which piece of verifiable evidence supports it.

Related notes

  • 13 min readWriting

    LLM Runtime: Which Layer Should Own Rate Limits, Retries, and Routing

    Once the second business, the second provider, and the second tenant show up, calling the SDK directly is no longer enough. This piece covers the responsibility boundary of an LLM Runtime, multi-model routing, reliability under high concurrency, and how to choose an observability approach.

  • 13 min readWriting

    Local RAG Design: Store the Evidence First, Then Retrieve

    How mt_rag separates replayable evidence, rebuildable query views, verified graph paths, and bounded generation—and why current source still wins.

Working on something similar?

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

[email protected]