Skip to main content
Palmidos Logo

APRIL 23, 2026

How to Train AI Agents on Business Documents: RAG vs Fine-Tuning

Training AI on company documents usually means retrieval (RAG), not fine-tuning. How to choose, the six build steps, and an acceptance test to run first.

Omer Shalom

Posted By Omer Shalom

11 Minutes read


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.

ApproachWhat changesGood forBreaks when
Retrieval (RAG)Nothing in the model. An index of your documents is searched for each question.Policies, contracts, manuals, client files, anything that changesDocuments are badly parsed or chunked, so the wrong passages come back
Fine-tuningThe model itself, through extra training on example inputs and outputsA fixed output format, a house style, narrow classification at high volumeFacts change. The model keeps answering from what it learned, with no source to show
Long contextNothing. The whole document set is pasted into every request.One long contract, one report, a small handbook that rarely changesThe 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.

SituationBest fitWhy
A few hundred HR or operations policies, updated every quarter, questions from many employeesRAGRe-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 suppliesFine-tuning (light)The problem is style, not knowledge
One long agreement that needs a risk review, onceLong contextBuilding an index for a single document is wasted work
Thousands of incoming emails a month to sort into fixed categoriesSmall fine-tuned modelA 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 formatRAG plus a light fine-tuneRetrieval 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.

Let's Talk About Your Project

A sample acceptance test for a document agent

Before anyone relies on the agent, it should pass a written test. A useful set has 30 to 50 questions collected from the people who will use it, not invented by the developer. Mix the question types so the test catches the failures that matter:

Question typeExamplePass condition
Direct lookupWhat is the notice period in the standard supplier agreement?Correct answer, cites the right clause
Answer spread across documentsWhich clients signed the old engagement letter and also have an open tax appeal?Combines sources, cites each one
Recently changed policyWhat is the current expense approval limit for team leads?Uses the newest version, not the archived one
Question with no answer in the documentsIs there a policy on crypto payments?Says it found no source, does not guess
Permission checkA junior employee asks about a partner-only fileRefuses or answers only from permitted files
Exact term or numberFind the clause that mentions section 8(c)Keyword search finds it even if meaning search does not

Write the expected answer and the expected source next to each question. Run the set before launch, after any change to chunking, prompts or models, and on a schedule. A system that cannot pass its own test should not reach customers or clients.

Common mistakes that ruin answer quality

Dumping PDFs straight in. If document parsing is a one-line script, answers will be mediocre. Complex documents need proper extraction, and scanned ones need OCR checked by a person on a sample.

Default chunk sizes. Tutorials pick one size for everything. Legal clauses, price tables and FAQ entries need different handling.

No metadata. Without source, date and access level on every chunk, the agent cannot filter, cite or respect permissions.

No evaluation. Teams launch, it "seems to work", and nobody measures until users complain. By then the fix is a rebuild.

Treating it as a one-time project. Documents change weekly and new sources get added. A document agent needs an owner, scheduled re-indexing and a review of flagged answers.

How do you keep company documents private?

Three layers matter. First, the model provider's terms: OpenAI states on its business data page that by default it does not use data from its API platform or business plans to train its models, and other major providers publish similar terms. Read the current terms and retention settings before sending client material. Second, where the system runs: a cloud region you choose, or an open-source model on your own servers when the data cannot leave. Third, permissions inside the system, enforced at retrieval time, with a log of who asked what. For Hebrew-heavy archives, model choice and search quality also change; see AI tools that work in Hebrew.

What does a real project look like?

An example from the accounting industry page: an AI assistant, still in development, that answers IFRS questions in Hebrew and English from one expert's body of knowledge, so accountants do not have to route every question through that expert. The pattern is typical. One well-defined body of knowledge, one group of users, answers that must point to a source.

A sensible path is to start with one document source and one use case (internal policy questions, client-file lookups, support macros), prove it against the acceptance test, then add sources. Once the agent answers well, it can also start acting: drafting a reply, filling a form, updating a record. That is the step into agentic workflows with human approval, and the retrieval layer is what keeps those actions grounded in the company's actual rules.

Build it, buy it, or use a ready document agent?

A managed tool with file uploads is a reasonable first test for a small team. It gets harder when the documents sit in several systems, when permissions differ by role, or when answers must follow a set format and cite sources. The trade-offs are laid out in ChatGPT vs a custom AI solution, and the cost drivers in what AI development costs. DocBrain is an AI agent that answers questions from a business's own documents, for companies that want that capability without a long build. When the archive and the rules are specific enough to need custom development, a short scoping conversation is the place to map sources, users and the acceptance test.

Frequently asked questions

Do I need a lot of documents for this to work?

No. Retrieval works on a small set. What matters is whether the documents actually contain the answers people ask for. A small, clean, current set beats a large, messy archive.

Does fine-tuning teach the model new facts?

Not reliably. Fine-tuning changes style, format and classification behavior. For facts that change, and for answers that must cite a source, retrieval is the right tool.

When is long context enough?

For a one-off review of a single long document, or a small handbook queried occasionally. It stops working when the set outgrows the window, when users have different permissions, or when query volume makes every request costly.

How do you keep company documents private?

Check the model provider's data terms and retention settings, choose where the system runs, and enforce permissions at retrieval time with a log of every question. For data that cannot leave, use an open-source model on your own servers.

Can an AI agent act on documents, not just answer?

Yes. The same retrieval layer grounds an agent that drafts replies, fills forms or updates records. Actions that change data or leave the company should go through a person for approval.

More articles that may interest you

Tell us what you need

One of our engineers will get back to you within 24 hours.

Still deciding?

Ask it.

Let an AI assistant give you its own take. Ask it who Palmidos is and how it builds AI for businesses, then decide for yourself.

How to Train AI Agents on Business Documents: RAG vs Fine-Tuning