Skip to content

AI

RAG Explained: An AI Assistant That Answers From Your Own Documents

By Synvica8 min read

In short

Retrieval-augmented generation (RAG) makes an AI assistant answer from your own documents. When someone asks a question, the system first searches your content for the most relevant passages, then hands them to a language model with instructions to answer only from them and cite them. RAG suits knowledge that changes often or must stay traceable, such as policies, product documentation and procedures. Quality depends mostly on the retrieval side: clean and current content, sensible splitting of documents, filtering by each user's permissions, and an evaluation set that checks both what was found and what was answered.

Retrieval-augmented generation (RAG) lets an AI assistant answer questions from your own documents instead of from whatever a language model absorbed during training. The system looks up the relevant passages first, then asks the model to write an answer from them, with references back to the source.

It is the usual way to build an internal knowledge assistant, a support bot or a search tool that answers in full sentences. This guide explains how it works in plain words, when it beats the alternatives, and what separates a dependable assistant from a demo.

How does RAG work, in plain words?

Picture a well-briefed assistant with a good filing system. Before answering, they pull the few most relevant pages from the files, read them, and answer from those pages, noting where each point came from. RAG does the same in two phases.

Preparing your content (indexing)

Documents are collected from their sources, cleaned and split into passages of manageable size, often called chunks. Each chunk is converted into an embedding, a list of numbers that represents its meaning, and stored in a search index together with metadata such as title, date, owner and who may see it.

Answering a question (retrieval and generation)

When a question arrives, it is converted the same way, and the index returns the passages closest in meaning. Many systems combine this with classic keyword search, which handles product codes and exact names better. The best passages go into the prompt with instructions to answer only from them, cite them, and say so when they do not contain the answer.

The 2020 paper that named the technique, by Patrick Lewis and colleagues, presented it as a response to two open problems with language models: providing provenance for their outputs and updating their knowledge. Those are still the two main reasons businesses use it.

RAG, fine-tuning or a long prompt: which do you need?

There are three common ways to give a model your company's knowledge, and they solve different problems.

ApproachWhat it doesBest forWatch out for
RAGLooks up relevant passages at question time and answers from themKnowledge that changes, answers that must cite sources, content with access rulesQuality depends on retrieval and on content upkeep
Fine-tuningAdjusts the model's weights using your examplesA consistent format, tone or narrow task at scaleFacts go stale, no citations, retraining needed to update
Long promptPastes whole documents into every requestA few short documents, prototypesCost per request, and answers can degrade when key facts sit mid-context
CombinationAn instructed or fine-tuned model on top of retrievalMature products with both style and knowledge needsMore moving parts to test

The CNIL, France's data protection authority, describes RAG as producing outputs that are potentially more specific and easier to update than the model itself, with better traceability of the information in answers, at the cost of more resources and skills than an off-the-shelf model. Research also argues against stuffing everything into one prompt: the 2023 study Lost in the Middle found that models often performed best when relevant information sat at the beginning or end of a long input, and significantly worse when it sat in the middle.

What does your content need before RAG can work?

Most RAG problems are content problems. The model can only be as right as the passages it is handed, so preparation deserves more attention than model choice.

  • Pick the sources deliberately. Start with a bounded set, such as the help center and current policies, rather than the whole shared drive.
  • Remove duplicates and old versions. If three versions of a policy exist, the assistant may quote the wrong one. Mark one as authoritative and retire the rest.
  • Give each source an owner who keeps it current and hears about the questions the assistant could not answer.
  • Extract text properly. Scanned PDFs need text recognition, and tables, headings and lists should survive extraction, because structure carries meaning.
  • Split along the document's structure, by section rather than by a fixed number of characters, and keep the document title and section name with each chunk.
  • Keep the metadata, such as date, product, region, language and access rights, so retrieval can filter on it.

How do you keep answers within each user's permissions?

An assistant must never reveal a document that the person asking could not open themselves. Enforce this in retrieval, not in the prompt: store access rights with each chunk, filter every search by the user's identity and groups, and keep those rights in sync with the source systems, so that revoking access at the source also removes it from the assistant.

