Best Practices for Hybrid Vector Search & RAG Retrieval
Key strategies for document chunking, hybrid keyword-dense embedding indexing, Reciprocal Rank Fusion (RRF), and grounded context validation in enterprise knowledge search.
Gourav
Founder & AI Systems Architect
The Limits of Naive Vector Retrieval
Retrieval-Augmented Generation (RAG) is commonly implemented by chunking documents into arbitrary 500-character blocks, computing dense vector embeddings (e.g. OpenAI text-embedding-3 or BGE-M3), and querying a vector index via cosine similarity.
In production enterprise systems, this naive architecture suffers from three fatal weaknesses: loss of document hierarchy, vulnerability to specific keyword/SKU queries, and poor ranking of dense technical tables. Solving this requires a hybrid multi-stage retrieval architecture.
Heading-Aware & Structure-Preserving Chunking
Rather than slicing text by arbitrary character or token boundaries, chunking must be semantic and document-aware. In technical documentation and enterprise manuals, every chunk must inherit its parent section hierarchy (e.g., `Document Title > Chapter 3 > Subsection B`).
Prepending the breadcrumb hierarchy to the chunk content before embedding gives the vector both the local detail and the surrounding document context, instead of an orphaned sentence.
interface StructuredChunk {
chunkId: string;
hierarchy: string[]; // e.g. ["HR Manual", "Health Benefits", "Dental Coverage"]
content: string;
tokenCount: number;
metadata: {
pageNumber: number;
sourceDocument: string;
sectionHash: string;
};
}
export function buildSemanticContextString(chunk: StructuredChunk): string {
const contextHeader = chunk.hierarchy.join(' > ');
return `[Context: ${contextHeader}]
${chunk.content}`;
}Hybrid Retrieval & Reciprocal Rank Fusion (RRF)
To achieve both semantic comprehension and exact-match precision, Nor AI employs hybrid search combining sparse BM25 keyword matching with dense vector similarity.
The individual score distributions from dense vector search and sparse BM25 cannot be directly summed because their scales differ. We normalize and merge the ranked candidate lists using Reciprocal Rank Fusion (RRF), where the constant k=60 is the value from the original RRF paper (Cormack et al., 2009) and is what stops top-rank skewing:
| Retrieval Strategy | Recall@5 | Precision@5 | P95 Latency |
|---|---|---|---|
| Dense Embeddings Only | measure | measure | measure |
| BM25 Keyword Search Only | measure | measure | measure |
| Hybrid RRF (Dense + BM25) | measure | measure | measure |
| Hybrid RRF + Cross-Encoder Rerank | measure | measure | measure |
Illustrative measurement structure, not measured results. We hold no public retrieval benchmark over legal or technical-spec corpora and would not publish one without disclosing the corpus, the judge, and the split. The directional claim is the real content of this table: hybrid fusion should beat either arm alone on exact-match queries, and reranking should buy precision with latency. Measure the magnitude on your own corpus.
export function reciprocalRankFusion(
denseRankings: string[],
sparseRankings: string[],
k: number = 60
): Map<string, number> {
const fusedScores = new Map<string, number>();
const processList = (list: string[]) => {
list.forEach((docId, rank) => {
const currentScore = fusedScores.get(docId) || 0;
const rrfScore = 1 / (k + (rank + 1));
fusedScores.set(docId, currentScore + rrfScore);
});
};
processList(denseRankings);
processList(sparseRankings);
return new Map(
[...fusedScores.entries()].sort((a, b) => b[1] - a[1])
);
}Cross-Encoder Re-Ranking & Context Hygiene
After initial hybrid retrieval extracts the top-25 candidate chunks, a lightweight cross-encoder model (such as BGE-Reranker-Large or Cohere Rerank v3) re-evaluates the query-chunk pair with full cross-attention.
The top-5 highest-scoring chunks are formatted into a clean, markdown-delimited prompt with strict citation requirements: "Cite [Doc ID: X, Page: Y] for every claim made. If the provided context does not contain the answer, explicitly state that the information is unavailable."
Enterprise Knowledge Hub & RAG
Schema-enforced document intelligence pipelines for proprietary enterprise data.
Written by
Gourav
Founder & AI Systems Architect at Nor AI Technologies
Keep reading
- Document AI
Automating Candidate Screening: Skill Extraction Patterns
Gourav · 7 min read
- Document AI
Multi-Modal Audio & Video Synthesis: Timestamped Chunking & LaTeX Math Extraction
Sonu · 8 min read