mjdeving
← concepts

Context & Retrieval

RAG

Fetching relevant context before generation. Vector search is the common way, not the only one.

RAG stands for retrieval-augmented generation: fetch the relevant material first, put it in the prompt, then generate. The problem it solves: a language model knows two things, what it absorbed in training, frozen in its weights, and whatever text you hand it in the prompt. It cannot look anything up on its own, so if the answer is in your documents, last week’s tickets, or a database, the model cannot see it.

Mechanically it is a pipeline. You split your sources into chunks, store them (usually as vector embeddings, so closeness in meaning becomes a math operation), and at query time you fetch the chunks nearest the question and prepend them. The model answers from what you fed it instead of from its weights alone.

RAG quality depends mainly on the four stages that decide what retrieval sends to the model: parsing, chunk boundaries, keyword and vector search, and reranking. A modest model answers well when those stages return the right evidence. A stronger model cannot recover evidence the retriever omitted.