AIUpdated 2026-11-20

RAG

Retrieval before generation: chunking, embeddings, hybrid search, reranking, citations, and what to do when retrieval finds nothing.

A filing cabinet indexed by meaning, so the assistant finds the right pages first.

That is retrieval-augmented generation. Before the assistant writes an answer, someone fetches the pages that look relevant, and the assistant answers from those pages only.

How it works

RAG answers a question by first retrieving relevant passages from your own knowledge, such as website pages, files and FAQs. It then asks the model to answer only from those passages, ideally with citations. This grounds the model in facts it was never trained on.

Code
Ingest: source → clean text → chunk → embed → store (text + vector + metadata)
Query:  question → embed → hybrid search → rerank → top few → prompt → answer + citations

A vector search in Postgres with pgvector looks like this:

Code
select id, content, 1 - (embedding <=> $1) as score
from knowledge_chunks
where tenant_id = $2
order by embedding <=> $1
limit 20;

The concerns that matter

  • Chunking. Split by structure, such as headings and paragraphs, into roughly 300 to 800 tokens with a small overlap. Keep the title and URL with each chunk.
  • Embeddings. Use one model per index. Changing it means re-embedding everything, so store the model name beside the vector.
  • Storage. pgvector keeps vectors next to tenant data and row-level security, which is enough for millions of chunks with an HNSW index. A dedicated vector store is the alternative when scale or features demand it.
  • Hybrid search. Combine vector similarity with keyword search and merge the results. Keywords catch names, codes and prices that embeddings miss.
  • Reranking. A cross-encoder or model reranker on the top 20 to 50 results improves precision before the best few go into the prompt.
  • Citations. Return which chunks were used, and show the sources to users and staff.
  • Freshness. Re-crawl on a schedule, hash content to skip unchanged pages and delete chunks of removed sources.
  • Knowledge gaps. When retrieval scores are low, say "I don't know", hand over to a person and log the question as a gap for the business to fill.

Every step before the model call costs time. For a spoken or chat answer, retrieval, reranking and generation add up, so each step has to earn its place.

When RAG is the wrong tool

  • The knowledge is tiny and fits directly in the prompt.
  • The question needs computation or live data. Use a tool or action call.
  • You want to change behaviour or style. That is prompting or fine-tuning, not retrieval.

Checking retrieval on its own

Build a small set of real questions, each with the page that should answer it. Run only the search step and see whether that page appears in the top results. When it does not, no prompt change will help, and the fix is in chunking, search or the source content. Doing this separately from answer quality saves a great deal of guessing.

Where I used it

HealthBridge AI is an early-stage health assistant with retrieval over a vector store, built with Groq, ElevenLabs, Qdrant and LangChain. It has no case study. Its stated problem is that a spoken answer has to arrive in seconds, so every retrieval step is a latency cost.

I make no claim beyond that: no accuracy figures, no latency numbers and no details of its chunking or ranking.

Trade-offs

BenefitCost
Current, tenant-specific answersAn ingest pipeline, crawl jobs and storage
Fewer made-up answers, with citationsRetrieval quality caps answer quality
No model training neededRe-embedding cost when the model changes
  • Garbage in, garbage out. Poorly cleaned pages produce poor chunks, and the model cannot repair them.
  • Access control must travel with the data. In a multi-tenant product, a search must be filtered by tenant, or one customer can read another's documents.
  • Retrieved text is untrusted. A page can contain instructions aimed at the model. Treat it as data, as in the LLM integration note.
  • Evaluation is its own job. Keep saved questions with the passages that should be found, and check retrieval separately from generation.

A useful rule: when the answer is wrong, look at what was retrieved before blaming the model. Most bad answers start with the wrong pages.