OWASP lists vector and embedding weaknesses among its top risks for LLM applications, including leaks between users who share an index and poisoned content. Its mitigations include permission-aware vector stores, strict partitioning between groups of users, accepting data only from trusted sources and keeping detailed logs of retrieval. Its poisoning example is a CV with hidden white-on-white text telling the system to recommend the candidate: retrieved documents can carry instructions as well as facts.

Personal data needs the same care. The CNIL notes that an organization connecting a generative AI system to its own knowledge base is responsible for that processing when the knowledge base contains personal data.

How should the assistant cite its sources?

Citations turn a fluent answer into a checkable one. For each answer, show the documents used, with a link that opens the exact section and ideally the quoted passage. Ask the model to tie each statement to a passage, then check in code that every cited source was among those retrieved, so the model cannot invent a reference.

Make no-answer a valid answer. When the retrieved passages do not contain the answer, the assistant should say so and offer a next step, such as a search link or a hand-off to a person. An assistant that admits gaps earns more trust than one that always sounds sure.

How do you measure whether a RAG assistant works?

Evaluate retrieval and generation separately, because they fail for different reasons. The authors of Ragas, a framework for evaluating RAG pipelines, make the same split: whether the system finds relevant, focused passages, whether the model uses them faithfully, and the quality of the answer itself.

  1. Build a question set from real questions, each with the document that should be found and the expected answer. Include questions your content cannot answer.
  2. Score retrieval: is the right passage among the top results? If not, no prompt will fix the answer.
  3. Score faithfulness: is every statement in the answer supported by the retrieved passages?
  4. Score usefulness: does the answer address the question, and do the citations point to the right places?
  5. Rerun the set after every change to content, chunking, search settings, prompt or model.

In production, collect thumbs up and down with a reason, track how often the assistant declines to answer, and review a sample of conversations every week. Questions with no good source become a to-do list for your content owners.

Where does RAG go wrong?

Most failures follow a handful of patterns, and each has a known fix.

SymptomLikely causeFix
Confident answer, wrong factsThe right passage was not retrievedImprove chunking and metadata, add keyword search, inspect retrieval results
Quotes an outdated policyOld versions are still indexedRetire old documents, favor recent ones, assign owners
Half-right answerA chunk separated the answer from its contextSplit by section and keep headings with each chunk
Cannot answer totals or countsThe answer is spread across many recordsRoute such questions to a database query or report
Shows content the user should not seePermissions not enforced at retrievalFilter by user rights at query time, sync access from sources
Follows odd instructionsInstructions hidden in an indexed documentIndex trusted sources only, treat retrieved text as data, review content

Questions such as how many contracts renew next quarter are a common trap: they need a query over structured data, not a few passages. A well-designed assistant recognizes them and hands them to the right tool.

FAQ

Does RAG stop hallucinations?

It reduces them but does not eliminate them. Answering from retrieved passages, with instructions to stay within them and citations users can check, makes wrong answers rarer and easier to spot. The model can still misread a passage or fill a gap, so keep evaluation running, let the assistant say it does not know, and keep a person in the loop where errors are costly.

Do we need a dedicated vector database?

You need an index that supports search by meaning, but not necessarily a separate product. Many databases and search engines now offer vector search alongside keyword search. Choose based on your volume, your permission-filtering needs and what your team already runs, rather than adding a new component by default.

Can RAG work with documents in several languages?

Yes, if the embedding model handles your languages and you test it. Multilingual embedding models can match a question in French to a passage in English, but quality varies, so include questions in each language in your evaluation set. Store each document's language as metadata, and decide whether answers follow the language of the question or of the source.

What drives the cost of a RAG assistant?

To build, the number and messiness of sources, the permission rules, the integrations and the evaluation work matter more than the model itself. To run, model usage grows with traffic and with how many passages each request carries, plus indexing and hosting. Estimate tokens per question and multiply by expected volume rather than relying on averages.

How Synvica builds RAG assistants

Synvica treats a RAG assistant as a data product as much as an AI feature. We usually start with a short discovery phase that audits your sources and builds the question set, then work in two-week sprints that each end in a live demo on your own documents, with retrieval and answer quality measured every time. You own the code, the index and the cloud accounts.

See our AI and automation and data and analytics services, or contact us to talk about your documents.

Written by the Synvica team, which designs, builds and runs custom software, web platforms, mobile apps and AI features.