AI & TechnologyFeatured

Building Production RAG Systems in 2025: Lessons from 50+ Deployments

After deploying RAG pipelines for 50+ businesses — from law firms to hospitals to e-commerce brands — here are the real lessons that nobody talks about. Chunking strategies, retrieval quality, eval frameworks, and what actually breaks in production.

Huzaifa Tahir
12 min read

Building Production RAG Systems in 2025: Lessons from 50+ Deployments


Retrieval-Augmented Generation (RAG) is no longer experimental. In 2025, it is the backbone of enterprise AI — knowledge bases, internal search, document intelligence, and customer-facing AI assistants all run on some form of RAG. After building and deploying RAG pipelines for 50+ clients across legal, healthcare, e-commerce, and logistics, I want to share the lessons that cost hours of debugging and thousands of dollars to learn.


What RAG Actually Is (and What It Isn't)


RAG is a pattern where you retrieve relevant context from a knowledge base and give it to an LLM before asking it to answer. Simple in theory. Brutally unforgiving in production.


The naive version: chunk your documents, embed them into Pinecone, retrieve top-5 chunks, stuff them in the prompt. This works in demos. It falls apart when:

  • Your documents are long and hierarchical (legal contracts, manuals, policies)
  • Users ask multi-hop questions ("What does our refund policy say for international orders shipped after December 1?")
  • The knowledge base is updated frequently
  • You need citations and source traceability

  • Lesson 1: Chunking Is the Most Underrated Problem


    Most teams spend 80% of their time on the LLM and 5% on chunking. It should be the reverse.


    **Fixed-size chunking is almost always wrong.** Splitting every 512 tokens without regard for document structure means your chunks will contain half a sentence from one section and half from another. Retrieval quality tanks.


    **What actually works:**

  • **Semantic chunking**: Split on paragraph and section boundaries. Preserve headings as part of the chunk for context.
  • **Hierarchical chunking**: Store both small chunks (for retrieval precision) and their parent sections (for full context). Retrieve the small chunk, then pass the parent section to the LLM.
  • **Sliding window with overlap**: For dense technical documents, 20–30% overlap between chunks prevents critical information from being split across boundaries.
  • **Document-aware splitting**: PDFs, Word docs, and HTML each need different parsers. A PDF with columns will produce garbage if you just extract raw text.

  • For legal contracts, I now use a custom parser that identifies clause headers and preserves them with their content. Retrieval accuracy went from 71% to 94% on our internal eval set.


    Lesson 2: Embedding Model Choice Matters Enormously


    In 2023, everyone used `text-embedding-ada-002`. In 2025, that is a mistake for specialized domains.


    **The problem with general embeddings**: They optimize for general semantic similarity. "The tenant shall vacate the premises within 30 days" and "The renter must leave the property in one month" are semantically similar — great. But "liability is limited to direct damages" and "consequential damages are excluded" are legally very different clauses that a general embedding model might cluster together.


    **What I use in 2025:**

  • **`text-embedding-3-large`** (OpenAI) for general-purpose RAG — best balance of quality and cost
  • **Cohere embed-multilingual-v3.0** for multilingual deployments
  • **Domain-fine-tuned models** via Hugging Face for healthcare and legal (BERT-based models fine-tuned on PubMed or legal corpora outperform general models by 15–25% on domain-specific retrieval)

  • Lesson 3: Retrieval Quality Must Be Measured, Not Assumed


    Most teams deploy RAG and test it manually with 5–10 questions. This is not a retrieval eval — it is wishful thinking.


    **Build an eval set from day one.** For every RAG deployment, I create a golden dataset of 50–100 question-answer pairs with the expected source chunks. I then measure:


  • **Retrieval recall@k**: For your golden Q&A pairs, what percentage of the time is the correct chunk in the top-k results?
  • **Answer faithfulness**: Is the LLM's answer grounded in the retrieved context, or is it hallucinating?
  • **Answer relevance**: Does the answer actually address the user's question?

  • Tools I use: **Ragas** for automated RAG evaluation, **LangSmith** for tracing individual retrieval and generation steps, and custom evals using Claude as a judge for subjective quality assessment.



    Pure vector (embedding) search misses exact-match queries. A user searching for "Invoice #INV-2024-8847" will get semantically similar documents — not the exact invoice they asked for.


    **Hybrid search** combines vector similarity with BM25 keyword search, then uses Reciprocal Rank Fusion (RRF) to merge results. This is now the standard approach for production RAG. Pinecone supports it natively; Weaviate, Qdrant, and pgvector can be configured for hybrid with additional setup.


    For most of my deployments, hybrid search improves retrieval recall by 8–15 percentage points over pure vector search.


    Lesson 5: The Re-Ranking Step Is Not Optional


    After retrieval, your top-k chunks may not be in the right order of relevance. A cross-encoder re-ranker (Cohere Rerank, BGE Reranker) looks at the query and each candidate chunk together, rather than independently, and re-orders them.


    In practice, adding re-ranking improves answer quality noticeably on multi-part questions. The cost is 50–150ms latency per query — almost always worth it.


    Lesson 6: Metadata Filtering Prevents Context Poisoning


    When your knowledge base has documents from multiple departments, time periods, or customers, retrieval without filtering will mix contexts. A question about "our return policy" might retrieve an old 2022 policy alongside the current 2025 one.


    Every document in your vector store should have rich metadata: `department`, `document_type`, `effective_date`, `customer_id`, `access_level`. Then filter at query time — only retrieve chunks matching the relevant metadata.


    This is especially critical for multi-tenant RAG where different users should only see their own data.


    Lesson 7: Know When RAG Is the Wrong Tool


    RAG is not a magic fix. Some scenarios where RAG fails:

  • **Highly structured queries that need SQL** — "Total revenue by region for Q3 2024" needs a database query, not a vector search
  • **Real-time data** — RAG retrieves from a static knowledge base. If your data changes every minute, you need a different architecture
  • **Numerical reasoning over many documents** — LLMs are bad at aggregating numbers from 100 retrieved chunks. Use structured queries instead.

  • In 2025, the best AI systems combine RAG for unstructured knowledge retrieval, SQL for structured data queries, and APIs for real-time data — all orchestrated by an AI agent that decides which tool to use.


    The Stack I Use in 2025


    For most production RAG deployments:

  • **Embeddings**: `text-embedding-3-large` or Cohere
  • **Vector store**: Pinecone (managed) or pgvector (when already on Postgres)
  • **Hybrid search**: Pinecone native hybrid or Elasticsearch BM25 + vector
  • **Re-ranking**: Cohere Rerank v3
  • **LLM**: Claude 3.5 Sonnet (best instruction-following for citation-based answers) or GPT-4o
  • **Orchestration**: LangChain or LlamaIndex
  • **Evals**: Ragas + LangSmith
  • **Infrastructure**: Docker + AWS Lambda or Vercel Edge Functions

  • RAG in production is 20% architecture and 80% data engineering. The teams that win are the ones obsessed with document quality, chunking strategy, and continuous evaluation — not just which LLM to use.

    Share this article

    Related Articles