RAG explained

RAG stands for retrieval-augmented generation: look things up first, then answer. The system finds the relevant passages in your own documents and hands them to the model together with the question. The model answers from what it was just given and cites the source. It does not learn your data – it reads it every…

Last checked:

Step by stepHow it works, step by step
  1. Documents are cut into chunks
  2. Each chunk gets an "embedding"
  3. The numbers are stored in a vector database
  4. The question gets an embedding too
  5. The model answers from the chunks it found

How it works, step by step

  1. Documents are cut into chunks. A 40-page staff handbook becomes perhaps 150 chunks of a couple of paragraphs each. Small chunks make it possible to find exactly the paragraph that answers the question.
  2. Each chunk gets an “embedding”. An embedding is a long list of numbers describing what the text is about. Texts with the same meaning get similar numbers, even when the words differ.
  3. The numbers are stored in a vector database. That can be a separate service such as Pinecone or Qdrant, or your ordinary PostgreSQL with the pgvector extension.
  4. The question gets an embedding too. The database finds the chunks whose numbers are closest to the question’s. This is called cosine similarity.
  5. The model answers from the chunks it found and must state which chunk each claim comes from. If the search finds nothing relevant, the system should say “I don’t know” instead of guessing.

We build it this way ourselves. In our own product jajob.dk the vectors live in PostgreSQL with pgvector, next to ordinary keyword search. Embeddings, language model and vector store are swappable modules, so we can test locally with a simple cosine calculation and use pgvector in production. That lets us change vendor without rebuilding the search.

When ordinary search is enough

RAG is not always the answer. If staff search for an item number, a customer name, a case number or an exact phrase, ordinary full-text search is faster, cheaper and more predictable. PostgreSQL has it built in, and we use Meilisearch for search in several products.

Search, semantic search or RAG?

NeedFull-text searchSemantic searchRAG (search + answer)
Findsexact words, numbers, namesthe same meaning in other wordsa written answer with a source
Example“invoice 10442”“rules for resignation” finds “notice period”“What notice does a salaried employee have with us?”
Cost per searchalmost zeroalmost zero (one embedding)one model call, usually under 1 øre
Fails ontypos, synonymsshort codes and numbersanswers the source does not support
Fitsarchives, cases, stockknowledge bases, FAQs, job adshandbooks, contracts, procedures
Rules of thumb from our own projects

Often the best is both. In jajob we combine BM25 keyword search with vector search and let a reranker sort the results. Keyword search catches the exact words; vector search catches the meaning.

Language is a classic trap

A business in Denmark quickly ends up with documents in Danish, English and maybe Ukrainian, Polish or German. Embeddings do understand meaning across languages, but not always well enough. We measured a similarity of only 0.048 when a Danish customer asked “hvornår har I åbent” (when are you open) in a Ukrainian knowledge base. When a model wrote eight likely questions per article at indexing time – three in Ukrainian, three in Danish and two in English – similarity rose to 0.84. It costs one model call per saved article, not per question. The generated questions go into both keyword and vector search, and the system answers only when the score is high enough. Otherwise it stays silent.

RAG, fine-tuning or MCP?

Here is the short answer. A table of which method fits which job, and what each costs, is on the RAG vs fine-tuning vs MCP page.

Fine-tuning means training a model further on your own examples. It changes style and format, but it is a poor way to teach a model facts: it cannot cite a source, and every time a handbook changes you have to train again. For questions about your documents, RAG is almost always the right choice.

MCP (Model Context Protocol) is a standard that lets an AI assistant call your systems directly – look up an order or fetch a customer. It suits structured data with an API. RAG suits text: handbooks, contracts, e-mails. Many solutions use both. More on agents and MCP at agent.best-choice.dk.

Everything in one prompt. Modern models can read a lot of text at once. With fewer than a hundred pages, a project in ChatGPT or Claude may be enough. Claude switches to RAG search by itself when project knowledge approaches the limit. For a course archive we chose a third way: a set of Markdown files with llms.txt and a manifest that any AI can read – ChatGPT, Claude, Cursor or NotebookLM – rather than hosted RAG or MCP.

Sources

Last reviewed: 2026-12-03

Questions about RAG

Does the model learn our data when we use RAG?

No. The model gets the relevant chunks with each question and forgets them afterwards. The big vendors’ business plans also do not train on your data by default – but check your agreement.

What is a vector database?

A database that can find the number lists (embeddings) closest to a given one. It can be a dedicated service, or PostgreSQL with pgvector, which many companies already run.

How many documents before RAG makes sense?

Under a hundred pages, a project in ChatGPT or Claude may do. Thousands of documents, or access that must be controlled per person, need a real search.

Can RAG get it wrong?

Yes. It can find the wrong chunk, or the model can say more than the source does. That is why you test with real questions and check the sources. See Quality and testing.

Fixed price, no commitment

Get a fixed price for AI on your own data

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?