Back to Insights
Private LLM & Infrastructure13 min readMarch 3, 2026

RAG at Scale: Building Enterprise Retrieval-Augmented Generation

Retrieval-augmented generation has moved from a research technique to the dominant architecture for enterprise LLM applications. The concept is straightforward: instead of relying solely on a model's parametric knowledge, you retrieve relevant documents from your own data stores and inject them into the prompt context. The execution, however, involves a chain of engineering decisions, each of which materially impacts the quality, latency, and reliability of the system. This article covers what it takes to build RAG that works at enterprise scale, not just in a notebook demo.

RAG Architecture: The Full Picture

A production RAG system is not a single component. It is a pipeline with at least seven distinct stages, each requiring its own optimization:

  • Document ingestion: Extracting text from source systems (PDFs, databases, wikis, email archives, APIs)
  • Preprocessing: Cleaning, deduplicating, and normalizing extracted text
  • Chunking: Splitting documents into retrieval-sized segments
  • Embedding: Converting chunks into dense vector representations
  • Indexing: Storing embeddings in a vector database with metadata
  • Retrieval: Finding the most relevant chunks for a given query
  • Generation: Constructing a prompt with retrieved context and generating a response

Failures at any stage cascade downstream. Poor chunking leads to irrelevant retrieval. Low-quality embeddings produce noisy search results. Inadequate preprocessing introduces garbage that the model faithfully parrots. Building reliable RAG means getting each stage right.

Chunking Strategies

Chunking is arguably the most impactful design decision in a RAG pipeline, yet it receives surprisingly little attention in many implementations. The goal is to produce chunks that are semantically coherent, appropriately sized for retrieval, and aligned with the structure of your source documents.

Fixed-Size Chunking

The simplest approach: split text into segments of N characters or N tokens with a fixed overlap. This is fast and deterministic but often splits mid-sentence or mid-paragraph, breaking semantic coherence. A chunk that starts in the middle of a paragraph about revenue projections and ends in the middle of a section about market competition provides poor retrieval signal.

When to use: Homogeneous, unstructured text where document structure is minimal (e.g., raw transcripts, log files). Not recommended for structured documents like reports, contracts, or technical documentation.

Recursive Character Splitting

A step up from fixed-size: recursively split on structural boundaries (double newlines, then single newlines, then sentences, then words) until chunks reach the target size. This preserves natural document structure much better than fixed-size splitting. LangChain's RecursiveCharacterTextSplitter popularized this approach, and it remains a solid default for most document types.

When to use: General-purpose RAG over mixed document types. This is the right starting point for most enterprise deployments.

Semantic Chunking

Uses an embedding model to detect semantic boundaries within a document. The text is split into sentences, each sentence is embedded, and consecutive sentences with high cosine similarity are grouped together. When similarity drops below a threshold, a chunk boundary is created. This produces chunks that are semantically coherent by definition, at the cost of a preprocessing embedding pass.

When to use: High-value document collections where retrieval quality is paramount and the additional preprocessing compute is justified. Particularly effective for long-form documents with varying topic density (analyst reports, research papers, legal filings).

Document-Structure-Aware Chunking

The most sophisticated approach: parse the document structure (headings, sections, tables, lists) and create chunks that align with the document's inherent organization. A section with its heading becomes one chunk. A table with its caption becomes another. This requires document-specific parsing logic but produces the highest-quality chunks for structured content.

When to use: Well-structured documents like technical manuals, regulatory filings, academic papers, and product documentation where the document structure carries important semantic information.

Chunk Size Guidelines

The optimal chunk size depends on your embedding model and use case, but general guidelines apply:

  • 256-512 tokens: Best for precise, fact-level retrieval (specific numbers, definitions, short answers)
  • 512-1024 tokens: Good general-purpose size that balances specificity with context
  • 1024-2048 tokens: Better for questions requiring broader context (summaries, analysis, comparisons)
  • Overlap: 10-20% overlap between consecutive chunks helps prevent information from being lost at boundaries

Embedding Model Selection

The embedding model converts text chunks into dense vectors for similarity search. The choice of embedding model directly determines retrieval quality and should be evaluated carefully.

Leading Models

  • BGE (BAAI General Embedding): Strong all-around performance with models from 33M to 1.5B parameters. The bge-large (1024 dimensions) offers an excellent quality-to-cost ratio for most enterprise use cases.
  • E5 (Microsoft): Particularly strong for asymmetric retrieval (short query, long document). The E5-Mistral-7B-instruct variant achieves state-of-the-art results but requires significantly more compute.
  • GTE (Alibaba): Competitive performance with efficient inference. Good choice for multilingual deployments.
  • Nomic Embed: Open-source with strong performance and 8192-token context length, enabling longer chunks without truncation.

Deployment Considerations

For private RAG deployments, run the embedding model on your own infrastructure. A dedicated GPU (even a modest one like an A10 or L4) can generate embeddings for thousands of documents per hour. This avoids sending your documents to a third-party embedding API and eliminates per-token embedding costs.

Key sizing parameters for production embedding:

  • Dimensionality: 768-1024 dimensions is the sweet spot. Higher dimensions (1536+) marginally improve retrieval but significantly increase storage and search costs.
  • Throughput: Benchmark your embedding model at batch sizes of 32-128 to find the optimal GPU utilization point.
  • Consistency: Never mix embedding models within a single index. If you change embedding models, you must re-embed your entire corpus.

Vector Database Comparison

The vector database stores your embeddings and provides similarity search at query time. For enterprise on-premise deployment, the practical options are:

Milvus

Purpose-built vector database with strong scalability characteristics. Supports billions of vectors across distributed clusters. Offers multiple index types (IVF, HNSW, DiskANN) and hybrid search combining vector similarity with scalar filtering. Milvus is the most mature option for large-scale enterprise deployments and handles operational concerns like sharding, replication, and backup well.

