Skip to main content

How to Prepare ERP Documents for RAG-Based AI Applications

Updated 6 min readMarkdown
How to Prepare ERP Documents for RAG-Based AI Applications

ERP systems store more than customer records, invoices and inventory data. They also contain purchase orders, supplier agreements, product manuals, quality reports and internal policies.

These documents hold useful business knowledge, but simply connecting them to an AI model does not make that knowledge searchable.

A retrieval-augmented generation (RAG) application needs documents that can be extracted, organised, indexed and retrieved with the right context.

Preparing ERP documents for RAG involves more than converting files into text. Here is how to build a practical document preparation pipeline.

1. Select the Right ERP Documents

Start with the questions your AI application should answer.

A procurement assistant may need supplier agreements, purchase orders and purchasing policies. A manufacturing assistant may need product specifications, quality reports and operating procedures.

Identify the relevant document types, source systems and business owners. Check whether documents are current, approved and suitable for the intended use.

Avoid indexing every available file. Unrelated or outdated documents can make retrieval less relevant and increase processing work.

2. Extract Text and Preserve Document Structure

ERP documents come in different formats, including PDF, DOCX, spreadsheets and scanned files.

Choose an extraction method based on the source:

  • Digital PDFs and DOCX files can be processed using document parsers.
  • Scanned PDFs and image-based files may require optical character recognition (OCR).
  • Spreadsheets need processing that preserves column names, rows and their relationships.

Document structure matters. For example, extracting invoice values without their column headings can make it difficult to distinguish quantities, unit prices and totals.

A common mistake is to treat every ERP document as plain text. This can cause problems when tables, revision details or approval information change how a value should be interpreted.

Preserve headings, table relationships, page numbers and section boundaries wherever they carry useful meaning. Review extracted content for OCR errors, missing sections and incorrect reading order.

3. Clean Content and Manage Document Versions

Before indexing, remove irrelevant content such as repeated headers, footers, duplicate copies and formatting artifacts.

However, do not remove information that provides business context. Document references, revision numbers, warnings and approval details may be important for retrieval.

Pay particular attention to document versions. If an old supplier agreement and its replacement are both indexed without clear version information, the application may retrieve outdated terms.

Maintain clear distinctions between current, superseded and archived documents. Keep a reference to the original file so retrieved information can be traced back to its source.

4. Add Metadata to Documents and Chunks

Metadata helps the retrieval system identify where information came from and whether it matches a user's question.

At the document level, useful fields may include the document ID, document type, supplier, source system, revision number, approval status and effective date.

For example, a purchase order might be identified as PO-1042, classified as a purchase order, linked to its supplier and marked as approved revision 2.

When the document is split into smaller chunks, retain relevant metadata with each chunk. Each chunk should have its own identifier while keeping a reference to the original document. Page numbers or section references can also help users trace retrieved information back to its source.

Metadata only improves retrieval when the application actually uses it for filtering, version selection, ranking or source tracking. Use verified values and fields that support the intended workflow.

5. Split Documents into Meaningful Chunks

Large documents are usually divided into smaller sections called chunks before embedding.

Avoid splitting content only at arbitrary character or token limits. A chunk should contain enough context to make sense when retrieved independently.

For better results:

  • Keep headings with their related paragraphs.
  • Preserve complete sections where possible.
  • Keep table headings connected to their values.
  • Retain document IDs and page references.
  • Use overlap where neighbouring sections need shared context.

There is no universal chunk size that works for every ERP document. A purchase order, product manual and quality report may need different strategies.

Test different approaches with realistic business questions before selecting a chunking method.

6. Generate Embeddings and Build the Retrieval Index

After cleaning and chunking, convert each text chunk into an embedding.

An embedding is a numerical representation of text that allows a retrieval system to compare semantic similarity between a user query and stored content.

Store the embeddings alongside the corresponding chunk text and metadata in a suitable search index or vector database.

Use the same embedding model for document chunks and user queries, following its documented query and document encoding requirements. If you use different models, make sure they are explicitly designed to produce compatible vectors in the same embedding space.

Depending on the application, you may use vector search, keyword search or hybrid search, which combines both approaches.

The goal is to retrieve relevant passages, not simply documents with similar names.

7. Enforce Access Controls and Test Retrieval

ERP documents may contain financial, employee, customer or contractual information.

The application must check the requesting user's permissions before returning document chunks. Access-control information should be carried through to the indexed chunks and enforced at retrieval time. Metadata filters can support this process, but they should be enforced by trusted application logic rather than relying on the language model to decide what a user can access.

Also consider document updates. When a source document changes, reprocess the affected content, regenerate embeddings where necessary and replace or remove obsolete chunks from the index. If access is revoked or a document is deleted, propagate that change to the relevant indexed content and derived data.

Consider this example: a procurement employee asks, "What are the payment terms in the currently effective, approved supplier agreement?"

The retrieval system should identify the correct supplier, filter for the currently effective and approved agreement, and retrieve the section containing the payment terms. It should then provide an answer with a reference to the source document and, where available, the relevant page or section.

Test with different user roles as well. A user without permission to view a document must not retrieve its contents through search or citations.

Also treat retrieved document content as untrusted input. Do not allow instructions found inside documents to override the application's system instructions or security rules.

Final Thoughts

Preparing ERP documents for RAG requires careful handling of document structure, versions, metadata, chunking and permissions.

A well-designed pipeline makes business information easier to retrieve and gives the language model relevant source material to work with. It does not guarantee correct answers, so retrieval and response quality must still be tested.

If you are planning AI integration, start with these eight ERP data readiness checks before integration. They cover the broader data requirements, while document preparation is a more specific part of building a RAG application.

The objective is to make the right business information available to the right users, with enough context to support useful AI responses.

About the author

  • Passionate about crafting meaningful content that bridges the gap between business needs and tech solutions. At BizzAppDev, Saurabh specializes in communicating the power of Odoo through storytelling, strategy, and clear messaging. When he's not writing or optimizing content, he's diving deep into the latest Odoo features and ERP trends.

Calling out table structure, revision numbers, and approval metadata as non-negotiable parts of ERP document prep hits the exact failure mode that breaks enterprise assistants. Flattening an invoice or purchase order into plain text strips the link between quantities, unit prices, and line totals, and dropping revision tags lets a superseded supplier policy outrank the active version.

Scoping ingestion to approved, business-owned document types instead of dumping every legacy export into the index also pays off immediately. Smaller, version-pinned corpora consistently beat larger noisy indexes on both retrieval precision and auditability.