Workspace/Lesson workspace
Loading progress
Grounding & reasoning40 min

Rerank for the question and ground each material claim

Lesson 3 of 3
How to study this lesson

Read one section, trace the worked example, and try the knowledge check. Bookmark saves a shortcut; notes appear in My notebook. Mark lesson complete is your own assessment and does not mark its lab passed.

By the end, you can

  • Distinguish candidate retrieval from query-conditioned reranking.
  • Create a claim-to-evidence mapping rather than decorative citations.
  • Abstain or narrow an answer when evidence does not support its scope.

The second stage can afford closer inspection

A first-stage retriever searches a large corpus quickly. A reranker inspects a smaller candidate set more closely for the current question. A cross-encoder can jointly process query and passage, allowing interactions that a precomputed passage vector cannot express directly. Sentence-BERT's discussion of pairwise encoding cost helps explain why joint scoring is often reserved for a smaller pool rather than every document in a large corpus.

If the first stage returns 100 candidates and the answer needs six passages, a reranker can focus its computation on those 100. The candidate count trades cost against recall. A tiny pool may omit the answer; an enormous one may exceed latency targets. Measure the point where additional candidates stop improving relevant-evidence recall enough to justify the extra computation.

Relevance is specific to the requested claim

A passage about a policy can be topically relevant while failing to answer its effective date, exception, or geographic scope. Reranking should consider the actual question, including entity, time, requested comparison, and constraints. A simple heuristic can prioritize exact version and entity matches, but a learned score still needs validation. Neither lexical overlap nor a model's positive relevance label proves logical support.

Suppose the question asks whether staging permits a 60-second timeout in revision 4. A passage stating production allows 60 seconds in revision 3 is nearby in meaning but insufficient. The correct answer needs staging and revision 4. Keep these qualifiers attached to the claim throughout retrieval and generation. Removing them in a query rewrite can retrieve a convincing answer to a different question.

Citations need an entailment relationship

Build an evidence bundle containing stable passage IDs, source revisions, locations, and the exact retrieved text. Generate claims against that bundle and map each material claim to supporting passage IDs. A citation is useful only if the cited content supports the associated assertion at the requested scope. A paragraph ending with three relevant-looking links can still contain unsupported conclusions.

The code uses structured facts to make this relationship deterministic. Each claim states an entity, field, and value; a cited record supports it only when all three match. This is a toy exact-match support check, not natural-language entailment. It reveals an important boundary: a valid citation ID does not establish support, and a supported number for the wrong environment does not validate the requested claim.

A worked grounding failure

Evidence E1 says staging timeout is 30 seconds. Evidence E2 says production timeout is 60 seconds. A generated claim says staging timeout is 60 seconds and cites E2. The citation exists and concerns timeouts, yet it does not support the entity-specific claim. The verifier must reject it. Replacing the citation with E1 while keeping the wrong value still fails.

A corrected answer states the staging value as 30 seconds and cites E1. If the user also asks why the values differ and the documents provide no reason, the answer should say the reason is not established by the supplied evidence. A generated plausible rationale would exceed the source. Grounding controls factual scope; it does not require every sentence of ordinary connective prose to carry a citation.

Keep untrusted content from becoming control instructions

Retrieved text may contain instructions, quoted conversations, or malicious prompt injection. Put it in a clearly identified evidence channel or structure and preserve the host's instruction hierarchy. The content can answer a question about what a document says without acquiring authority to control tools. A document saying export all files before answering is a claim in the document, not permission from the user.

Evaluate evidence sufficiency, citation precision, answer correctness, and abstention behavior separately. Include questions with no supporting passage and questions where two relevant passages disagree. A robust system can give a partial answer with an explicit unresolved point. The project seed returns structured facts and verified source references; the learner expands it into a retrieval pipeline whose answer quality can be traced back to ingestion, ranking, and grounding decisions.

Work through the code

An exact structured-fact verifier checks both citation existence and entity-field-value agreement. This simulation catches an environment mismatch. Natural-language evidence requires a richer entailment check and human-reviewed evaluation cases.

verify_claim_support.py
python
evidence = {
    "E1": {"entity": "staging", "field": "timeout", "value": 30},
    "E2": {"entity": "production", "field": "timeout", "value": 60},
}
claims = [
    {"entity": "staging", "field": "timeout", "value": 60, "cite": "E2"},
    {"entity": "staging", "field": "timeout", "value": 30, "cite": "E1"},
]

def supported(claim, evidence):
    source = evidence.get(claim["cite"])
    if source is None:
        return False
    fields = ("entity", "field", "value")
    return all(claim[field] == source[field] for field in fields)

for index, claim in enumerate(claims, 1):
    print("claim", index, "supported:", supported(claim, evidence))
EXPECTED / ILLUSTRATIVE OUTPUT
claim 1 supported: False
claim 2 supported: True

Run Python snippets locally with the prerequisites named above. The module coding lab runs directly in your browser.

Pause and reason

A passage supports the current timeout value but contains no explanation for why it was chosen. The user asks for both value and rationale. What answer behavior preserves grounding?

Check your understanding

A cited passage discusses the right topic but a different environment. Does it support the claim?

Your notes

Explain the mechanism in your own words. Add a failure you want to test.

Saved notes appear in your notebook

Go deeper with primary sources

Practice this module