Entity Guide

RAG: Retrieval-Augmented Generation explained for enterprise

Drawn from Xenqube production RAG work in legal, finance, and other regulated domains. This page covers what RAG is, when to use it, and architecture decisions that survive compliance review.

How RAG Works: The Three Core Components

Every production RAG system has three components. The quality of each determines the final system quality.

Document Ingestion Pipeline

Load, chunk, and embed your documents into the vector database. Chunking strategy is the most important decision - it determines retrieval quality more than model choice.

  • Document parsing (PDF, Word, HTML, Markdown)
  • Semantic chunking by meaning, not character count
  • Embedding with text-embedding-3-small or similar
  • Metadata extraction for filtered retrieval

Hybrid Retrieval

At query time, run both semantic search (vector similarity) and keyword search (BM25), then fuse results with RRF. This combination catches both conceptual matches and exact matches.

  • Vector similarity search
  • BM25 keyword search
  • Reciprocal Rank Fusion (RRF)
  • Metadata filtering (date, source, department)

Re-ranking

Take the top 20-50 retrieved chunks and re-order them using a cross-encoder model that scores each chunk against the specific query. Improves answer quality by 20-30%.

  • Cross-encoder re-ranking (BGE, Cohere, Jina)
  • Eliminates irrelevant retrieved chunks
  • 100-300ms latency cost - worth it for accuracy
  • Optional for cost-sensitive use cases

RAG - Frequently Asked Questions

Common questions about building, deploying, and evaluating RAG systems in enterprise environments.

What is RAG (Retrieval-Augmented Generation)?

RAG is an AI architecture that combines a retrieval system (vector database + search) with a large language model. When a user asks a question, the system first retrieves relevant documents from your knowledge base, then passes those documents as context to the LLM to generate a grounded, source-attributed answer. This gives the model access to current, proprietary information it wasn't trained on.

Why do enterprises use RAG instead of just prompting an LLM?

LLMs only know what they were trained on - which is public data up to a cutoff date. They don't know your internal policies, your product catalog, your client history, or your proprietary research. RAG solves this by retrieving your specific documents and including them in the LLM's context at query time. The model then reasons over fresh, current, source-attributed information.

What is the difference between RAG and fine-tuning?

Fine-tuning adjusts the model's weights to change its behavior (format, style, reasoning patterns). RAG keeps the model unchanged but gives it access to your data at query time. RAG is the right choice when the problem is 'the model doesn't know something.' Fine-tuning is right when the problem is 'the model doesn't behave correctly.' Most enterprise problems are knowledge problems - RAG addresses them.

What is hybrid search in a RAG system?

Hybrid search combines vector similarity search (semantic search - finds conceptually related documents) with BM25 keyword search (exact match - finds documents with the specific terms). Vector search alone misses exact matches (product codes, policy section numbers). BM25 alone misses semantic relationships. The combination catches both, improving retrieval recall by 15-30%.

How do you prevent hallucination in a RAG system?

RAG significantly reduces hallucination because the model reasons over retrieved documents rather than relying on training data. Additional controls: citation enforcement (the model must cite the source document for every claim), retrieval validation (reject queries where no relevant documents are found rather than guessing), and confidence thresholds (flag low-confidence answers for human review).

What vector database should I use for enterprise RAG?

For most enterprise use cases, Postgres with pgvector handles retrieval reliably without the operational overhead of a dedicated vector database. It integrates with your existing data infrastructure and supports hybrid search with BM25. For very large corpora (10M+ documents) or extremely high query volumes, dedicated vector databases (Pinecone, Weaviate, Qdrant) offer better performance at scale.

How long does it take to build a production RAG system?

A well-scoped RAG POC (one knowledge domain, basic retrieval): 2-4 weeks. A production RAG system (hybrid search, re-ranking, evaluation framework, monitoring): 6-10 weeks. An enterprise knowledge platform (multiple domains, security controls, role-based access): 3-6 months.