Retrieval-Augmented Generation · worked example
A question-answering system built over the SmartDelivery infra docs and microservice code — pulled apart stage by stage, with real results from two retrievers and what would change before it went to production.
268 files were chunked and embedded once with OpenAI. Then the same question
set went through two different retrievers, each feeding its chunks to the same
gpt-4o-mini prompt — so any difference in the answers is down to retrieval,
not the model.
stack · text-embedding-3-small (embeddings) · gpt-4o-mini (generation) · Azure AI Search (hybrid)
Plain cosine similarity over the 637 vectors held in a local file. The simplest retriever that works — nothing but nearest-neighbour math.
Deployed on Azure AI Search (free tier): hybrid retrieval that fuses BM25 keyword scoring with vector similarity. The production-style backend.
RAG is two ordinary steps bolted together. Retrieval: documents are cut into chunks, each chunk is turned into a vector (an embedding) that captures its meaning, and your question — also a vector — is matched against them by nearest-neighbour search. No model "understanding" yet; it is similarity arithmetic. Generation: the closest chunks are pasted into the prompt, and the model answers using only that context, so the answer is grounded in your material instead of the model's training data.
The retriever can only ever hand the model a whole chunk, so a chunk that splits a
heading from its body degrades every answer that needs it. Try the three strategies on a
real slice of TECH_SPEC.md and watch the boundaries move.
The interesting engineering is retrieval, so we ran the same questions through
two backends and fed each one's chunks to the same gpt-4o-mini prompt. Any
difference in the answer comes from what was retrieved, not the model.
Two honest caveats. The scores aren't comparable — cosine runs 0–1, Azure's fused RRF score runs ~0.02–0.03 — so judge by which chunks came back, not the number. And "more complete" is not automatically "more correct": broader retrieval can also pull in loosely-related context, so a production system verifies, it doesn't just trust.
| Concern | This demo | In production |
|---|---|---|
| Vector store | One file, brute-force cosine over 637 rows | Approximate-NN index (pgvector, Pinecone, Azure AI Search) over millions |
| Retrieval | Cosine, or Azure free-tier hybrid | Hybrid plus a cross-encoder semantic reranker (Basic tier+) |
| Chunking | Recursive character splitter per file type | Layout-aware for PDFs, AST-based for code, parent-document retrieval |
| Query handling | Question embedded verbatim | Query rewriting, multi-query, HyDE, conversation-aware rephrasing |
| Freshness | Manual re-index | Incremental pipeline keyed on content hashes, triggered by commits |
| Evaluation | Reading the answers | Recall@k / MRR on a golden set; faithfulness scoring in CI |
| Access control | None — local | Per-document ACLs enforced at retrieval time |
| Serving | Static page, no keys (this site) | Backend proxy, per-IP rate limits, budget caps, abuse monitoring |
A static snapshot — no live API keys, nothing to abuse. Corpus: the
SmartDelivery infra + app repositories. Embeddings: text-embedding-3-small.
Generation: gpt-4o-mini. Hybrid retrieval: Azure AI Search (free tier).