Answers · AI basics

What is RAG, and how does AI answer from your own documents?

In short

Retrieval-augmented generation (RAG) lets an AI model answer from your files. When someone asks a question, the system searches your documents, picks the few passages that match, and sends them to the model with the question. The model answers from those passages. It is only as good as the documents and the search behind it.

How does RAG work?

The method comes from a 2020 research paper by Lewis and colleagues. Anthropic's description of the usual setup has three steps:

  • Prepare. Split your documents into chunks of a few hundred tokens each, turn each chunk into an embedding (a list of numbers that captures its meaning), and store them in a searchable index.
  • Search. When a question comes in, find the chunks closest in meaning. Adding plain keyword search helps with exact terms such as part numbers and error codes.
  • Answer. Send the best chunks and the question to the model, with instructions to answer only from them and to name which document each fact came from.

The search step decides most of the quality. Anthropic reported that adding context to each chunk, keyword search and a reranking step cut failed retrievals by 67% in its tests.

What does it cost to run?

The model calls are usually small. OpenAI's docs put its small embedding model at about 62,500 pages per dollar, so indexing 1,000 pages costs pennies. A typical question sends around 3,000 tokens of passages and instructions and gets back about 400. At Claude Sonnet 5.5 prices that is roughly one cent per question.

The larger costs are elsewhere: building the pipeline, hosting the index, keeping documents in sync, and someone checking answers. On your own hardware, the per-question bill goes away and the machine and its upkeep take its place.

What goes wrong?

  • Stale documents. If last year's price list is still in the index, the model will quote it. Old versions need to be removed, not only new ones added.
  • Permissions. If the index holds payroll files, anyone who can ask questions may get answers from them. The search must apply the same access rules as your file system.
  • Bad search. If the right passage is not retrieved, the model answers from the wrong one or guesses. See why AI makes things up.
  • Messy files. Scanned pages, tables and spreadsheets need cleanup before they search well.

When does RAG fit?

  • Staff keep asking questions whose answers sit in your documents: policies, manuals, past proposals, product specs.
  • The documents change, so training a model on them would go stale.
  • You want each answer to point to the file it came from.
  • The set is too large to paste in. Under about 500 pages, Anthropic suggests sending it all in the prompt instead.

Where do we start?

We start with one set of documents and a list of real questions staff ask, then measure how often the right passage comes back before anyone relies on the answers. We build this on a client's own data, and on their hardware when it must stay in-house. See private AI.

Questions owners ask

Does RAG train the model on my files?

No. The model itself does not change. Your passages are sent with each question and used for that answer only.

Can it run without sending files to the cloud?

Yes. The search index and an open-weight model can both run on your own hardware, at the cost of upkeep and usually a less capable model.

How big does a document set need to be before RAG is worth it?

Anthropic suggests that a knowledge base under about 200,000 tokens, roughly 500 pages, can often go straight into the prompt without RAG.

Want AI that answers from your own documents?

We set up private AI on hardware you own, and AI agents for the jobs someone repeats every day. It starts with a written plan and a fixed price.