> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Document Chunking

> Group paragraphs into chunks and split oversized paragraphs at sentence boundaries.

`DocumentChunking` packs double-newline-separated paragraphs toward `chunk_size`. It splits an oversized paragraph at sentence boundaries.

**1. Create a Python file**

```python document_chunking.py theme={null}
from agno.agent import Agent
from agno.knowledge.chunking.document import DocumentChunking
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.pdf_reader import PDFReader
from agno.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge = Knowledge(
    vector_db=PgVector(table_name="recipes_document_chunking", db_url=db_url),
)

knowledge.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    reader=PDFReader(
        name="Document Chunking Reader",
        split_on_pages=False,
        chunking_strategy=DocumentChunking(),
    ),
)

agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
)

agent.print_response("How do I make Thai curry?", markdown=True)
```

<Snippet file="create-venv-step.mdx" />

**2. Install dependencies**

```bash theme={null}
uv pip install -U agno sqlalchemy psycopg pgvector pypdf openai
```

**3. Export your OpenAI API key**

<Snippet file="set-openai-key.mdx" />

<Snippet file="run-pgvector-step.mdx" />

**4. Run the script**

```bash theme={null}
python document_chunking.py
```

The example sets `split_on_pages=False` so `PDFReader` combines the pages before applying `DocumentChunking`. Keep the default value of `True` to chunk each page independently.

## Chunk Size

`chunk_size` is a target rather than a strict ceiling. Paragraph separators, a sentence longer than the target, and overlap can produce a longer chunk. Overlap is prepended without an added separator.

## Document Chunking Params

<Snippet file="chunking-document.mdx" />

## Developer Resources

* [Chunking overview](https://agno-v2.mintlify.site/knowledge/concepts/chunking/overview.md)
* [Chunking strategies examples](https://agno-v2.mintlify.site/examples/knowledge/building-blocks/chunking-strategies.md)
* [PDF reader](https://agno-v2.mintlify.site/knowledge/concepts/readers/pdf-reader.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.