LLM RAG Patterns Cheat Sheet

Retrieval-Augmented Generation patterns — chunking strategies, embedding, vector search, reranking, hybrid search, and RAG evaluation metrics.

Last Updated: July 15, 2025

RAG Architecture Pipeline

1. Ingest
Load documents — PDF, HTML, Markdown, APIs
2. Chunk
Split into retrievable units — fixed-size, semantic, recursive
3. Embed
Convert chunks to vectors — OpenAI, Cohere, sentence-transformers
4. Store
Index in vector DB — Pinecone, Weaviate, Chroma, Qdrant
5. Retrieve
Query → embed → similarity search (cosine, dot product, Euclidean)
6. Augment
Inject top-k chunks + user query into LLM prompt

Chunking Strategies

StrategyHow It WorksBest For
Fixed-SizeSplit by N tokens with overlapGeneral purpose, fast
RecursiveSplit by separators: \n\n → \n → . → spaceMarkdown/docs
SemanticSplit at natural topic boundaries (embeddings)Long-form content
Sentence WindowRetrieve sentence, expand context windowPrecision retrieval

Retrieval Techniques

TechniqueDescription
Dense RetrievalEmbed query and chunks — semantic similarity
Sparse RetrievalBM25/TF-IDF keyword matching — exact matches
Hybrid SearchCombine dense + sparse → weighted fusion (RRF)
Multi-QueryGenerate variant queries → retrieve → deduplicate union
Parent DocumentRetrieve small chunks, return full parent document

Reranking

MethodDescription
Cross-EncoderScore (query, chunk) pairs — Cohere Rerank, BGE-reranker
LLM-as-RerankerGPT-4 evaluates relevance of each chunk
Reciprocal Rank FusionMerge multiple ranked lists without scores

Vector Databases Compared

DBSelf-HostedFilteringBest For
PineconeNo (cloud)Metadata + namespacesProduction, scale
WeaviateYesGraphQL + hybrid searchMultimodal, hybrid
ChromaYesMetadata filteringPrototyping, local dev
QdrantYesPayload filteringPerformance, Rust-based
MilvusYesScalar + vectorBillion-scale, GPU indexing
Pro Tip: Chunk size is the most impactful RAG decision — too small loses context, too large dilutes relevance. Start at 512 tokens with 64-token overlap and tune from there.
Part of the Empire Builder Network