RAG for technical documentation: questions, sources and answer verification

Twenty fixed questions against a synthetic corpus: a BM25 baseline, explicit metric denominators and automated review of model answers; human review is pending.

A retrieved passage is checked against a specific question.
A retrieved passage is checked against a specific question.

When a system retrieves three passages from documentation, displaying three links beside its answer is easy. That still does not establish whether it found the necessary rule, whether the rule addresses the question, or whether it supports what the model wrote. One particularly misleading case is a valid link next to a claim that the document never makes.

The paper on retrieval-augmented generation combines retrieval of external passages with text generation. For your own technical documentation, it helps to evaluate these parts separately: first the availability of evidence, then its use in a particular answer.

This independent exercise uses Python and its standard library. Retrieval was executed and model answers were obtained for 20 predefined questions. The retrieval metrics describe a baseline; the answers separately underwent automated editorial review, while the owner's human review remains pending.

Freeze the questions before the first result

The corpus consists of 20 short English sections for a fictional system called Harbor Notes. They describe a network port, attachments, backups, tokens, background jobs and exports. The collection includes a current contract, an archived revision, an unaccepted proposal and two conflicting current instructions. All data was written for the exercise; it is not documentation for a real product.

The retrieval unit is a complete section with a title, text, status and revision reference. No further chunking takes place. This makes the content of each result easier to inspect, but it does not establish that this passage size would suit a large documentation library.

Exactly 20 questions and editorial judgments were written separately from the retrieval code. Each question has required sources, a reference answer, required facts and claims the sources do not permit. The corpus, questions, judgments and protocol were frozen before ranking was implemented and before the first evaluation. They were not changed after inspecting the result.

Question type Count What a future answer must preserve
Has a definite answer in the corpus 15 Required facts and their supporting sources
Leaves a term ambiguous 1 A clarification request instead of an arbitrary choice
Has conflicting evidence 1 Both values and the unresolved disagreement
Has no required evidence 3 Explained uncertainty without invented details

This is an authored diagnostic set, not an independently annotated representative benchmark. Its judgments can contain errors too. Their value is that they exist before the result and are not adjusted to fit what was retrieved. A reference answer in that file is a condition for later review; it is not an answer obtained from a model.

Retrieval must not see the expected answer

A separate program ranks section titles and text using the question text. It does not read the judgments file. The question identifier connects report rows but does not select a document. An additional check ran all 20 queries in a directory without the judgments or evaluator and produced identical results.

The baseline uses lexical BM25 with k1=1.2 and b=0.75. These parameters and the inverse document frequency formula can be checked against the Apache Lucene documentation. Our small Python program does not reproduce Lucene's entire implementation: it has none of its indexing, analyzers or length encoding.

Text is transformed with casefold, split into alphanumeric words, and filtered through a predefined list of common English words:

def tokens(text):
    return [token for token in re.findall(r'[^\W_]+', text.casefold()) if token not in STOPWORDS]

There is no stemming, synonym handling, embedding model or query expansion. Each distinct question term contributes once. The result contains up to three sections with positive scores; zero-score candidates are not added to fill the list. Equal scores are ordered by source reference.

Document status is returned as metadata available for subsequent context, but it neither boosts nor reduces the retrieval score. An archive or draft can therefore appear in the top three. This search measures lexical similarity; deciding whether a source is authoritative needs its own rule. The highest score does not make a document authoritative.

The denominator determines what a number means

For each question, we count how many returned sections belong to its predefined relevant set. Precision@3 divides this count by 3 even when fewer results were returned. The precision implementation in NIST trec_eval explicitly describes this treatment of unfilled positions. The average for our 20 questions therefore has 60 positions in its denominator.

For one question, Recall@3 divides the relevant sections found by the number of all sections judged relevant to that question. We then average 17 such fractions. Those 17 include ambiguity and conflict: justified uncertainty also needs evidence. The three questions with empty relevant sets have recall=null; they do not receive an automatic score of one.

We separately calculate Hit@3: whether at least one required source was found. That differs from covering the whole set; the ir-measures documentation explains this distinction between Recall and Success. Our exercise also records a stricter measure: whether every source required by the judgments was returned.

