Documentation Index
Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
The Field Labeled CSV Reader converts CSV rows into field-labeled text documents, making them more readable for natural language processing and agent-based retrieval systems.
Code
cookbook/knowledge/readers/csv_field_labeled_reader.py
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.field_labeled_csv_reader import FieldLabeledCSVReader
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
reader = FieldLabeledCSVReader(
chunk_title="🎬 Movie Information",
field_names=[
"Movie Rank",
"Movie Title",
"Genre",
"Description",
"Director",
"Actors",
"Year",
"Runtime (Minutes)",
"Rating",
"Votes",
"Revenue (Millions)",
"Metascore",
],
format_headers=True,
skip_empty_fields=True,
)
knowledge_base = Knowledge(
vector_db=PgVector(
table_name="imdb_movies_field_labeled_readr",
db_url=db_url,
),
)
knowledge_base.add_content(
url="https://agno-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
reader=reader,
)
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
instructions=[
"You are a movie expert assistant.",
"Use the search_knowledge_base tool to find detailed information about movies.",
"The movie data is formatted in a field-labeled, human-readable way with clear field labels.",
"Each movie entry starts with '🎬 Movie Information' followed by labeled fields.",
"Provide comprehensive answers based on the movie information available.",
],
)
agent.print_response(
"which movies are directed by Christopher Nolan", markdown=True, stream=True
)
Usage
Create a virtual environment
Open the Terminal and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U agno aiofiles sqlalchemy psycopg[binary] pgvector openai
Set environment variables
export OPENAI_API_KEY=xxx
Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
agno/pgvector:16
Run Agent
python cookbook/knowledge/readers/csv_field_labeled_reader.py
Params
| Parameter | Type | Default | Description |
file | Union[Path, IO[Any]] | Required | Path to CSV file or file-like object |
chunk_title | Optional[Union[str, List[str]]] | None | Title to add at the top of each entry. Can be a single string or a list that rotates through entries |
field_names | Optional[List[str]] | [] | Custom labels for CSV fields. If not provided, column headers are used |
format_headers | bool | True | Whether to format column headers by replacing underscores with spaces and applying title case |
skip_empty_fields | bool | True | Whether to skip fields with empty values in the output |
delimiter | str | "," | Character used to separate fields in the CSV |
quotechar | str | '"' | Character used to quote fields in the CSV |
encoding | Optional[str] | "utf-8" | Character encoding for reading the file |