Skip to main content
Chunkers are responsible for splitting large documents into smaller, manageable pieces called chunks. This is a crucial step before embedding and graph extraction, as most embedding models have a limit on the amount of text they can process at once.

Token-Based Sizing

Cognee uses token-based sizing for chunks, rather than character counts. This means that chunk_size refers to the maximum number of tokens allowed in a chunk, which is directly tied to the tokenizer used by your embedding model. This ensures that chunks are always within the model’s context window. The token-counting tokenizer is auto-selected to match your embedding model, so chunk sizes (and the --dry-run token estimate) reflect how the model actually tokenizes text. If a matching tokenizer cannot be loaded, Cognee logs a non-fatal advisory warning and falls back to the TikToken tokenizer — token counts become approximate but ingestion continues. To restore exact counts and silence the warning, set HUGGINGFACE_TOKENIZER to a tokenizer that matches your embedding model. See Embedding Providers for the per-provider tokenizer mapping and override details.

Available Chunkers

Cognee provides several built-in chunkers to handle different types of content:
  • TextChunker: The default chunker. It splits text by paragraphs while respecting the token limit. It tries to keep paragraphs together but will split them if they exceed the chunk_size.
  • CsvChunker: Designed specifically for CSV data. It splits by rows, ensuring that each chunk contains complete rows and does not break data in the middle of a record. Each row is chunked independently — row-level state (text, size, and chunk index) is reset at each row boundary, so one row’s fields are never accumulated onto the next row’s chunk.
  • LangchainChunker: Wraps LangChain’s RecursiveCharacterTextSplitter. It splits text recursively by characters (e.g., \n\n, \n, ) and supports chunk_overlap (in words; default: 10). Requires pip install cognee[langchain].
  • TextChunkerWithOverlap: A paragraph-based chunker that supports overlap via a chunk_overlap_ratio (a fraction of chunk_size, e.g. 0.2 = 20% overlap). Useful for maintaining context across chunk boundaries.
Overlap only works with LangchainChunker and TextChunkerWithOverlap. The default TextChunker splits strictly at paragraph boundaries and does not use overlap. Calling cognee.config.set_chunk_overlap() has no effect when using TextChunker.

Additional Information

Chunk overlap causes consecutive chunks to share a portion of text, which helps preserve context at chunk boundaries and can improve entity extraction quality — at the cost of more LLM calls and a slightly larger graph.When standard document readers instantiate your chunker, they call it as chunker_cls(document, get_text=..., max_chunk_size=...). The max_chunk_size value is the chunk_size you pass to remember() or cognify(). Extra chunking parameters such as overlap are not forwarded, so set them by subclassing the chunker and hard-wiring them inside __init__.
TextChunkerWithOverlap takes a chunk_overlap_ratio between 0.0 and 1.0 (fraction of chunk_size). Because this value cannot be passed through cognee.config.set_chunk_overlap() at runtime, configure it by subclassing:
You can create a custom chunker by inheriting from the Chunker base class and implementing the read method. Your chunker must yield DocumentChunk objects.
The /cognify REST API endpoint does not accept a chunk_size parameter directly. When you use Cognee through Docker or the HTTP API, set the chunk size via environment variables instead:
With Docker Compose, add these to your .env before starting:
Then start the server:
With docker run, pass them inline:
The chunk_size environment variable is read once at startup. Restart the container after changing it.
The chunk_size passed to remember() directly affects how the knowledge graph is built:If chunk_size is not set, Cognee auto-calculates it as the minimum of your embedding model’s context window and half of your LLM’s context window.
For structured data, the goal is to make chunk boundaries follow the shape of the source. TextChunker (and the underlying chunk_by_paragraph) preserves sentence and paragraph boundaries where possible, batching complete sentence-sized units up to chunk_size before starting a new chunk. It does not understand a “rule”, XML element, or JSON record by itself, so treat chunk_size as a guardrail rather than a semantic guarantee.If you have procedural rules, configuration, or other structured content where each unit must stay intact, choose the smallest source unit you would be comfortable retrieving on its own:
  1. Raise chunk_size so the whole document fits in one chunk. Because chunk_size is a token budget, any content that fits under it is kept together. Set it large enough to hold your entire ruleset and no splitting occurs:
  2. Add each rule as its own data item so every rule becomes an independent document and is processed on its own:
  3. Write a custom chunker (see the Custom Chunkers section above) that splits on your own boundaries (e.g. one chunk per rule, per XML element, or per JSON record) when the natural unit isn’t a paragraph.
Cognee is strongest when the data has concepts, entities, and relationships to reason over. For workflows that must reproduce deterministic API calls or fixed rules verbatim, keep the canonical procedure in a regular file or source system, then use Cognee for the parts that benefit from semantic search and graph reasoning.