跪拜 Guibai
← All articles
Artificial Intelligence

Four Steps That Took a RAG Pipeline from 67% to 92% Hit Rate

By 神奇小汤圆 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most teams launch RAG with blind prompt tweaking and no quantitative baseline. This optimization sequence gives a repeatable, low-complexity path—hybrid retrieval and reranking alone deliver 21 points of Hit Rate improvement—and makes clear which steps are must-dos versus optional latency trade-offs.

Summary

Starting from a pure vector-search baseline scoring 67% Hit Rate@5 and 0.52 MRR on a 50-query evaluation set, a four-stage optimization pushes retrieval to 92% Hit Rate@5 and 0.85 MRR. The first stage adds BM25 keyword retrieval fused with vector results via Reciprocal Rank Fusion, fixing 7 of 12 bad cases and gaining 11 percentage points. A cross-encoder reranker then re-scores the top-50 candidates, lifting MRR by 0.16—more than Hit Rate—by pulling correct chunks to the front. Query rewriting with Multi-Query and HyDE closes the gap on vocabulary mismatch between user questions and document language, adding another 4 points at the cost of one or two extra LLM calls. Finally, context deduplication, reordering to combat Lost in the Middle, and grounding prompts improve answer accuracy from roughly 83% to 88% without changing retrieval metrics.

The work also surfaces the real production trade-offs: a 92% Hit Rate still means 8% of queries fail, so a score-threshold fallback that says "no relevant content found" prevents hallucination. Offline gains don't guarantee online wins—A/B testing against user behavior remains essential. And the latency budget tightens fast when Multi-Query and HyDE each add an LLM round-trip, pushing total response time toward 4–5 seconds unless smaller models or parallel retrieval are used.

Takeaways
Build a 50-query annotated evaluation set before touching retrieval; without it, you cannot distinguish improvement from regression.
Pure vector retrieval on the test set scored 67% Hit Rate@5 and 0.52 MRR; 12 of 17 missed cases were retrieval-fixable.
Adding BM25 keyword search and fusing results with RRF lifted Hit Rate@5 to 78% and fixed 7 of the 12 retrieval bad cases.
RRF avoids the normalization headaches of weighted fusion by using only rank position, not raw scores.
A cross-encoder reranker on the top-50 candidates pushed Hit Rate@5 to 88% and MRR from 0.63 to 0.79—its main value is pulling correct results higher in the list.
Multi-Query rewriting (LLM generates multiple query variants) raised Hit Rate@5 to 91%; HyDE (generating a hypothetical document) reached 90%, and combining both hit 92%.
HyDE works well for specific queries but can hallucinate a wrong document direction for vague questions; Multi-Query is safer when queries are ambiguous.
Context deduplication, reordering chunks to put the most relevant at both ends, and grounding prompts improved answer accuracy from ~83% to ~88%.
A 92% Hit Rate still leaves 8% of queries without a correct chunk; a score-threshold fallback that refuses to answer is safer than generating a hallucination.
Offline metrics are a signal, not a guarantee—online A/B tests against user behavior (likes, follow-ups, copy actions) are mandatory before concluding an improvement.
Conclusions

Hybrid retrieval and reranking are the highest-leverage steps: together they deliver 21 percentage points of Hit Rate improvement with no LLM calls and moderate implementation complexity.

MRR is a stricter and more revealing metric than Hit Rate because it penalizes correct chunks that appear late in the result list—reranking's true value shows up in MRR, not just recall.

Query rewriting is where the optimization shifts from deterministic retrieval to probabilistic LLM calls, introducing a latency-vs-accuracy trade-off that each team must evaluate against their own p95 latency budget.

The 8% residual failure rate after all optimizations is a reminder that retrieval is never perfect; a production system needs a fallback policy, not just better ranking.

Offline evaluation sets drift from production distribution over time, so continuous bad-case logging and periodic regression testing are as important as the initial optimization sprint.

Concepts & terms
Hit Rate@K
The fraction of queries for which at least one relevant chunk appears in the top-K retrieved results. A retrieval-only metric that measures recall, not answer quality.
MRR (Mean Reciprocal Rank)
The average of 1/rank for the first correct result across all queries. A result at rank 1 contributes 1.0; at rank 3 it contributes 0.33. Stricter than Hit Rate because it penalizes correct results that appear late in the list.
RRF (Reciprocal Rank Fusion)
A method to merge ranked lists from multiple retrieval systems by scoring each document as Σ 1/(k + rank), where k is a constant (often 60). It avoids score-normalization problems because it uses only rank position.
Bi-Encoder vs. Cross-Encoder
A Bi-Encoder encodes queries and documents separately, enabling fast offline indexing but missing token-level interaction. A Cross-Encoder concatenates query and document and encodes them together through full attention, giving higher accuracy but at much higher latency, so it is used only for reranking a small candidate set.
HyDE (Hypothetical Document Embeddings)
A query-rewriting technique where an LLM generates a hypothetical answer document, and the embedding of that document is used for retrieval. It bridges the vocabulary gap between short user queries and the language of the knowledge base, but can misdirect retrieval when the query is vague.
Lost in the Middle
The observed tendency of LLMs to pay less attention to content in the middle of a long context window. Mitigation strategies include reordering chunks so the most relevant ones appear at the beginning and end of the prompt.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