Skip to main content

Building RAG Systems for Production: Lessons Learned

Practical insights from deploying Retrieval-Augmented Generation systems in enterprise environments.

S

SmartTechLabs

SmartTechLabs - Intelligent Solutions for IoT, Edge Computing & AI

5 min read

Retrieval-Augmented Generation (RAG) has become the standard approach for building AI systems that need to provide accurate, up-to-date information. After deploying RAG systems in enterprise settings, we’ve gathered lessons that can help you avoid common pitfalls.

Update, November 2026

The pipeline below is still a sound baseline. Three things have shifted since January:

  • Contextual retrieval is now a common step before embedding: an LLM prepends a short description of where the chunk sits in its document. Anthropic reported 49% fewer failed top-20 retrievals when combining contextual embeddings with contextual BM25, and 67% with reranking added (source). Measure it on your own data.
  • Agentic retrieval is used more often: the model decides when to search, rewrites queries and searches again, instead of one fixed retrieve-then-generate pass. It costs extra latency and tokens, so use it when single-pass retrieval fails on your evaluation set.
  • Larger context windows make it possible to pass whole documents for small corpora. For large or access-controlled corpora, retrieval is still needed for cost, latency and permissions.

The figures in the tables below are rules of thumb, not benchmarks. Verify them against your own golden dataset.

Why RAG Matters

Beyond Basic LLMs

RAG systems combine the language ability of large language models with a retrieval step that supplies source documents. Answers are only as good as the retrieved context.
BenefitDescriptionImpact
Hallucination ReductionGrounding responses in actual documentsFewer unsupported answers; size depends on corpus and evaluation
Knowledge UpdatesAdd documents without retrainingReal-time knowledge refresh
TransparencyCite sources for verificationIncreased user trust
Cost EfficiencyOften cheaper than fine-tuning to keep knowledge currentLower update costs

The RAG Pipeline

RAG pipeline: Documents are chunked, embedded and stored; a query is embedded, searched, reranked and passed with context to the LLM, which answers with citations.

Each component presents its own challenges and optimization opportunities.


Lesson 1: Chunking Strategy Matters More Than You Think

The way you split documents into chunks fundamentally affects retrieval quality.

StrategyDescriptionBest For
Fixed-SizeSplit at character countSimple documents
SemanticSplit at topic boundariesComplex content
HierarchicalParent-child relationshipsContext expansion
OverlappingChunks share boundariesPreserving context

Key Recommendations

  • Semantic chunking can help on documents with clear topic structure, but gains over fixed-size chunking with overlap are inconsistent, and it costs extra embedding calls. Start with structure-aware splitting (headings, paragraphs) and test
  • Overlap between chunks (10-20%) helps preserve context
  • Metadata attached to chunks (source, date, section) improves filtering
  • Hierarchical chunking enables context expansion when needed

Key Insight

Combining vector search with keyword search (for example BM25) usually improves retrieval, especially for identifiers, product names and rare terms. We have seen this consistently in production deployments.
Search TypeStrengthsWeaknesses
Vector SearchSemantic understandingMay miss exact terms
Keyword SearchExact matchingNo semantic understanding
HybridBest of bothMore complex to implement
1
2
3
4
5
# Pseudo-code for hybrid search
vector_results = vector_db.search(query_embedding, k=20)
keyword_results = keyword_index.search(query_text, k=20)
combined = reciprocal_rank_fusion(vector_results, keyword_results)
return combined[:10]

Lesson 3: Reranking is Worth the Latency Cost

StageOptimization GoalTypical Latency
Initial RetrievalRecall (find all relevant)10-50ms
RerankingPrecision (rank best first)50-100ms
Final SelectionQuality balanceInstant

Initial retrieval optimizes for recall (finding all relevant documents), but reranking optimizes for precision:

  • Use a cross-encoder model to re-score top candidates
  • The latency cost (50-100ms) is usually acceptable for enterprise applications
  • Relevance usually improves significantly; how much depends on the retriever and the reranker model

Lesson 4: Context Window Management

More Isn't Always Better

Large context windows can dilute signal with noise. Focus on quality over quantity: a few highly relevant chunks often work better than many marginal ones. Test the value of k on your own evaluation set.
ApproachProCon
Stuff AllSimple implementationDiluted signal
Top-KFocused contextMay miss info
DynamicAdapts to queryMore complex
SummarizedCompressed infoLoss of detail

Lesson 5: Evaluation is Non-Negotiable

You can’t improve what you don’t measure. The targets in the table are examples; set them from your own baseline.

Metric CategoryMetricsTarget
Retrieval QualityPrecision, Recall, MRRExample: MRR >0.7
Generation QualityAccuracy, Relevance, GroundednessExample: >90% grounded
User FeedbackSatisfaction, Helpfulness>4/5 rating
System HealthLatency, Error ratep95 <2s

Evaluation Framework

  1. Build a golden dataset of questions with expected answers
  2. Measure both retrieval quality and generation quality
  3. Run automated evaluations in CI/CD pipelines
  4. Collect user feedback for continuous improvement

Production Considerations

Scaling

ComponentScaling ChallengeSolution
Vector DBIndex size growthSharding, clustering
EmbeddingsThroughput limitsBatching, caching
LLM CallsAPI rate limitsQueuing, load balancing
StorageDocument corpusTiered storage

Monitoring

Track these metrics in production:

Metricp50 Targetp99 Target
Retrieval Latency<100ms<500ms
Embedding Latency<50ms<200ms
LLM Response<2s<5s
End-to-End<3s<8s

Security

ConcernMitigation
Access ControlDocument-level permissions
Audit LoggingQuery and response tracking
PII HandlingRedaction in pipeline
Rate LimitingPrevent abuse

Implementation Checklist

  1. Data Pipeline: Document ingestion and chunking strategy
  2. Vector Store: Select and configure vector database
  3. Retrieval: Implement hybrid search with reranking
  4. Generation: Prompt engineering and context assembly
  5. Evaluation: Build golden dataset and automated tests
  6. Monitoring: Set up observability and alerting
  7. Security: Implement access control and audit logging

Conclusion

RAG systems are deceptively simple in concept but require careful engineering to work well in production. The key is to treat RAG as a complete system rather than just connecting a vector database to an LLM.

Start with a strong evaluation framework, iterate on each component, and monitor everything in production. The investment in infrastructure pays off in system reliability and user trust.


Working on a RAG implementation? Reach out to discuss your specific challenges.

Share this article
S

SmartTechLabs

Building Intelligent Solutions: IoT, Edge Computing, AI & LLM Integration