Qdrant

Written in Rust with a focus on performance and operational simplicity. Supports named vectors (multiple embeddings per document), payload filtering, and quantization for memory-efficient storage. Qdrant's filtering during search (not post-search) makes it particularly efficient for metadata-heavy retrieval patterns common in enterprise settings.

Weaviate

An object-oriented vector database that treats vectors as properties of data objects rather than standalone entities. Provides built-in vectorization modules, GraphQL API, and hybrid BM25 + vector search. Strong choice for teams that want an all-in-one solution with less custom plumbing.

pgvector

A PostgreSQL extension that adds vector similarity search to your existing relational database. The appeal is obvious: no new infrastructure to deploy and manage. Performance is adequate for corpora under a few million vectors. Beyond that, purpose-built vector databases offer significantly better query latency and throughput.

Our recommendation: For enterprise deployments with more than a million chunks, use Milvus or Qdrant. For smaller deployments or teams that want to minimize infrastructure surface area, pgvector is a pragmatic choice.

Retrieval Optimization

Raw vector similarity search is a baseline, not a ceiling. Production RAG systems employ multiple techniques to improve retrieval quality.

Hybrid Search

Combine dense vector search (semantic similarity) with sparse keyword search (BM25). Vector search excels at understanding intent and synonyms but can miss exact matches for specific terms, acronyms, or product names. BM25 excels at exact term matching but misses semantic relationships. Hybrid search with reciprocal rank fusion (RRF) or weighted scoring consistently outperforms either approach alone.

Reranking

After initial retrieval returns a candidate set (typically 20-50 chunks), apply a cross-encoder reranker to rescore and reorder results. Cross-encoders process the query and document together, enabling deeper relevance assessment than the bi-encoder embedding used for initial retrieval. Models like BGE-Reranker, Cohere Rerank (if using their API), or a fine-tuned cross-encoder dramatically improve top-k precision.

Reranking adds 50-200ms of latency per query depending on candidate set size and model, but the retrieval quality improvement is typically worth the trade-off.

Query Transformation

User queries are often vague, ambiguous, or poorly formed for retrieval. Transform queries before searching:

  • Query expansion: Use the LLM to generate multiple search queries from the original question, covering different phrasings and angles
  • Hypothetical document embeddings (HyDE): Generate a hypothetical answer to the question and embed that instead of the question itself, bridging the vocabulary gap between questions and documents
  • Step-back prompting: For specific questions, generate a broader question first, retrieve context for both, and combine

Metadata Filtering

Attach metadata to chunks (source document, date, department, document type, access level) and filter before or during vector search. This prevents the system from retrieving irrelevant documents from other departments, outdated versions, or documents the user should not access. Metadata filtering is essential for multi-tenant RAG deployments.

Evaluation Metrics

You cannot improve what you do not measure. RAG evaluation requires metrics at both the retrieval and generation stages.

Retrieval Metrics

  • Recall@K: What fraction of relevant documents appear in the top K results? This is the most important retrieval metric.
  • Precision@K: What fraction of returned results are actually relevant? High precision means less noise in the LLM context.
  • MRR (Mean Reciprocal Rank): How high does the first relevant result appear? Critical for user-facing applications.
  • NDCG: Measures the quality of ranking, accounting for the position of relevant results.

Generation Metrics

  • Faithfulness: Does the generated answer accurately reflect the retrieved context without hallucination?
  • Answer relevance: Does the generated answer actually address the user's question?
  • Context relevance: Is the retrieved context relevant to the question? (This catches retrieval failures surfaced through generation quality.)

Frameworks like RAGAS, DeepEval, and Phoenix provide automated evaluation pipelines for these metrics. Build an evaluation dataset of 100-500 question-answer pairs with ground truth and run evaluations after every pipeline change.

Production Patterns at Scale

Several architectural patterns emerge in mature enterprise RAG deployments:

Multi-Index Architecture

Rather than a single monolithic vector index, maintain separate indexes for different document types or knowledge domains. A query router directs questions to the appropriate index based on classification. This improves retrieval precision and allows different chunking and embedding strategies per document type.

Caching Layers

Implement semantic caching to avoid redundant retrieval and generation for similar queries. Hash the query embedding (or a quantized version) and cache the retrieval results and generated response. For enterprise knowledge bases where many users ask similar questions, caching can reduce GPU inference load by 30-50%.

Incremental Indexing

Production knowledge bases change continuously. Build an incremental indexing pipeline that detects new, updated, and deleted documents and processes only the changes. Use document fingerprinting (content hashes) to avoid re-embedding unchanged documents. For large corpora, incremental indexing is not optional; re-indexing the entire corpus on every change is prohibitively expensive.

Access Control Integration

Enterprise documents have access controls. Your RAG system must respect them. Embed access control metadata (group memberships, classification levels) with each chunk and filter at query time based on the requesting user's permissions. This is non-negotiable for any deployment touching HR documents, financial data, legal files, or classified material.

Citation and Provenance

Users need to know where answers come from. Return source document references with every generated response. Include document title, page or section reference, and a link to the original document. This is not just a UX nicety; it is essential for trust and for regulatory compliance in sectors where traceability is required.


RAG at scale is an engineering discipline, not a library import. The difference between a demo and a production system lies in the attention paid to chunking quality, retrieval optimization, evaluation rigor, and operational patterns like incremental indexing and access control. Get these foundations right, and RAG becomes the bridge between your organization's knowledge and the generative capabilities of modern language models.

Free: Enterprise AI Readiness Playbook

40+ pages of frameworks, checklists, and templates. Covers AI maturity assessment, use case prioritization, governance, and building your roadmap.

Ready to put these insights into action?