Similarity search returns the old policy because questions use its wording. Validity dates at ingestion and an as-of filter fixed 8 of 8 synthetic questions.
The most similar chunk is often the old one
Policies change, and the questions customers ask are phrased like the policy they remember. At Belgavi's Book Store the returns policy said, until 1 June 2026, that a book could be returned within 30 days for a full refund with free return shipping. The current policy allows 14 days and charges for return shipping unless the item arrived damaged. When a customer asks "Can I return a book within 30 days for a full refund?", the old chunk shares almost every word with the question. A retriever that ranks by similarity alone returns it first, and a model grounded on it gives a confident, outdated answer with a citation.
Re-embedding does not fix this, and neither does a better reranker, because both measure the same thing: how close the text is to the question. Which version applies is not a property of the text. It is metadata, and it has to be attached at ingestion and used at query time. This guide shows how, with a small runnable example that measures the effect on a synthetic corpus.
Attach validity at ingestion
Every chunk gets fields that come from the document management system, not from the text:
{"id": "returns@v2", "doc": "returns", "version": 2,
"valid_from": "2026-06-01", "valid_to": null,
"text": "Books can be sent back for 14 days after delivery. ..."}The rules are simple and must be enforced by the ingestion job:
valid_fromis inclusive andvalid_tois exclusive, so on 1 June 2026 exactly one version of the returns policy is valid.- Publishing a new version sets
valid_toon the previous one in the same transaction. A corpus where two versions of a document are valid on the same day is a data error, and a test should fail on it. - A withdrawn document gets a
valid_toand no successor. It stays in the index for as-of questions.
Keep superseded versions in the index. Deleting them looks tidy and breaks every question about the past, which a help desk gets constantly: orders placed in March are governed by the March policy.
Four retrieval strategies, measured
The companion example superseded_document_retrieval ranks a seven-chunk corpus with a deliberately simple bag-of-words cosine scorer, so the effect of metadata is not hidden by a model. It asks eight questions. Six are about current policy and two are as-of questions, about an order delivered in March 2026 and about January 2026. The as-of date comes from the order record in the fixture, not from parsing the question.
| Strategy | Correct of 8 | Answered from the wrong version |
|---|---|---|
| Similarity only | 3 | 5 |
| Demote superseded chunks (score × 0.5) | 4 | 2 |
| Keep only versions valid today | 6 | 0 |
| Keep versions valid on the question's as-of date | 8 | 0 |
Similarity alone returned the 30-day returns policy for the 30-day question and the free-return-shipping version for "Is return shipping free?". Both are the old wording. It also returned the 2024 shipping policy for the January 2026 question, because "free shipping threshold" matches its phrasing better than the version that was in force.
Demotion is the strategy many teams try first, and it is not enough. Halving the score of superseded chunks still let the 50-dollar shipping version win "Do orders over 50 dollars ship free?" over the current 60-dollar one, because the question quotes the old number. Demotion also broke the as-of question about March, which the plain filter does not attempt at all.
Filtering to versions valid today fixed every current question and, by construction, failed both as-of questions: it retrieved unrelated chunks because the right ones were filtered out. Filtering on the as-of date answered all eight.
The query-time filter
Apply the filter as a metadata condition inside the search where your vector store supports it. A filter applied after a top-k search can leave fewer than k results, or none, when most of the nearest chunks are superseded:
def valid_on(chunk, day):
start = date.fromisoformat(chunk['valid_from'])
end = date.fromisoformat(chunk['valid_to']) if chunk['valid_to'] else None
return start <= day and (end is None or day < end)
as_of = order.delivered_on if question_refers_to(order) else today
hits = index.search(query_vector, k=5,
filter=lambda c: valid_on(c, as_of))Where the as-of date comes from matters more than the filter. The safest source is structured context the application already holds: the order the conversation is about, the date the case was opened, the contract start date. Let the model extract a date from free text only as a fallback, validate it against the conversation's records, and log it, so a wrong date is visible in the trace.
When only part of a document changes
Real policy updates rarely replace a whole document. The returns policy might change its window and leave the paragraph on damaged items untouched. Two designs handle this, and the choice affects the metadata:
- Version the whole document. Every chunk of the new version gets the new
valid_from, including unchanged ones, and every chunk of the old version getsvalid_to. The index holds duplicate text for the unchanged sections, but each version is complete and the as-of filter stays simple. This is the right default. - Version sections. Each chunk has its own validity, and only changed sections get a new version. The index is smaller, but answering an as-of question means assembling the sections valid on that date. A bug in one section's dates makes the assembled document inconsistent, for example a 14-day window next to a reference to the old free shipping.
Whichever you choose, keep a document-level version number on every chunk so you can always tell which release of the policy a chunk belongs to. Cite it in answers and logs; it is what a support lead will ask for when a customer disputes an answer.
What the answer should say
Even with the right chunk, the answer should name the version it relied on. "Under the returns policy in effect since 1 June 2026, you have 14 days" is checkable. When the question mentions the old rule, the answer can say so explicitly: "The 30-day window applied to orders delivered before 1 June 2026." That sentence is only possible if the retriever returns both versions on purpose, so for questions that mention a figure, consider retrieving the current version and the version the figure came from, labelled as such.
Measure staleness, not only relevance
Standard retrieval metrics ask whether a relevant chunk was retrieved. Here the old chunk is relevant by every text measure and still wrong. Add a metric that counts answers grounded on a version not valid on the as-of date. Build the evaluation set from real phrasings: take questions from case logs that quote old figures, and pair each with the version that should answer it. The example's wrong_version count is that metric in miniature.
Failure modes
- Ingestion without dates. Documents scraped from a wiki often have no effective date. Default them to the publication date and flag them for review; do not leave
valid_fromempty. - Two valid versions. A failed publish job leaves both open. The example's test checks that exactly one version per document is valid on each boundary date. Run the same check on the real index nightly.
- Chunks without the document id. If chunks of the same document cannot be grouped, supersession cannot be applied. The id belongs in every chunk's metadata.
- Caches. A semantic answer cache built before the policy change keeps serving the old answer. Key cache entries by the versions they were grounded on and invalidate them when a version closes.
- Time zones. A policy effective "from 1 June" in one time zone is already effective earlier elsewhere. Store the boundary as a timestamp with a zone if customers span zones.
How to verify on your system
Pick the last three policy changes. For each, write five questions in the old phrasing and two as-of questions, and run them through the full pipeline. Count wrong-version answers before and after adding the filter. Then close a document version in a test environment and confirm that the next query no longer returns it for current questions, and still returns it for an as-of date before the change.