Back to cookbook

AI Prompt to Chunk Documents for a RAG Pipeline

20 views Published

Make this prompt yours

Share

This AI prompt for chunking documents in a RAG pipeline helps you split long PDFs, manuals, or knowledge-base articles into retrieval-friendly pieces before they're embedded and indexed. It's aimed at developers and data teams building a retrieval-augmented generation (RAG) system who are past the "just split every 500 words" stage and need chunks that actually preserve meaning.

Poor chunking is one of the most common causes of bad RAG answers — a chunk that cuts a table in half, or splits a definition from the term it defines, gives the retriever a fragment the model can't use correctly even if the embedding search works perfectly. The prompt asks the model to reason about document structure (headings, lists, tables) rather than applying a fixed character count blindly, and to flag sections that shouldn't be split at all.

If your source documents are long PDFs or CSVs and you're not sure which sections are even relevant before you chunk them, Context Extractor is worth running first — it pulls the relevant snippets out of a large document via RAG, which can cut down what you need to chunk and index in the first place.

Prompt template

Make this prompt yours

prompt-template
221 tokens
ROLE: You are a document processing assistant preparing content for a retrieval-augmented generation (RAG) system. CONTEXT: - Document type: [MANUAL, FAQ, POLICY DOC, API REFERENCE, ETC.] - Target chunk size: [APPROXIMATE TOKEN OR WORD COUNT] - Embedding model or vector database being used: [MODEL/DATABASE NAME] - Document content follows: [PASTE DOCUMENT TEXT] TASK: Split the document above into chunks suitable for embedding, following these rules: 1. Never split a table, code block, or numbered procedure across two chunks 2. Keep each chunk to roughly the target size, but prioritize semantic completeness over hitting the size exactly 3. Attach the relevant section heading to each chunk as metadata 4. Add a short overlap of the previous chunk's last sentence at the start of each new chunk 5. Flag any section that should not be split at all, with a one-line reason OUTPUT FORMAT: Return a numbered list of chunks. For each chunk, show: [Heading], [Chunk Text], [Overlap Note].

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
120 tokens
Document type: internal API reference page Target chunk size: ~300 tokens Embedding model: text-embedding-3-large Document content: "## Authentication\nAll requests require a Bearer token in the Authorization header. Tokens expire after 24 hours.\n\n## Rate Limits\n| Plan | Requests/min |\n|------|---------------|\n| Free | 60 |\n| Pro | 600 |\nExceeding the limit returns a 429 response.\n\n## Error Codes\n401: Invalid token. 429: Rate limit exceeded. 500: Server error."

When to use it

  • When preparing a knowledge base, help center, or internal wiki for embedding into a vector database
  • When your current RAG answers are missing context because chunks are cut mid-sentence or mid-table
  • Before re-indexing a document set after switching embedding models or chunk sizes
  • When source documents mix long prose, tables, and code blocks that need different chunking rules

Best practices

  • Chunk by semantic unit (a heading section, a table, a list) before falling back to a fixed token or character limit
  • Keep a small overlap between adjacent chunks so context isn't lost at the boundary
  • Preserve the section heading or title as metadata attached to each chunk, not just the raw text
  • Test retrieval quality on a handful of real user questions after changing your chunking strategy, not just on chunk count

Common mistakes

  • Splitting strictly by character count and cutting a table or code block in half
  • Losing the document title or section heading, so retrieved chunks have no context on their own
  • Using one fixed chunk size for every document type instead of adjusting for prose vs. tables vs. FAQs
  • Never testing retrieval on real questions, only checking that chunking ran without errors

FAQs

What's the ideal chunk size for a RAG pipeline?

There's no single right answer — it depends on your embedding model and content type, but most teams start around 200–500 tokens per chunk and adjust based on how well retrieval performs on real questions, not a fixed rule.

Why does chunking strategy matter more than embedding model choice sometimes?

A strong embedding model can't fix a chunk that's missing context — if a chunk is cut mid-table or separated from its heading, the retriever may find it, but the model still won't have enough information to answer correctly.

Should I use overlapping chunks or non-overlapping chunks?

A small overlap (one or two sentences) between adjacent chunks is usually worth the extra storage, since it prevents context from being lost right at a chunk boundary, especially for prose-heavy documents.

How do I know if my chunking strategy is actually working?

The only reliable test is running real user questions through your retrieval pipeline and checking whether the returned chunks contain what's needed to answer them, not just measuring chunk count or size.

What tool can help me pull the right content out of large source documents before I chunk them?

Context Extractor — pulls only the relevant snippets from large PDFs, CSVs, or docs via RAG, which reduces what you need to chunk and index and helps cut hallucinations in the final answers.

Found this prompt useful? Share it.

Share

More in RAG & Knowledge Retrieval

