AI ENGINEERING

Building RAG Pipelines That Actually Work in Production

We break down the architecture behind our Qdrant-powered retrieval-augmented generation stack from chunk sizing and embedding models to re-ranking and hallucination guardrails.

Ahsan Iqbal

Lead Engineering Architect

Jul 28, 2026 8 min read

💡 Key Takeaways & Architecture Summary

  • Optimal chunking strategy: 512 tokens with 15% overlap maintains contextual coherence.
  • Hybrid Search (Dense + Sparse via Qdrant & BM25) yields 24% higher retrieval precision than vector-only search.
  • Reciprocal Rank Fusion (RRF) and Cross-Encoder re-ranking filter out false positives before LLM context injection.
  • Strict system prompt contracts + output schema validation reduce hallucination rates under 0.8%.

The Gap Between Demos and Production RAG

Naive Retrieval-Augmented Generation (RAG) demos take 30 minutes to build with LangChain. However, deploying a production RAG system that answers high-stakes customer queries with sub-second latency and zero hallucinations requires rigorous database indexing, hybrid retrieval, and multi-stage re-ranking.

1. Intelligent Chunking & Embedding Strategies

Fixed-size naive text splitting destroys semantic continuity. We employ header-aware markdown chunking combined with sentence-boundary fallbacks. Each chunk is enriched with metadata (document source, section path, publication date) before embedding via OpenAI text-embedding-3-large or Cohere Embed v3.

typescriptCode Snippet
import { QdrantClient } from "@qdrant/js-client-rest";

const client = new QdrantClient({ url: process.env.QDRANT_URL });

export async function hybridVectorSearch(queryEmbedding: number[], sparseIndices: number[], sparseValues: number[]) {
  return await client.search("legal_case_law", {
    vector: {
      name: "dense-text-embedding",
      vector: queryEmbedding,
    },
    sparse_vector: {
      name: "sparse-bm25",
      vector: { indices: sparseIndices, values: sparseValues },
    },
    limit: 10,
    with_payload: true,
  });
}

2. Hybrid Search & Multi-Stage Re-Ranking

Dense vector similarity excels at capture of general semantic intent but frequently fails on exact phrase matches (e.g., specific law section numbers or product SKUs). By combining Qdrant dense vector search with sparse BM25 token matching, we achieve optimal retrieval recall across diverse query types.

3. Hallucination Guardrails & Context Pruning

Injecting 20 raw search results into an LLM prompt degrades context utilization ('lost in the middle' phenomenon). We pass top retrieved documents through a Cohere Rerank v3 cross-encoder model, selecting only the top 3-5 highest scoring passages before constructing the final prompt.

Tags:
#RAG
#Vector Search
#Qdrant
#LLM
#TypeScript
#Python

Related Engineering Articles

IOT · AI ENGINEERING

AI at the Edge: Running Inference on Hardware You Don't Control

An NFC smart stand or a plant-floor tablet doesn't have a GPU and can't always reach the cloud. Here's how we decide what runs on-device, what stays server-side, and what fails gracefully when the connection drops.

DATA ENGINEERING · AI

From Dashboards to Predictions: Adding Forecasting to an Existing Data Pipeline

Your SPC or OEE dashboard already tells you what happened. Layering a forecasting model on the same pipeline tells you what's about to here's the architecture change that takes, and the one it doesn't.

Let's scope your first AI workflow

A 30-minute call, a shortlist of automations, and an honest estimate of what they're worth.