Free | No tracking | Every fact with a source|German and English

AI course / Module 4: Keep going

Lesson 11/12 Your own documents and RAG

How a language model uses RAG to answer questions about your own documents — completely local. · 6 min.

A language model knows a lot, but not your files. It knows nothing about your user manuals, contracts, notes, or company handbooks. With a technique called RAG, you change that. And the best part: It works completely locally, without your documents leaving the PC.

The problem: the model doesn't know it

You remember lesson 2. A language model answers from its fuzzy training knowledge. If you ask it about your lease, it doesn't know it. In the worst case, it makes up a plausible answer.

The obvious solution: You just copy the text into the chat. That works very well for short documents. But with a folder full of PDFs, you quickly hit the limit of the context window. And a huge context needs a lot of memory and makes the model slow.

The solution: search first, then answer

RAG stands for “Retrieval-Augmented Generation.” In German, roughly: generation with prior search. The idea is simple:

  1. You ask a question.
  2. A search program finds the matching text passages in your documents.
  3. Only those passages are sent to the model along with your question.
  4. The model answers based on those passages.

An analogy: Think of an open-book exam. You don't have to know everything by heart. You only need to find the right page and then phrase your answer well. The model is the good wordsmith, while the search program flips to the right pages first.

How the search works

To make the search work, your documents are prepared in advance:

  • Split up: Each document is divided into small sections, called Chunks. These might be a few paragraphs.
  • Convert: A special small model, an Embedding-Modell, turns each section into a kind of meaning fingerprint. Sections with similar meaning get similar fingerprints.
  • Store: The fingerprints are saved in a database, often called a vector database.

When you then ask a question, it gets a fingerprint too. The database looks for the sections whose fingerprints are most similar. The trick: This works by meaning, not just exact words. The question "How long is my warranty?" also finds a section with the phrase "Gewährleistungsfrist."

Try RAG

You don't have to build such a system yourself. Several programs already include the feature:

  • Open WebUI together with Ollama can ingest and search documents.
  • LM Studio lets you attach documents to a chat.
  • There are also specialized programs for document collections.

How to set it up in practice is shown in the guide Chat with documents. You can find ideas for use cases under Applications: Chat with documents.

Tip: Start with a few well-readable documents. That makes it easy to check whether the answers are correct before you throw in an entire folder.

What RAG does well

  • Answer specific factual questions in your documents.
  • Find the right passage in a long manual.
  • Provide answers with a source citation, meaning a reference to the document.
  • Keep knowledge up to date: Add a new document, and the knowledge is there. No retraining needed.

Where RAG reaches its limits

RAG is not a miracle cure. Typical weaknesses:

  • The search finds the wrong thing: If the right passage isn't found, the model can't use it either. Then it answers incorrectly or says it doesn't know.
  • Overview questions: "Summarize all 200 documents" works poorly because only a few sections are found each time.
  • Hard-to-read files: Scanned PDFs without text recognition, complex tables, or images are often not captured correctly.
  • Broken context: If an important piece of information is spread across multiple sections, sometimes only part of it is found.

Important: Even with RAG, a model can make mistakes. For important matters, check the cited source in the original document.

Tuning knobs for better results

If the answers don't fit, you can adjust a few things. Exactly where depends on the program:

  • Chunk size: Smaller sections find details more precisely, larger ones preserve more context.
  • Number of hits: More found sections give the model more material, but also use more context.
  • Embedding model: Some understand German much better than others.
  • Language model: A stronger model uses the found passages more skillfully.

RAG or training?

Many people first think: "I'll just train the model with my documents." For factual knowledge, though, RAG is usually the better choice. It's cheaper, faster to set up, easier to update, and provides sources. Training is more suitable for changing a model's style or behavior. More on that in the next lesson.

The most important points at a glance

  • RAG first searches for matching passages in your documents and passes them to the model.
  • An embedding model enables meaning-based search instead of word-only search.
  • Open WebUI, LM Studio, and other programs include RAG features.
  • RAG is strong for specific questions, weak for overview questions across many documents.
  • For factual knowledge, RAG is usually better than training your own model.

Short quiz

1. What happens with RAG before the model answers?
2. What is the embedding model used for in RAG?
3. Which question does a RAG system typically answer poorly?