For most businesses, "training" an AI agent on company documents does not mean training a model at all. It means retrieval (RAG): the documents sit in a searchable index, the agent pulls the few passages that matter for each question, and it answers with a link to the source. Fine-tuning changes how a model writes, not what it knows. Pasting everything into the prompt (long context) works only for a small, stable set of documents.
The question usually comes from a specific pain. Staff spend their day hunting through shared drives. Senior people answer the same internal questions every week. New employees take months to learn where things are. An accounting firm is a typical case: answers live in standards, client files, internal memos and years of email, and a wrong answer has a cost. This guide explains the three approaches, how to choose between them, how a document agent is built, and how to test it before anyone relies on it.
What does "training AI on your documents" actually mean?
When a vendor says it will train an AI on your data, it can mean three very different things. They differ in what changes, what it costs to keep current, and what can go wrong.
| Approach | What changes | Good for | Breaks when |
|---|---|---|---|
| Retrieval (RAG) | Nothing in the model. An index of your documents is searched for each question. | Policies, contracts, manuals, client files, anything that changes | Documents are badly parsed or chunked, so the wrong passages come back |
| Fine-tuning | The model itself, through extra training on example inputs and outputs | A fixed output format, a house style, narrow classification at high volume | Facts change. The model keeps answering from what it learned, with no source to show |
| Long context | Nothing. The whole document set is pasted into every request. | One long contract, one report, a small handbook that rarely changes | The set grows past the window, or query volume makes every request expensive |
OpenAI's own guide to optimizing LLM accuracy frames the choice by the type of failure. If the model lacks knowledge (it was never in its training data, or it is out of date), add context with retrieval. If the model knows enough but behaves inconsistently (wrong format, wrong tone), fine-tune. The guide also notes the two methods are additive: a production system can use both.
Size matters too. Anthropic's write-up on contextual retrieval says that a knowledge base under about 200,000 tokens (roughly a few hundred pages) can often go straight into the prompt, with prompt caching keeping the cost down. Above that, retrieval is the practical route.
Which approach fits your documents?
Most real cases fall into one of a handful of patterns. The table below is the shortcut.
| Situation | Best fit | Why |
|---|---|---|
| A few hundred HR or operations policies, updated every quarter, questions from many employees | RAG | Re-indexing a changed policy takes minutes; retraining a model takes days and still gives no citation |
| Drafts that must follow the firm's structure and tone, on facts the drafter supplies | Fine-tuning (light) | The problem is style, not knowledge |
| One long agreement that needs a risk review, once | Long context | Building an index for a single document is wasted work |
| Thousands of incoming emails a month to sort into fixed categories | Small fine-tuned model | A narrow, repeated task where a small model is cheaper to run |
| A support or knowledge agent that must be current and answer in a fixed format | RAG plus a light fine-tune | Retrieval keeps facts fresh; the tune keeps answers consistent |
Does fine-tuning teach the model new facts?
Not reliably. Fine-tuning shifts behavior: phrasing, structure, which category to pick. It can absorb some facts, but it cannot tell you which document an answer came from, it does not know who is asking, and every policy change means another training run. "The model should know the product range" is almost always a retrieval problem.
When is long context enough?
When the job is a one-off review of a single document, or a small handbook that a few people query occasionally. It stops being enough when the document set outgrows the window, when different users may see different files, or when every one of thousands of daily questions pays to process the whole corpus again.
How do you build an AI agent on business documents?
A document agent that people trust is built in six steps. The middle steps are engineering; the first and last decide whether the project succeeds.
1. Inventory the documents
List which documents matter, where they live (file server, SharePoint, Google Drive, email, a document management system), who owns each source, how often it changes, and what is confidential. Most of the value usually sits in a small part of the archive. Start there, and decide which version wins when the same document exists in three folders.
2. Extract and clean the text
Raw PDF extraction breaks tables, merges columns and loses headings. Scanned files need OCR. Footers, disclaimers and page numbers add noise. This unglamorous step has more effect on answer quality than the choice of model.
3. Split documents into sensible chunks
The index stores passages, not whole files. Cutting at a fixed size slices a contract clause in half or separates a table from its header. Chunk by structure instead: keep a section together, carry the document title and heading with every chunk, and overlap slightly at the edges. FAQs want short chunks; narrative reports and legal text want longer, structure-aware ones.
4. Index with metadata and permissions
Each chunk is turned into an embedding (a numeric representation of meaning) and stored in a vector index. For many companies an extension such as pgvector inside an existing PostgreSQL database is enough. Every chunk should carry metadata: source, section, date, department and access level. That is what lets the agent filter by context and respect the rule that a junior employee does not see the partners' files.
5. Retrieve, rerank and answer with a citation
For each question the system finds candidate passages, combines meaning-based search with keyword search (so exact terms like a client number or a section of a standard are not missed), reranks the results, and passes the best few to the model with instructions to answer only from them and cite the source. Anthropic reported that adding context to each chunk before indexing, combined with keyword search, cut failed retrievals by 49% in its tests, and by 67% with reranking added (source).
6. Measure before launch, and keep measuring
Build a fixed test set of real questions with known answers, run it before launch and after every change, and keep a feedback button in front of users. Quality drifts quietly when documents change and indexes go stale.
For a plain-language primer on the retrieval layer itself, see how RAG document search works.