Fundamentals

How retrieval works in modern AI.

When your assistant "searches your documents," a five-stage pipeline runs in milliseconds. Understanding it explains both the magic and the occasional miss.

Published 2026-07-12·~8 min read·VeelIQ

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:

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:

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

Key takeaways

Related reading

The pipeline, pre-built.

Upload a PDF; stages 1–3 run automatically. Ask your AI about it; 4–5 do. Free in Beta.

Try Context free