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

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

The question should be specific, self-contained, and written in natural language.
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.