RAG & Knowledge Retrieval

AI Prompt to Query and Summarize Pinecone Vector Search Results via Pinecone's MCP Server

This Pinecone MCP prompt is for teams running a RAG pipeline on top of a Pinecone vector index who want an AI assistant to query that index…

ROLE:
You are a retrieval assistant that answers questions using only records returned from a Pinecone vector search via MCP.

CONTEXT:
Query: [USER_QUESTION]
Index/namespace: [PINECONE_NAMESPACE_OR_INDEX_NAME]
Top-k retrieved: [NUMBER_OF_MATCHES_RETURNED]
Retrieved matches (provided by the MCP server):
[LIST_OF_MATCHES_WITH_ID_SCORE_METADATA_AND_TEXT_SNIPPET]

INSTRUCTIONS:
1. Review each retrieved match and its similarity score.
2. Treat matches below [CONFIDENCE_THRESHOLD] similarity as low-confidence; do not state their contents as fact without flagging them as uncertain.
3. Answer the query using only information present in the retrieved matches. Do not add outside knowledge.
4. For every claim in your answer, cite the record ID or title it came from in parentheses.
5. If none of the retrieved matches answer the query, say so explicitly instead of guessing.

OUTPUT FORMAT:
Answer: [YOUR_GROUNDED_ANSWER_WITH_INLINE_CITATIONS]
Confidence note: [ANY_CAVEATS_ABOUT_LOW-SCORE_MATCHES_OR_MISSING_COVERAGE]

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Deduplicate Near-Duplicate Documents Before RAG Indexing

This prompt asks ChatGPT, Claude, or Gemini to design a strategy for catching near duplicate documents before they go into a RAG index, the…

You are a retrieval systems engineer designing a document deduplication stage for a RAG pipeline.

Context:
- Document sources: [LIST SOURCES, e.g. Confluence export, CMS pages, uploaded PDFs]
- Approximate corpus size: [NUMBER OF DOCUMENTS]
- Current chunking strategy: [e.g. 512-token chunks with 50-token overlap]
- Embedding model in use: [MODEL NAME]
- Known duplication pattern, if any: [e.g. same FAQ exported in two formats, revised policy versions]

Design a near-duplicate detection and resolution strategy with the following requirements:
1. Recommend a detection method (embedding cosine similarity, MinHash/shingling, or a hybrid) appropriate for the corpus size and chunking strategy above
2. Propose a specific similarity threshold or range, and explain the tradeoff of setting it higher versus lower
3. Define a tie-breaking rule for which document in a near-duplicate pair to keep
4. Specify a dry-run report format that lists candidate duplicate pairs with their similarity score before anything is removed
5. Describe how to flag pairs that are similar overall but differ in a critical detail, such as a number, date, or clause, so those are kept rather than merged
6. Explain how to log every merge or removal decision for later auditing

Output format:
- A short written plan covering points 1-3
- A sample dry-run report row format (as a table or structured record)
- A short section on the critical-detail safeguard from point 5
- A one-paragraph logging and audit approach

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Design a Metadata Filtering Strategy for RAG Retrieval

Metadata filtering narrows a RAG system's search space before similarity ranking even runs, using fields like document date, source, departm…

You are a retrieval systems engineer designing a metadata filtering strategy for a RAG pipeline.

Corpus description: [WHAT THE DOCUMENTS ARE, E.G. INTERNAL POLICY DOCS, PRODUCT MANUALS, SUPPORT TICKETS]
Available metadata fields: [LIST FIELDS, E.G. DOCUMENT DATE, DEPARTMENT, PRODUCT VERSION, ACCESS LEVEL]
Current retrieval problem: [DESCRIBE THE SPECIFIC FAILURE, E.G. RETURNS OUTDATED POLICY VERSIONS ALONGSIDE CURRENT ONES]
Example query that fails today: [EXAMPLE QUERY]
Query volume/pattern notes (optional): [E.G. MOST QUERIES DON'T MENTION A DATE OR VERSION]

Task:
1. Identify which available metadata fields would most directly address the retrieval problem described.
2. For each recommended field, specify whether it should be applied as a hard pre-filter or a soft ranking boost, and explain why.
3. Describe how the system should behave when a query gives no explicit signal for that field (e.g. default to most recent, ask a clarifying question, or search unfiltered).
4. Flag any field where filtering carries a real risk of excluding a relevant result due to inconsistent or missing metadata.
5. Walk through the example query that fails today and show how the proposed strategy would change the result.

Constraints:
- Only recommend filtering on fields explicitly listed as available.
- Do not recommend a hard filter without first addressing what happens to documents missing that field.

Output format: a table of recommended fields with filter type and rationale, followed by a short walkthrough of the example query.

Make this prompt yours