Measure from the actual retrieval run Result Counting scope
Mean Precision@3 21/60 = 0.35 All 20 questions, with 3 positions each
Mean Recall@3 16/17 ≈ 0.9412 17 questions with nonempty relevant sets
Hit@3 16/17 ≈ 0.9412 At least one required source
Complete required-evidence coverage 16/17 ≈ 0.9412 Every source required for that question
Empty result when evidence is absent 2/3 Only the 3 questions with empty relevant sets

The three equal values arose from this particular outcome: 16 questions received their entire required set, while one received no relevant section. In another run these measures could diverge. Precision@3 includes unfilled positions, so its shortfall from one is not solely the proportion of irrelevant documents actually returned.

Individual questions expose useful failures

The question about the application port ranked the documentation website section first. The required section specifying port 8088 came second; the unrelated port 8443 belonged to another service. Evidence coverage was complete, but an answer mechanically taken from the first result would have been wrong. The retrieval score does not interpret negation in the question as a selection rule.

For How long is a token valid?, retrieval returned two meanings of the term. A pagination cursor lasts 15 minutes, while an API token remains valid until revoked; the old API token has a separate five-minute grace period after rotation. The judgment requires clarification of which token is meant. Choosing either number would lose an ambiguity that the sources make visible.

The worker-attempts question found both a policy stating 3 attempts and a runbook stating 5. Both documents are marked current, with no supersession link or precedence rule. Retrieval supplied the evidence needed to report a conflict. Whether an answer preserves that conflict must be assessed separately from retrieval itself.

By contrast, Which file layout does a downloaded collection use? retrieved collection cache and metadata sections. The export-format section was missing, although it is the source that specifies UTF-8 JSON Lines. This is a preserved failure of the lexical baseline, not a reason to rewrite the question after execution. Synonym handling or another retriever should be evaluated as a separate comparison.

A certification question also returned passages containing the product name, although none established certification. A nonempty list therefore does not establish that an answer is available. Empty lists for two other questions do not themselves measure refusal quality either: that requires separate assessment of the model's answers.

From sources to a verifiable answer

The CPython 3.12.3 run preserved all 20 retrieval rows. The 26 separate mechanics checks do not enter the metric denominators. The JSON boundary now rejects numeric overflow and escaped lone surrogates. Six shared regression methods are counted separately; an explicit fault injection checks the decoder-error contract. No actual crash on bounded deeply nested JSON was observed. Frozen data, judgments and ranking remained unchanged.

For the same 20 questions, 20 outputs were obtained through the Responses API using gpt-6.1-sol. The input contained only the question and up to three complete retrieved passages, with no gold data, tools or retries. The calls used store=false; the maximum of 800 output tokens was chosen before calling, and answers were limited to 120 English words. The largest serialized context was 1068 bytes against an 8192-byte limit. Exceeding the limit stops the step without silently truncating a source. All 20 outputs were JSON-schema valid.

Automated editorial review inspected the actual factual sentences and cited sources: 19 answers satisfied the semantic criteria and one failed. For Q16, the required export source was not retrieved: the unknown answer was grounded in the limited context but failed the full-corpus task. For Q20, the model asked for clarification rather than inventing a meaning, but this differed from the frozen unknown label. Exact decision labels mismatched for Q16 and Q20; the gold was not changed. These are diagnostic observations, not an overall RAG quality claim.

Checking factual claims against cited passages must account for required facts and prohibited inventions. Matching the reference wording or producing valid JSON does not replace that review. The automated editorial review is not an independent human review: the owner's review under the protocol is still pending, so the aggregate assessment is partial. Grounding in the supplied context and success on the full-corpus task must remain separate assessments.

The result provides a concrete basis for further work: a reproducible source list, a preserved paraphrase failure, and visible cases of ambiguity and conflict. The next change should identify the particular gap it addresses and face the same questions without hiding unsuccessful rows.

  1. Knowledge & AI Context for one task: how to avoid sending the whole platform to a model
  2. Knowledge & AI A retrieved document is not yet a current decision: freshness in knowledge search
  3. Knowledge & AI AI task quality: a small case set instead of one successful run
  4. Knowledge & AI A document tells the model to ignore the rules: testing the untrusted-context boundary

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article