A grounded, sub-80ms hybrid retrieval engine built over 11 dense computer science volumes (2,810 chunks) combining dense vector embeddings, BM25 Okapi lexical scoring, Reciprocal Rank Fusion, and strict citation verification.
Building production RAG over dense technical literature requires deliberate trade-offs across chunking granularity, vector dimensions, memory footprint, and retrieval fusion.
We chose BAAI/bge-small-en-v1.5 to satisfy our 2β5s SLA on commodity hardware without requiring expensive NVIDIA CUDA GPUs or burning paid API tokens per search query:
| Model | Parameters | Dimensions | CPU Inference | RAM / Storage Footprint | Fit for This Project |
|---|---|---|---|---|---|
| BAAI/bge-small-en-v1.5 | 33.3M | 384 | 15 β 25 ms | ~150 MB RAM (1.5 KB / vector) | Optimal (Chosen) |
| BAAI/bge-large-en-v1.5 | 335M | 1,024 | 180 β 350 ms | ~1.4 GB RAM (4.1 KB / vector) | Too slow on CPU |
| OpenAI text-embedding-3-small | API hosted | 1,536 | 120 β 250 ms (Network) | Paid API cost per query | Violates offline OSS rule |
Vector Storage Economics: 384 dimensions require 4x less memory in Qdrant HNSW graphs than 1536-dimensional OpenAI embeddings, allowing the entire 2,810-chunk index to execute inside sub-millisecond RAM caches.
Chunking technical books requires solving the Context Truncation Dilemma:
15% Overlap (105 tokens): Implemented via token-aware sentence boundary snapping. If an essential algorithmic definition lands across a chunk break, it is guaranteed to appear in full in both adjacent chunks.
Dense embeddings produce cosine similarity scores bounded in $[0, 1]$, whereas BM25 Okapi produces unbounded frequency scores in $[0, \infty)$. Linear weighted sum ($\alpha \cdot \text{Dense} + (1-\alpha) \cdot \text{BM25}$) fails because score scales shift wildly between short and long queries.
RRF eliminates score normalization vulnerabilities: It operates strictly over ordinal positions: $\text{RRF}(d) = \sum \frac{1}{60 + \text{Rank}_m(d)}$. As demonstrated below in our interactive sandbox, this allows BM25 to rescue exact terminology matches (like Chunk #4, promoted +16 ranks into the context window) while preventing single-keyword spam from overwhelming semantic relevance.
Our ingestion pipeline processed, cleaned, and indexed 11 authoritative technical textbooks into 2,810 searchable passages. Hover to tilt in 3D perspective or click any tome to inspect its chunk profile:
Watch data packets pulse through the dual-branch hybrid retrieval circuit. Below, interactively navigate the 2D vector projection space with live nearest neighbor raycasting:
Drag node Q with your mouse across the vector field to observe real-time cosine distance raycasting and dynamic nearest neighbor discovery across 2,810 book chunks.
Directly test the mathematical mechanics of Reciprocal Rank Fusion:
RRF Score = 1/(k + DenseRank) + 1/(k + LexicalRank).
Drag the k parameter slider to observe how rank smoothing dynamically swaps and reorders candidate passages in real-time.
Experience what happens step-by-step when a query enters the FastAPI server. Click "Run End-to-End Simulation" to trace the exact execution path across all 8 micro-stages with live latency meters.
Author: Seth Weidman β’ Publisher: O'Reilly Media