Time-aware RAG: how I built AsOf to answer “what was the GST rule on date X?”
By Pranav T · · 4 min read
Short answer
A standard RAG pipeline retrieves the most similar text, so for versioned data like tax law it confidently cites a version that was not in force on the date asked. AsOf fixes this by making time part of retrieval: every chunk stores a validity date range, the date filter runs in SQL before the LLM sees anything, and every quote in an answer is checked against its source. On a 49-question benchmark it reached 64.1% answer accuracy versus 38.5% for a standard RAG, with 0% stale citations versus 28.6%.
Why does standard RAG give wrong answers for versioned data?
Most RAG tutorials teach you to retrieve the most similar text. For versioned data, that gets you a confident wrong answer.
Law is versioned. Rule 36(4) of the CGST Rules changed from a 20% provisional ITC cap to 10%, then 5%, and was later replaced entirely. A standard RAG pipeline returns whichever version sounds most similar to the question, cites a real notification, and is wrong for the date that matters.
The best way to learn Retrieval-Augmented Generation is to build it on a hard problem. So I built AsOf, an open-source, time-aware RAG system for Indian GST law. It answers one question: “What was the rule on date X?”
How do you make time part of retrieval?
Every chunk stores a half-open validity range [valid_from, valid_to) as a PostgreSQL daterange. The date filter runs in SQL, before the LLM sees anything:
SELECT id, text
FROM chunks
WHERE validity @> DATE '2020-02-15' -- only law in force on that date
ORDER BY embedding <=> :query_embedding
LIMIT 30;Leaving dates to the model doesn’t work, because it mixes versions. If an outdated version never reaches the prompt, the model can’t cite it.
Do you need a separate vector database?
No. PostgreSQL with pgvector handles all of it in a single query:
- HNSW vector search for semantic similarity
- Full-text search with
tsvectorand a GIN index for exact legal terms - Date ranges with a GiST index for the validity filter
- The amendment graph that links rule versions together
One database means one place to filter by date, and no syncing between a vector store and the source of truth.
How does hybrid search with Reciprocal Rank Fusion work here?
Three retrievers run side by side: vector similarity, keyword match, and explicit rule-reference matches (for example a question that names “Rule 36(4)”). Their rankings are merged with Reciprocal Rank Fusion (k = 60), which rewards documents that rank well in several lists without having to compare raw scores.
A cross-encoder reranker (Nemotron Rerank 8B) then narrows 30 candidates down to 8, with at most 2 chunks per document so one long notification can’t crowd out the rest.
How are amendments tracked?
An LLM extracts “amends”, “substitutes”, “omits” and “supersedes” relations between documents. Each relation must quote its source text verbatim, or it is discarded. The surviving relations become rule-version chains with validity dates, which is what fills in valid_from and valid_to.
How do you stop the model from inventing citations?
Trust nothing without a quote. Every quote cited in an answer is checked against its source, using an exact match or a fuzzy match of at least 85%, where numbers and negations must line up exactly. A quote that says “10%” can’t pass as one that says “20%”. If the sources don’t support an answer, the system declines instead of guessing.
How much better is it than standard RAG?
Same corpus, same LLM, same embeddings, on a 49-question benchmark:
| Metric | AsOf | Standard RAG |
|---|---|---|
| Answer accuracy | 64.1% | 38.5% |
| Correct document ranked #1 | 59.0% | 20.5% |
| Stale citations (law not in force on the date asked) | 0% | 28.6% |
What does it run on?
The whole stack runs on free tiers: Python, FastAPI, NVIDIA Nemotron for the LLM and embeddings, OpenRouter, and Neon Postgres.
Where else does this pattern apply?
Any versioned rulebook: RBI directions, SEBI circulars, insurance policy wordings, technical standards. Anywhere the right answer depends on the date, the date has to be part of retrieval, not something the model works out.
You won’t learn chunking, reranking or grounding properly from a diagram. Clone the repository, run asof ask in both modes, and see where the baseline breaks.
Frequently asked questions
- What is time-aware RAG?
- Retrieval-Augmented Generation that only retrieves text that was valid on a given date. Each chunk carries a validity range, and retrieval filters on it before the language model sees anything, so answers reflect the version in force on that date.
- Why not just tell the LLM the date in the prompt?
- Because the model still sees every version and mixes them. Filtering by date in the database removes outdated versions before generation, so they cannot be cited.
- Can pgvector replace a dedicated vector database for RAG?
- For many projects, yes. PostgreSQL with pgvector can run HNSW vector search, full-text search and date-range filters in one query, which keeps filtering and data in a single place.