> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-codex-docs-audit-20260719-0149.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.

<Steps>
  <Step title="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)
    ```
  </Step>

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno sqlalchemy psycopg pgvector pypdf openai
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <Snippet file="set-openai-key.mdx" />
  </Step>

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

  <Step title="Run the script">
    ```bash theme={null}
    python document_chunking.py
    ```
  </Step>
</Steps>

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](/knowledge/concepts/chunking/overview)
* [Chunking strategies examples](/examples/knowledge/building-blocks/chunking-strategies)
* [PDF reader](/knowledge/concepts/readers/pdf-reader)
