> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Chunking Strategies

> Optimize document chunking for better retrieval

Optimise how documents are split into chunks for better retrieval quality.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Researcher",
    instructions="Answer using retrieved document chunks.",
    knowledge=KnowledgeConfig(sources=["docs/"], chunk_size=500, chunk_overlap=50),
)

agent.start("What does our deployment guide say about Docker?")
```

The user uploads documents; they are chunked and embedded, and the agent retrieves the best slices for each question.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    U[Input] --> A[Agent]
    A --> O[Output]

    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

    class A agent
    class U,O tool
```

Optimize how documents are split into chunks for better retrieval quality.

## Chunking Options

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Knowledge

knowledge = Knowledge(
    sources=["docs/"],
    chunk_size=500,        # Target chunk size
    chunk_overlap=50,      # Overlap between chunks
    chunking_strategy="semantic"  # Chunking method
)
```

## Strategies

### Fixed Size (Default)

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
knowledge = Knowledge(
    sources=["docs/"],
    chunking_strategy="fixed",
    chunk_size=500,
    chunk_overlap=50
)
```

### Semantic

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
knowledge = Knowledge(
    sources=["docs/"],
    chunking_strategy="semantic"
)
```

### Sentence-Based

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
knowledge = Knowledge(
    sources=["docs/"],
    chunking_strategy="sentence",
    sentences_per_chunk=5
)
```

## Best Practices

<AccordionGroup>
  <Accordion title="Match chunk size to content">
    Technical docs: 500–800 tokens with 50–100 overlap (semantic). FAQs: 200–400 with 20–50 overlap (fixed).
  </Accordion>

  <Accordion title="Long articles">
    Use 800–1200 token chunks with 100–200 overlap and semantic splitting for narrative content.
  </Accordion>

  <Accordion title="Code and mixed media">
    Keep code chunks around 300–500 tokens with \~50 overlap; prefer fixed splitting for source files.
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Knowledge Base" icon="book" href="/docs/guides/rag/knowledge-base">
    Build a knowledge base
  </Card>

  <Card title="Knowledge Module" icon="code" href="/docs/sdk/praisonaiagents/knowledge/knowledge">
    Full API reference
  </Card>
</CardGroup>
