Chunk
Split documents into passages of roughly 200–800 tokens, often with 10–20% overlap so ideas aren't cut mid-sentence. Chunk size is the #1 quality lever: too big dilutes relevance, too small loses context.
Most "AI implementation" failures aren't model problems — they're knowledge and people problems. RAG is the pattern that connects an LLM to your documents at answer time, so it stops guessing and starts citing. Here's the whole pipeline, working, below.
Below is a toy knowledge base — 12 chunks from a fictional company handbook, each embedded as a point in space. Pick a question: it gets embedded too (the orange comet), the nearest chunks by cosine similarity light up, and the top-k get stuffed into the prompt. Drag the 3D space to orbit.
Drag to rotate the embedding space · blue dots = chunks · orange = your query
Split documents into passages of roughly 200–800 tokens, often with 10–20% overlap so ideas aren't cut mid-sentence. Chunk size is the #1 quality lever: too big dilutes relevance, too small loses context.
An embedding model maps each chunk to a vector — commonly 384 to 3,072 dimensions — where semantic neighbors land close together. "PTO policy" and "vacation days" end up near each other despite sharing zero words.
Vectors go into a vector store (pgvector, Pinecone, Weaviate, FAISS…) with an ANN index like HNSW that finds near-neighbors in milliseconds instead of scanning everything.
The user's question is embedded with the same model, and the store returns the k most similar chunks — typically k = 3–10. Many systems then re-rank those candidates with a cross-encoder for precision.
Retrieved chunks are pasted into the prompt as context, with instructions like "answer only from the context; say 'I don't know' otherwise." This is what grounds the model and slashes hallucination.
The LLM answers from the supplied evidence — and can cite chunk IDs. Update the documents, and answers update instantly. No retraining, no fine-tuning cycle.
Similarity between query vector q and chunk vector c is the cosine of the angle between them:
Worked example in 3 dimensions: q = (0.9, 0.2, 0.1), c₁ = (0.8, 0.3, 0.0), c₂ = (0.1, 0.1, 0.95).
| Pair | Dot product | Norms | Cosine | Meaning |
|---|---|---|---|---|
| q · c₁ | 0.9×0.8 + 0.2×0.3 + 0.1×0 = 0.78 | 0.930 × 0.854 | 0.982 | Nearly same direction — retrieved |
| q · c₂ | 0.9×0.1 + 0.2×0.1 + 0.1×0.95 = 0.205 | 0.930 × 0.960 | 0.230 | Mostly unrelated — skipped |
Real systems do this in hundreds of dimensions, but the geometry is identical — which is why the 3D demo above is an honest miniature.
A RAG system is only as good as the documents behind it — and documents are owned by people. Before wiring up a vector store, an honest readiness check:
Is your source of truth current, deduplicated, and access-controlled? RAG retrieves stale policy pages just as confidently as fresh ones. Garbage in, confidently-cited garbage out.
Who owns retrieval quality? Someone must review "the model said X, the doc says Y" reports weekly. Unowned pipelines rot in about a quarter.
The teams that win start with one painful, document-heavy workflow (support macros, policy Q&A, onboarding) and measure deflection rate — not with a moonshot chatbot for everything.
Track groundedness (answers traceable to a retrieved chunk), retrieval hit rate, and "I don't know" honesty. If you can't measure it, you're demo-ing, not deploying.