Chunking Strategies for RAG
Chunking strategies for RAG in FlowGenX: structure-aware chunking that keeps sections and tables whole, metadata enrichment, and OCR for scanned PDFs.
Before a document can be searched, the Knowledge Base splits it into chunks: short passages that are embedded and retrieved one at a time. How a document is split decides what a search can find, so the strategy you pick changes answer quality directly.
What is chunking?
Embedding models and language models can only read a limited amount of text at once, and a long document embedded as a single vector blurs every topic in it together. Chunking breaks the document into pieces small enough to embed precisely and to fit into a model's prompt alongside other results.
Each chunk becomes one searchable unit. When someone asks a question, retrieval returns the best-matching chunks, not whole documents, and the answer is written from those chunks. A chunk that cuts a thought in half, or mixes three topics, retrieves poorly.
Intelligent chunking
AI models have a limit on how much text they can read at once. We don't just chop your documents into arbitrary pieces. Our Intelligent Chunking algorithms analyze the structure of your document (paragraphs, headers, and sections) to ensure that each chunk of information is complete and meaningful.
This means when you ask a question, the AI gets a complete thought, not a fragmented sentence.
In practice, an uploaded file goes through these steps:
- Layout-aware parsing. PDF, DOCX, PPTX, XLSX, CSV, HTML, Markdown and text files are converted to structured text that keeps headings, so the chunker knows where sections begin and end.
- Splitting. The chosen strategy cuts the text into chunks within a token budget, 512 tokens by default.
- Filtering. Fragments shorter than 20 tokens, such as stray chapter labels, are dropped before embedding.
- Embedding with context. Each chunk is embedded together with a short header naming its document and section path (for example
Document: handbook.pdf; Section: Benefits > Leave). The stored chunk text stays unchanged; the header only helps a continuation chunk keep its topic.
Spreadsheets (.xlsx and .csv) get table-aware chunking: a table is kept whole, or split by rows with the header row repeated in each piece, so a later part of a table still says what its columns mean.
Chunking strategies in FlowGenX
You choose a strategy in the Chunking Strategy field of the upload dialog, and in the Chunking Configuration section of the Knowledge Base workflow node when it uploads a file. The options are:
| Strategy | How it splits |
|---|---|
| Hybrid | Splits on document headings, then merges neighbouring pieces from the same section up to the token budget. The default in the upload dialog. |
| Hierarchical | Splits on document headings, preserving section context. Oversized sections are split further. The default in the workflow node. |
| Recursive | Splits recursively along natural boundaries, sized by token count. |
| Token | Fixed token windows, ignoring structure. |
| Markdown | Header-aware chunking for Markdown. |
| Semantic | Groups consecutive sentences whose meaning is similar, using embedding similarity. |
| Sentence | Groups whole sentences into chunks within the token budget. |
| Code | AST-aware code chunking (tree-sitter), splitting along the code's syntax tree. |
| Late | Late chunking: embeds the text first, then splits, to improve retrieval recall. |
Code and Late rely on optional components of the processing service. If one is not available, the upload fails with a message saying which component is missing, and you can retry with another strategy.
Text uploads from the workflow node (raw text rather than a file) have no strategy picker. The service picks one from the content: Markdown for text with headings, Code for source code, and Semantic otherwise.
How to choose a chunk size
Chunk size is a trade-off, whatever tool you use:
- Smaller chunks match narrow, factual questions precisely ("what is the notice period?"), but each one carries little context, so an answer may need several of them.
- Larger chunks keep explanations and their caveats together, but one embedding has to represent more text, so matches get less precise and fewer results fit in the model's prompt.
- Overlap repeats a little text across a boundary so a sentence split between two chunks still appears whole in one of them. It matters most for strategies that ignore structure.
In FlowGenX the token budget is fixed at 512 tokens per chunk by default, counted with the cl100k_base tokenizer. Your main lever is the strategy, which decides where the cuts fall within that budget:
- Well-structured documents (policies, manuals, specifications with real headings): Hybrid. Sections stay whole and short neighbouring sections are packed together, so you avoid tiny chunks.
- Documents where each section must stay separate: Hierarchical. Every chunk belongs to exactly one section.
- Unstructured prose (transcripts, emails, scanned text without headings): Semantic or Sentence, which cut where the topic or sentence ends rather than at a fixed count.
- Source code: Code.
- Exports with no structure at all: Token or Recursive.
Hybrid and Hierarchical do not overlap chunks, because each chunk ends on a section boundary.
The Knowledge Base node also shows Chunk Size and Chunk Overlap fields in characters (defaults 1,000 and 200). These apply only to fixed-size character chunking. The strategies in the dropdown size chunks by the token budget instead.
To check a choice, upload a representative document, run a few real questions in Semantic Search, and read the passages that come back. If answers keep missing context that sits just before or after the matched passage, try a structure-aware strategy. If one result drags in unrelated material, try a finer one.
Optical Character Recognition (OCR)
PDF parsing checks each page for a usable text layer. When a document is mostly scanned, the low-text pages are run through OCR. In an otherwise electronic PDF, a page with images but no text layer is also run through OCR. Text read this way is chunked like any other text.
The upload dialog does not accept standalone image files, so OCR in the Knowledge Base applies to PDFs.
Metadata enrichment
As documents are processed, each chunk is stored with metadata that later powers filtering and citations:
- Source: the file name and the chunk's position in the document.
- Location: the page numbers the chunk came from and the heading path above it.
- Tags: the schema, regulation and data types you set at upload, which become the metadata filters in the search interface. See Document Management for tagging.
Page and heading data is what lets knowledge search in FlowGenX Chat cite the page a passage came from.
Document Management
Document management in the FlowGenX AI Knowledge Base: upload, categorize, and manage your documents through a user-friendly interface.
Security & Storage
How the knowledge base vector store keeps data secure: tenant isolation, encryption in transit and at rest, embedding model choice, data ownership.