Skip to content

📄 Preparing Documents for RAG ​

When you upload a document to your AI Agent, Ainisa doesn't feed the whole file to the AI at once. Instead, it splits the text into smaller pieces called chunks, converts them into embeddings, and stores them in a vector database. When a customer asks a question, only the most relevant chunks are retrieved and passed to the AI.

This means the quality of your answers depends heavily on how your document is structured. A well-organized file produces clean, self-contained chunks and accurate retrieval. A messy file produces broken chunks and vague or wrong answers.

This guide explains how to prepare documents (PDF, DOCX, TXT, MD) that work well with RAG.


✅ The Golden Rules ​

  1. Use real text, not scanned images. The document must contain selectable text. Scanned PDFs (photos of pages) have no extractable text and cannot be indexed properly.
  2. Keep sections short and focused. One idea per section. Long walls of text get split in the middle and lose meaning.
  3. Use clear headings. Headings give each chunk context and help the AI understand what a section is about.
  4. Make each section self-contained. A chunk should make sense on its own, without needing the paragraph before or after it.
  5. Prefer Q&A / FAQ format for support content — it matches how customers ask questions.

🧱 How to Structure Your Document ​

Use descriptive headings ​

Break your content into clearly titled sections. Instead of one long "About Us" page, split it:

  • Business hours
  • Delivery options
  • Return policy
  • Payment methods

Each heading becomes an anchor that keeps its chunk meaningful.

Keep paragraphs short ​

Aim for 2–5 sentences per paragraph. Avoid single paragraphs that run for a full page — they get cut across chunk boundaries and the AI loses the thread.

Make sections self-contained ​

Avoid references like "as mentioned above" or "see the previous section." When a chunk is retrieved alone, those references point to nothing.

❌ Weak:

As we said earlier, this also applies to the second option.

âś… Strong:

Express delivery also has free shipping on orders above 50 USD.

Use lists and tables for structured data ​

Prices, specifications, hours, and comparisons are clearer as lists or tables than as prose.

PlanPriceSupport
Basic10 USD/moEmail
Pro30 USD/moPriority

Write in a Q&A / FAQ style ​

For support and sales knowledge, phrase content the way customers ask:

Q: Do you offer refunds? A: Yes. You can request a full refund within 14 days of purchase by contacting support@example.com.

This format chunks cleanly and matches real questions almost word-for-word.


🚫 Common Mistakes to Avoid ​

  • Scanned or image-only PDFs — no extractable text.
  • Complex multi-column layouts — text extraction often mixes the columns together into unreadable order.
  • Everything in one giant section — no headings, no structure, poor chunking.
  • Important info trapped inside images, charts, or infographics — the AI can't read pixels; put the key facts in text too.
  • Heavy decoration (page headers/footers, watermarks, repeated boilerplate) — this noise ends up in chunks and dilutes retrieval.
  • Tables built with spaces/tabs instead of real tables — extraction scrambles them.

If you have a choice, Markdown (.md) and clean DOCX files usually produce the best chunks, because their headings and structure are explicit. Clean text-based PDF works well too. Use PDF when you need a fixed layout to share; use MD/DOCX when you just want the AI to read the content.


🤖 Using Claude to Restructure an Existing File ​

If you already have a document (for example a marketing PDF, a brochure, or an old policy file) that is not structured for RAG, you can use an AI assistant like Claude to convert it into a clean, RAG-friendly format.

Steps ​

  1. Open Claude (or a similar assistant).
  2. Upload your existing PDF or document.
  3. Ask it to restructure the content for a knowledge base.

Example prompt ​

I'm uploading a document that I want to use as a knowledge base for an AI support agent (RAG system). Please restructure it into clean Markdown with:

  • clear, descriptive headings for each topic
  • short, self-contained sections (no "see above" references)
  • a Q&A / FAQ format where it makes sense
  • tables for any prices, specs, or structured data Keep all the factual information, remove decorative filler, page headers/footers, and repeated boilerplate.
  1. Review the output — make sure no facts were changed, dropped, or invented.
  2. Save it as a .md file and upload it to your AI Agent.

Tip: Always read through the restructured file before uploading. AI can occasionally reword or drop details, so verify prices, dates, contact info, and policy terms are correct.


🔄 Workflow Summary ​

  1. Gather your source content (existing PDF, docs, notes).
  2. Structure it — headings, short sections, Q&A, tables. Or use Claude to restructure an existing file.
  3. Make sure it's real text, not scanned images.
  4. Save as .md, clean .docx, or text-based .pdf.
  5. Upload it to your AI Agent's knowledge base.
  6. Test with real customer questions and refine the sections that answer poorly.

💡 Notes ​

  • Supported formats: PDF, DOCX, TXT, MD.
  • Scanned PDFs are not reliably supported — use text-based files.
  • You can upload multiple files; split large knowledge bases into topic-focused documents rather than one huge file.
  • After uploading, always test with real questions and improve the sections that give weak answers.