> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/getting-started/core-ai-concepts/chunking.md).

# Chunking

### **Chunking: Optimizing Data Retrieval in Stack AI Workflows**

Chunking is a key technique in AI-powered document processing. In **StackAI**, using the right chunking strategy can greatly enhance how effectively machine learning models understand and extract data from documents.

***

#### **What is Chunking in StackAI?**

**Chunking** = Breaking large documents into smaller, manageable parts.

* Used in StackAI’s **"Files"** and **"Documents"** nodes.
* Ensures input fits within AI model token limits.
* Can be configured via the gear icon in relevant nodes.

***

#### **Chunking Methods**

**1. Naïve Chunking (Fixed-Length)**

Splits text by character, word, or token count.

* Pros:
  * Fast and simple to implement
  * Predictable processing time
* Cons:
  * May break sentences or ideas
  * Can reduce AI comprehension

***

**2. Sentence-Based Chunking**

Splits text along natural sentence boundaries.

* Pros:
  * Preserves meaning and structure
  * Enhances AI understanding
* Cons:
  * More computationally intensive
  * Chunk sizes can vary

***

#### **Optimizing Chunk Configuration**

**Chunk Size**

* Choose based on your model's capabilities.
* Tradeoff:
  * **Larger chunks** = better context but risk hitting token limits.
  * **Smaller chunks** = faster, but may lose coherence.
* Recommended: **200–1,000 tokens**

**Chunk Overlap**

* Adds continuity between chunks.
* Suggested: **15–30% overlap**

***

#### **Best Practices for Stack AI Users**

* Use **sentence-based chunking** for documents with rich content.
* Tune **chunk size** to match your AI model's limits.
* Experiment with **overlap percentages** to preserve context.
* **Iteratively test** to ensure optimal results.

***

#### **Technical Tips**

* Configure chunking inside "Files" and "Documents" nodes.
* Continuously monitor model performance as you adjust settings.
* Align your chunking strategy with your specific ML model needs.

***

#### **Why It Matters**

Mastering chunking helps:

* Improve document comprehension for AI
* Boost data extraction accuracy
* Deliver better performance across document-based workflows in StackAI


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.stackai.com/getting-started/core-ai-concepts/chunking.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
