Retrieval is the connective tissue of applied AI: it powers RAG over documents, semantic recall in memory systems, and the search steps inside agentic loops. The core idea is one sentence: represent meaning as geometry, so "find relevant text" becomes "find nearby points." Everything else is engineering around that idea.
Stage 1: Chunking — deciding the unit of retrieval
Documents are too big to retrieve whole, so they're split into chunks — typically a few hundred tokens, often overlapping so sentences aren't severed from their context. Chunking is quietly the highest-leverage stage:
- Too large, and a chunk matches many queries weakly while dragging irrelevant text into the prompt.
- Too small, and meaning fragments — "the deadline moved" without which deadline.
- Structure-blind splitting (every N characters) cuts tables and arguments mid-thought; good chunkers respect headings, paragraphs, and pages.
When retrieval "misses," bad chunk boundaries are the first suspect.
Stage 2: Embedding — meaning as coordinates
Each chunk is passed through an embedding model that outputs a vector — hundreds to thousands of numbers positioning the chunk in a semantic space where similar meanings land near each other regardless of wording. "Q3 revenue fell 8%" and "third-quarter sales declined" end up neighbors; "my cat is ill" lands far away. This is the property that makes semantic search fundamentally different from keyword search: synonyms, paraphrases, and even cross-lingual matches work because the geometry encodes meaning, not spelling.
Stage 3: Indexing — making neighbors findable fast
Vectors go into an index built for nearest-neighbor search. Exact comparison against every chunk works for thousands of vectors; at scale, approximate nearest neighbor (ANN) structures — graph-based indexes like HNSW, or quantization schemes — trade a sliver of accuracy for orders-of-magnitude speed. The index also carries metadata (source file, page, upload date, workspace), which is what makes filtered queries and citations possible later.
Stage 4: Query — the same geometry, in reverse
At question time, the query is embedded with the same model, and the index returns the chunks whose vectors sit closest — each with a similarity score. Two refinements matter in practice:
- Hybrid search combines vector similarity with classic keyword matching, because exact identifiers ("invoice #4471", "HNSW") are where pure semantics is weakest.
- Reranking takes the top candidates and re-scores them with a more expensive model that reads query and chunk together, sharpening precision where it counts — the few chunks that will actually enter the prompt.
Stage 5: Grounding — retrieval meets generation
The top chunks are injected into the model's context alongside the question, typically with instructions to answer from them and cite sources. The model composes; the retrieval grounds. Done well, the answer quotes your documents with a pointer to file and location — the difference between an assistant that knows and one that guesses (context engineering is largely the discipline of feeding this stage well).
Where it lives in the tools you use
This pipeline used to be a build-it-yourself project: parser, chunker, embedding jobs, vector database, query API. Increasingly it's a service behind a protocol. In VeelIQ Context, uploading a document runs stages 1–3 automatically; when any MCP-connected assistant calls search_knowledge, stages 4–5 execute and return scored, source-attributed chunks. The same machinery serves memory: facts saved with remember are embedded too, which is why recall finds "what did we decide about pricing?" even though the stored fact never contains the word "pricing" (memory vs RAG covers what differs above the shared stack).
Why retrieval sometimes misses — a diagnostic guide
- The answer spans chunks. Half the fact in chunk 12, half in chunk 13, neither scoring high alone. Remedies: overlap, larger chunks, or structure-aware splitting.
- Vocabulary mismatch at the extremes. Highly specific tokens (part numbers, code symbols) need the keyword half of hybrid search.
- Corpus staleness. Retrieval faithfully returns the outdated spec you never replaced. The index is only as good as its curation.
- Near-duplicate crowding. Five copies of a boilerplate paragraph occupy the whole top-k, displacing the unique chunk that mattered.
- Question–document register gap. Casual queries against dense legalese embed further apart than you'd hope; rephrasing the query closes the distance.
Key takeaways
- Retrieval = chunk → embed → index → query → ground; meaning becomes geometry, relevance becomes proximity.
- Chunking quality and corpus hygiene set the ceiling; embeddings and indexes are rarely the bottleneck.
- Hybrid search and reranking patch semantic search's weak spots (exact tokens, fine-grained precision).
- The same pipeline powers document RAG and semantic memory — and it's now a hosted capability, not a mandatory build.
Related reading
Upload a PDF; stages 1–3 run automatically. Ask your AI about it; 4–5 do. Free in Beta.