Ask where a RAG system is likely to be weak and most engineers point at retrieval: the embeddings aren’t good enough, the chunking splits context awkwardly, the top-k ordering puts the wrong document first. All of that is real and worth fixing. It’s also the easier half, because retrieval quality is easy to measure: hold out a labeled query, check which documents came back, and score precision and recall. The harder half doesn’t show up in that score. Even when retrieval returns exactly the right document, the generation step can drift from it, adding a detail the source didn’t say or stating something the source only implied. A system can do well on retrieval and silently fail on faithfulness.
Retrieval quality work
Here is real retrieval-quality engineering, which is worth doing. A RAG chat platform’s reranker takes Pinecone’s raw cosine-similarity matches and re-scores them with a small trained model before they reach the generation step, instead of trusting embedding similarity order as-is:
/**
* Pure-TypeScript inference for the tiny reranker MLP trained offline in
* ml/reranker/train.py. Combines Pinecone's own cosine-similarity score
* (dense signal) with a lexical word-overlap signal to re-rank RAG matches,
* instead of trusting raw embedding-similarity order alone.
*/
The model is a two-layer MLP trained on cosine similarity plus a lexical word-overlap feature. It’s small enough to run as plain arithmetic in a Cloudflare Worker, with no model-serving runtime:
function extractFeatures(query: string, cosineSimilarity: number, docText: string): number[] {
const queryWordCount = tokenize(query).length;
const docWordCount = tokenize(docText).length;
return [
cosineSimilarity,
lexicalOverlap(query, docText),
Math.min(queryWordCount, 50) / 50,
Math.min(docWordCount, 500) / 500,
];
}
Reranking assumes raw embedding similarity is a noisy proxy for relevance. Two passages can be close in embedding space for reasons unrelated to answering the query, and a second signal (here, literal word overlap) catches some of what cosine similarity misses. You can check whether the reranked order improves relevance against a held-out test set, and the project does. But the whole pipeline, embedding plus reranking, only answers which documents are most relevant to the query. It says nothing about whether the generated answer stuck to what those documents contain.
Relevance and faithfulness
Relevance asks whether we retrieved the right material. Faithfulness asks whether every claim in the final answer traces back to that material. Handing an LLM the correct documents doesn’t constrain its response to them. The model can go beyond what’s in front of it, fill a gap with something plausible from its training data, or state a detail more confidently than the source supports. The two fail independently, so they have to be checked independently.
Faithfulness needs its own evaluation. One way to check it, used in a research-agent project with a different pipeline, is an LLM judge given both the raw retrieved sources and the generated report, scored specifically on whether the report uses only facts present in those sources:
class EvalScore(BaseModel):
faithfulness: int = Field(
description="Score 1-5: Does the report ONLY use facts present in the raw sources?"
)
relevance: int = Field(
description="Score 1-5: Does the report actually answer the user's topic comprehensively?"
)
The two scores are kept separate because they move independently. A report can be relevant to the topic while stating something the sources never said, and a report can be faithful to its sources without addressing what the user asked. A single “quality” score would hide the failure that matters most: an answer that reads well and cites roughly the right material but says something its sources don’t support.
Where to spend the effort
Reranking and better embeddings are worth the investment; just don’t stop there. A RAG system with excellent retrieval and no faithfulness check can’t see the step between “we found the right document” and “the answer is grounded in it”, because every retrieval metric only looks at what came back from the vector store. If you can only invest in one, don’t assume faithfulness comes free with good retrieval. A wrong answer built from the right sources is invisible to retrieval metrics.