- 100 Documents
1. Ingestion
- Parsing
- OCR
- Chunking
- Storing
- Vector database
- Index creation
- Metadata store Relational
- BM25
- HNSW
- IVF
2. Generation
- API Gateway
- Authentication
- Metadata Filtering
- Keyword Lookup using BM25 Index
- HNSW search
- Reciprocal Rank Fusion
- Optional Cross Encoder
- Intent Classification
- Routing Rules
- Model Selection
- Guardrails
- Observability
- Output Generation
3. Evaluation
- Recall@K
- 100K documents
- Kafka
- IVF-PQ
- Disk ANN
- Multi Node Opensearch
- Metadata filtering
- Query Rewriting
- Document Deduplication
- Hierarchical Retrieval
- Context Compression
- Auto Scaling BM25
- Catching
- Multi stage Retrieval
Recall@K measures whether the retrieval system returns the correct document or chunk within the top K results.
For example, suppose you have 100 test questions, and for each question you already know the correct policy chunk.
If you retrieve the top 5 chunks (K=5) and the correct chunk appears in the top 5 for 92 questions, then Recall@5 = 92/100 = 92%.
In a RAG system, Recall@K is critical because if the correct chunk is not retrieved, the LLM cannot generate the correct answer, regardless of how powerful it is. Typically, we aim for a high Recall@5 or Recall@10 before optimizing the generation model.
- LLM as a Judge for Unlabelled data
Dimensions
- correctness
- groundedness
- completeness
- relevance
- hallucination
Prompt Design
Glossary
- Recall
Recall measures how many of the relevant (positive) items were successfully retrieved.
Formula:
Recall = TP / (TP + FN)
Where:
- TP (True Positive): Relevant chunk was retrieved.
- FN (False Negative): Relevant chunk was not retrieved.
- TN (True Negative): Irrelevant chunk was not retrieved (not used in recall).
- FP (False Positive): Irrelevant chunk was retrieved (used in precision, not recall).
In RAG, the priority is to minimize False Negatives, because if the correct policy chunk is missing from the retrieved results, the LLM cannot answer correctly. That is why Recall@K is one of the most important retrieval metrics.
- HNSW
- Enter at the Top: The search begins at a predefined entry point on the absolute highest layer of the graph.
- Greedy Search (Top-Down): The algorithm evaluates the distance from the query vector to the current node's neighbors. It jumps to whichever neighbor is closest to the query.
- Local Minima: When the algorithm can no longer find a neighbor closer to the query than its current node, it drops straight down to the exact same node on the next layer below.
- Repeat and Refine: It repeats this greedy search on the lower layer, leveraging the denser connections to fine-tune the match .
- Final Stop: This process continues until it reaches Layer 0. On Layer 0, it uses a priority queue to keep track of the top
efSearchclosest neighbors, returning your final result
M(Max Connections per Node): The maximum number of bidirectional links created for each new node at Layer 0.- Low M (e.g., 8-16): Less memory usage, faster builds, but lower search accuracy on complex datasets.
- High M (e.g., 32-64): Better recall for high-dimensional data, but uses significantly more RAM.
efConstruction(Build Depth): Controls how many entry points are evaluated when adding a new vector to the index.- Higher values: Increases index build time but yields highly optimized graphs with better accuracy.
efSearch(Search Depth): Controls the size of the dynamic candidate list evaluated during a query.- Higher values: Increases search time but drastically improves accuracy (recall). This can be adjusted on the fly per query without rebuilding the index
- IVF
- Clustering (Index Creation): The database uses an algorithm like k-means to group all data vectors into distinct clusters, each represented by an anchor point called a centroid. Every vector is then assigned to its nearest centroid to create an inverted list of vectors per cluster.
- Probing (Search Query): When you run a query, the system first finds the closest centroids and then searches only within the vectors of those specific clusters.
- nlist: The total number of clusters/centroids the index is divided into when it is built. A higher
nlistcreates smaller clusters, which means fewer vectors to search per cluster. - nprobe: The number of clusters the algorithm is allowed to check during a search. A higher
nprobeincreases accuracy but takes more time, while a lowernprobeincreases speed.
- IVF_FLAT: Searches exactly within the selected clusters using brute force. It provides a great balance of speed and high accuracy.
- IVF_PQ (Product Quantization): Compresses the vectors within the clusters to heavily save on memory. It trades a tiny amount of accuracy for major storage efficiency.
- IVF_SQ (Scalar Quantization): Reduces the precision of the numbers in the vectors to save space.
nprobe parameter.- Train: The algorithm runs k-means clustering on a representative dataset to find the coordinates of the centroids (
nlist). - Add: The database assigns every vector in your dataset to its nearest centroid, building the inverted file lists.
- Search: The query looks at the closest
nprobecentroids and searches only the vectors inside them.
- Training Data Size: You do not need your entire dataset to train the index, but you need enough. Faiss recommends between 30 * nlist and 256 * nlist vectors for the
train()step. - Choosing nlist: A good baseline is \(nlist = 4 \times \sqrt{N}\), where N is your total number of vectors.
- The Accuracy Trade-off: If your search results are inaccurate during testing, increase your
index.nprobevalue. If it is too slow, decreaseindex.nprobe.
- IVF-PQ
- DiskANN
- Hierarchical Retrieval
- Coarse Retrieval (High-level): The system searches across document titles or broad summaries to quickly pinpoint the most relevant document or major section.
- Fine-Grained Retrieval (Low-level): Once the right section is found, it zooms in to retrieve smaller, specific text chunks that directly answer the user's query.
- Context Condensation: The system selectively merges the detailed child-chunks into their larger parent-context before sending it to the LLM.
- Legal and Regulatory Compliance: Quickly referencing specific clauses while preserving the full paragraph or contract section for context.
- Academic & Financial Research: Cross-referencing findings across multiple SEC filings or scientific papers.
- Enterprise Knowledge Bases: Navigating complex policy documents across different departments.

