Prompt
I need to monitor RAG citation quality and context drift
Latest observation
Here’s a practical way to monitor both RAG citation quality and context drift in production.
1) What to measure
A. Citation quality
You want to know whether the model’s answer is actually supported by the retrieved sources.
Track:
- Citation coverage: % of answer claims that have at least one supporting citation
- Citation precision: % of cited claims that are truly supported by the cited chunk
- Citation recall: % of important answer claims that are cited
- Unsupported-claim rate: claims with no evidence in retrieved context
- Citation correctness: whether the citation points to the right document/chunk, not just a vaguely related one
- Answer-to-source entailment: do the sources entail the answer?
B. Context drift
You want to know whether the retrieved context is becoming less relevant over time, even if the model still sounds fluent.
Track:
- Query-to-retrieval relevance
- Retrieved chunk relevance distribution
- Context freshness / staleness
- Embedding drift between current queries and historical query clusters
- Topic drift in queries and retrieved documents
- Answer drift: are answers changing for similar queries over time?
- Retrieval stability: do similar queries retrieve similar chunks?
2) A useful monitoring pipeline
Step 1: Log every RAG interaction
Store, per request:
- user query
- rewritten query, if any
- retrieved document IDs
- chunk text
- retrieval scores
- final answer
- citation spans / citation IDs
- timestamps
- user feedback, if available
Step 2: Run offline evaluators
Use automatic checks on sampled traces:
Citation evaluation
For each answer sentence or claim:
- split into atomic claims
- compare each claim against cited chunk(s)
- label as:
- supported
- partially supported
- unsupported
- contradictory
Methods:
- NLI/entailment model
- LLM-as-judge with strict rubric
- lexical overlap as a weak baseline
- human review on a small sample
Context relevance evaluation
For each retrieved chunk:
- score relevance to query
- score relevance to answer
- measure rank of best supporting chunk
- flag irrelevant top-k retrievals
3) Key metrics to dashboard
Citation dashboard
- % responses with at least one citation
- avg citations per answer
- supported-claim rate
- unsupported-claim rate
- contradiction rate
- citation precision by model version
- citation quality by query type
- top failing source documents
Drift dashboard
- avg retrieval similarity over time
- average top-1 / top-k relevance score
- query embedding centroid shift
- topic distribution shift
- answer consistency for repeated or near-duplicate queries
- stale-document retrieval rate
- “no good context found” rate
4) Detecting context drift specifically
Drift signals
-
Embedding distribution shift
- Compare current query embeddings to historical baseline
- Use KL divergence, Wasserstein distance, or cosine centroid shift
-
Retrieval quality degradation
- Falling top-k relevance scores
- More empty/low-confidence retrievals
- Lower citation support rate
-
Topic drift
- Topic model current queries vs previous period
- New query clusters appear
- Existing clusters move semantically
-
Source drift
- New document set changes retrieval behavior
- Older sources dominate even when outdated
- Recently added docs are under-retrieved
-
Answer drift
- Similar queries yield different answers across time
- Increased variance in answer embeddings for similar inputs
5) Practical alerting rules
Start with simple thresholds:
- unsupported-claim rate > X%
- citation precision < Y%
- top-1 retrieval relevance drops by Z%
- stale-doc retrieval rate > threshold
- answer inconsistency for near-duplicate queries rises
- retrieval score distribution shifts beyond baseline
Trigger alerts by:
- model version
- index version
- document corpus version
- query class
- tenant / product area
6) Best evaluation setup
Use three layers:
Layer 1: Automated checks
Cheap, continuous, broad coverage
Layer 2: Human review
Sample:
- high-confidence failures
- random positives
- drift alerts
- high-impact queries
Layer 3: Golden set
Maintain a benchmark of:
- canonical queries
- expected supporting docs
- expected answer properties
- adversarial cases
- stale/outdated cases
7) Recommended implementation pattern
For citations
Make the model output structured data:
{
"answer": "...",
"claims": [
{
"text": "Claim sentence",
"citations": ["doc12#chunk4", "doc9#chunk1"]
}
]
}
Then evaluate claim-by-claim.
For drift
Compute weekly/monthly:
- query embedding stats
- retrieval score stats
- corpus freshness stats
- answer consistency stats
Compare against a baseline window.
8) Good first version
If you want a minimal but effective setup, start with:
- Log queries, retrievals, answers, citations
- Sample 200 traces/week
- Use an entailment judge on each cited claim
- Track unsupported-claim rate and citation precision
- Track top-k retrieval relevance and stale-document rate
- Alert on significant week-over-week drops
9) Example KPI definitions
- Citation precision = supported cited claims / all cited claims
- Citation coverage = cited claims / all answer claims
- Unsupported-claim rate = unsupported claims / all claims
- Retrieval relevance score = mean similarity of query to top-k chunks
- Drift index = distance between current and baseline query embedding distributions
- Stale retrieval rate = queries where top retrieved source is older than freshness threshold
10) Tools you can use
- RAGAS
- TruLens
- LangSmith
- Arize Phoenix
- custom eval pipelines with:
- embeddings
- NLI models
- LLM judges
- human review workflows
If you want, I can also give you:
- a concrete metric schema,
- a dashboard design, or
- a Python evaluation pipeline for citation quality and drift detection.