> ## 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.

# Semantic Chunking

> Group sentences into chunks using embedding similarity and configurable boundary controls.

`SemanticChunking` wraps Chonkie's semantic chunker and groups sentences using embedding similarity. See [Chonkie Semantic Chunker](https://docs.chonkie.ai/oss/chunkers/semantic-chunker).

**1. Create a Python file**

Save one of these variants as `semantic_chunking.py`:

```python Agno Embedder theme={null}
from agno.agent import Agent
from agno.knowledge.chunking.semantic import SemanticChunking
from agno.knowledge.embedder.openai import OpenAIEmbedder
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"

embedder = OpenAIEmbedder(id="text-embedding-3-small")

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="recipes_semantic_chunking", db_url=db_url, embedder=embedder
    ),
)
knowledge.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    reader=PDFReader(
        name="Semantic Chunking Reader",
        split_on_pages=False,
        chunking_strategy=SemanticChunking(
            embedder=embedder,
            chunk_size=500,
        ),
    ),
)

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

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

```python Chonkie Embedder theme={null}
from agno.agent import Agent
from agno.knowledge.chunking.semantic import SemanticChunking
from agno.knowledge.embedder.openai import OpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.pdf_reader import PDFReader
from agno.vectordb.pgvector import PgVector
from chonkie.embeddings import Model2VecEmbeddings

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

agno_embedder = OpenAIEmbedder(id="text-embedding-3-small")
chonkie_embedder = Model2VecEmbeddings(model="minishlab/potion-base-32M")

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="recipes_semantic_chunking", db_url=db_url, embedder=agno_embedder
    ),
)
knowledge.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    reader=PDFReader(
        name="Semantic Chunking Reader",
        split_on_pages=False,
        chunking_strategy=SemanticChunking(
            embedder=chonkie_embedder,
            chunk_size=500,
        ),
    ),
)

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

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

```python String Model ID theme={null}
from agno.agent import Agent
from agno.knowledge.chunking.semantic import SemanticChunking
from agno.knowledge.embedder.openai import OpenAIEmbedder
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"

agno_embedder = OpenAIEmbedder(id="text-embedding-3-small")

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="recipes_semantic_chunking", db_url=db_url, embedder=agno_embedder
    ),
)
knowledge.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    reader=PDFReader(
        name="Semantic Chunking Reader",
        split_on_pages=False,
        chunking_strategy=SemanticChunking(
            embedder="minishlab/potion-base-32M",
            chunk_size=500,
        ),
    ),
)

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 "chonkie[semantic]" openai pgvector psycopg pypdf sqlalchemy
```

**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 semantic_chunking.py
```

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

## Choose an Embedder

The `embedder` parameter accepts an Agno `Embedder`, a Chonkie `BaseEmbeddings` instance, or a string model identifier resolved by Chonkie. See [Chonkie Embeddings](https://docs.chonkie.ai/oss/embeddings/overview).

| Embedder Value | Chunk Size Measurement |
| - | - |
| Agno `Embedder` | Whitespace-separated words |
| Chonkie `BaseEmbeddings` | Tokens from the embedder's tokenizer |
| String model identifier | Tokens from the tokenizer selected by Chonkie |

## Semantic Chunking Params

<Snippet file="chunking-semantic.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.