Home Knowledge Base Retrieval-Augmented Generation (RAG)

Retrieval-Augmented Generation (RAG) is the architecture pattern that enhances LLM responses by first retrieving relevant documents from an external knowledge base and injecting them into the prompt context before generation — grounding the model's output in factual, up-to-date information rather than relying solely on parametric knowledge learned during pretraining, dramatically reducing hallucination and enabling domain-specific expertise.

RAG Pipeline

1. User Query: "What is the maximum operating temperature for the XYZ-3000 chip?" 2. Retrieval: Query embedded → similarity search against vector database → top-K relevant documents retrieved. 3. Augmentation: Retrieved documents prepended to the prompt as context. 4. Generation: LLM generates answer grounded in the retrieved context.

Components

ComponentPurposeExamples
Embedding ModelConvert text to vectorsOpenAI ada-002, BGE, E5, GTE
Vector DatabaseStore and search embeddingsPinecone, Weaviate, Qdrant, Chroma, pgvector
Chunking StrategySplit documents into retrievable units256-1024 tokens, overlap 10-20%
RerankerRe-score retrieved results for relevanceCohere Rerank, BGE-reranker, cross-encoder
LLMGenerate final answer from contextGPT-4, Claude, LLaMA, Mistral

Chunking Strategies

StrategyChunk SizeOverlapBest For
Fixed-size512 tokens50 tokensGeneral text
Sentence-based3-5 sentences1 sentencePrecise retrieval
SemanticVariableNoneCoherent topics
Recursive character1000 chars200 charsLangChain default
Parent-childSmall retrieve, large returnN/ABest of both worlds

Advanced RAG Techniques

Evaluation Metrics

MetricWhat It Measures
FaithfulnessIs the answer supported by retrieved context?
Answer RelevanceDoes the answer address the question?
Context RelevanceAre retrieved documents relevant to the query?
Context RecallDid retrieval find all necessary information?

RAG vs. Fine-Tuning

RAG is the standard architecture for production LLM applications — by separating knowledge storage (database) from reasoning (LLM), it solves the core limitations of LLMs: outdated knowledge, hallucination, and lack of domain expertise, making it essential for enterprise AI deployments.

retrieval augmented generationragretrieval generationvector search ragcontext injection

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.