CSV Reader
The CSV Reader processes local CSV files and converts them into documents that can be used with Kern's knowledge system.
Code
1from pathlib import Path23from kern.knowledge.reader.csv_reader import CSVReader45reader = CSVReader()67csv_path = Path("tmp/test.csv")89try:10 print("Starting read...")11 documents = reader.read(csv_path)1213 if documents:14 for doc in documents:15 print(doc.name)16 # print(doc.content)17 print(f"Content length: {len(doc.content)}")18 print("-" * 80)19 else:20 print("No documents were returned")2122except Exception as e:23 print(f"Error type: {type(e)}")24 print(f"Error occurred: {str(e)}")Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U pandas kern-aiRun Agent
1python examples/basics/knowledge/concepts/readers/overview/csv_reader.py1python examples/basics/knowledge/concepts/readers/overview/csv_reader.pyParams
| Parameter | Type | Default | Description |
|---|---|---|---|
file | Union[Path, IO[Any]] | Required | Path to CSV file or file-like object |
delimiter | str | "," | Character used to separate fields in the CSV |
quotechar | str | '"' | Character used to quote fields in the CSV |