Beyond Basic Vector Search: What Production RAG Actually Looks Like

· 3 min read

Building a proof-of-concept RAG system takes an hour: load a PDF, split it into 500-token chunks, push embeddings into a vector database, and run cosine similarity against a user query.

Then you deploy it to real users, and problems immediately surface:

A production-ready retrieval pipeline cannot rely on naive dense vector search alone. Here is the architecture that actually holds up in production.

1. The Fallacy of Pure Dense Vector Search

Dense vector embeddings (like OpenAI text-embedding-3 or Gemini embeddings) are exceptional at capturing semantic intent, synonyms, and conceptual relationships. But they are fundamentally weak at:

  1. Exact keywords: Product codes, part numbers, stock tickers, or function names (CVE-2024-38063 or ERC-721).
  2. Short, ambiguous queries: Searches where keywords carry high information density.
  3. Negation: "Show documentation that does not use Docker" often retrieves documents heavily discussing Docker.

The solution is not to abandon vector search, but to pair it with traditional lexical keyword search (BM25 or PostgreSQL tsvector).

2. Hybrid Search with Reciprocal Rank Fusion (RRF)

Hybrid search queries two independent systems in parallel:

  1. Lexical retrieval (BM25 / Full-Text Search): Finds documents matching exact tokens and keywords.
  2. Dense vector retrieval (Vector DB): Finds documents matching semantic meaning.

Instead of trying to normalize and blend raw cosine scores and BM25 scores (which have completely different score distributions and ranges), production systems use Reciprocal Rank Fusion (RRF):

RRF_Score(d) = Σ [ 1 / (k + rank_lexical(d)) ] + [ 1 / (k + rank_vector(d)) ]

Where k is a constant (typically 60) that prevents top-ranked outliers from completely dominating.

Documents that rank high in both full-text and vector search rise straight to the top. Documents that excel in only one still make the candidate pool. This single change eliminates over 70% of user retrieval complaints.

3. Parent-Child Semantic Chunking

One of the deepest tensions in RAG is chunk size:

Parent-Child chunking solves this dilemma by decoupling what you search from what you send to the LLM:

  1. Ingest documents and split them into large Parent Chunks (e.g., 1,200 tokens).
  2. Subdivide each parent into smaller Child Chunks (e.g., 200 tokens).
  3. Embed and index only the Child Chunks in your vector store, storing a reference pointer to their parent ID.
  4. When a search matches a child chunk, fetch the full Parent Chunk from storage and pass that to the LLM.

The LLM receives full, coherent context without sacrificing vector search precision.

4. Metadata Filtering Before Vector Search

Never perform vector similarity search across your entire database and filter out forbidden documents in application memory afterward. If a user only has access to a specific organization or project, vector search might waste all top-k slots on documents the user cannot read.

Always apply strict pre-filtering using your vector database’s native payload filters:

const results = await qdrant.search("knowledge_base", {
  vector: queryEmbedding,
  filter: {
    must: [
      { key: "org_id", match: { value: currentOrgId } },
      { key: "is_archived", match: { value: false } }
    ]
  },
  limit: 10
});

5. Cross-Encoder Reranking

Bi-encoder embeddings compute vectors for query and document independently. A cross-encoder reranker takes the top 20 candidate documents and computes joint cross-attention between (query, document) simultaneously.

Rerankers are too computationally intensive to run against millions of documents, but running them against just your top 20 retrieved candidates takes under 50ms and routinely boosts final response quality by 20–30%.

Conclusion

If your RAG system is failing in production, don't rush to switch to a larger LLM. The bottleneck is almost always retrieval. Add lexical hybrid search with RRF, decouple your indexing chunk size from your generation context with parent-child chunking, and add a reranker.

Thoughts? Email me at sudarshan096k@gmail.com.

GitHub
LinkedIn
X