Files
agno/cookbook/agent_concepts/knowledge/chunking/csv_row_chunking.py
T
AlexandMustafa Esoofally 2dbd1d3890 feat: Row chunking for csv documents (#2704)
## Summary

This pull request introduces a new chunking strategy called RowChunking
within the `agno.document.chunking.strategy` module. The RowChunking
class provides functionality to treat each row in a CSV file as a
separate chunk, enabling more granular processing of CSV-based
documents.



## Type of change

- [ ] Bug fix (If applicable, issue number: #____)
- [x] New feature
- [ ] Breaking change
- [ ] Improvement
- [ ] Model update
- [ ] Other: _____________________

---

## Checklist

- [x] Code complies with style guidelines
- [x] Ran format/validation scripts (`./scripts/format.sh` and
`./scripts/validate.sh`)
- [x] Self-review completed
- [x] Documentation updated (comments, docstrings)
- [ ] Examples and guides: Relevant cookbook examples have been included
or updated (if applicable)
- [x] Tested in clean environment
- [ ] Tests added/updated (if applicable)

---

## Additional Notes

Given a CSV document with the following content:

```
Alice,30,New York
Bob,25,San Francisco


```
The vector DB will have 

**Chunk 1:**

Content: "Alice,30,New York"

Metadata: { "row_number": 2 }

**Chunk 2:**

Content: "Bob,25,San Francisco"

Metadata: { "row_number": 3 }

---------

Co-authored-by: Mustafa Esoofally <[email protected]>
2025-07-21 10:05:05 +02:00

31 lines
825 B
Python

from pathlib import Path
from agno.agent import Agent
from agno.document.chunking.row import RowChunking
from agno.knowledge.csv_url import CSVUrlKnowledgeBase
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge_base = CSVUrlKnowledgeBase(
urls=[
"https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
],
vector_db=PgVector(
table_name="imdb_movies_row_chunking",
db_url=db_url,
),
chunking_strategy=RowChunking(),
)
# Load the knowledge base
knowledge_base.load(recreate=False)
# Initialize the Agent with the knowledge_base
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
)
# Use the agent
agent.print_response("Tell me about the movie Guardians of the Galaxy", markdown=True)