Skip to main content
AgenticChunking asks a model to choose each split position within max_chunk_size characters. It uses the size limit when the model call fails or the response cannot be parsed as an integer. Positions above the limit are clamped.
1

Create a Python file

agentic_chunking.py
2

Set up your virtual environment

3

Install dependencies

4

Export your OpenAI API key

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.
5

Run PgVector

6

Run the script

Custom Prompts

custom_prompt is inserted into Agno’s chunking instructions. For the chunker to make progress, the model must return a positive integer.
Set max_chunk_size explicitly when using a custom prompt so the model receives the intended limit.

Agentic Chunking Params

Developer Resources