> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CSV Loader

> Load CSV files with flexible row handling and content synthesis

## Overview

CSV loader processes CSV files with options to create documents per row, per chunk, or as a single document. Supports column filtering and flexible content formatting.

**Loader Class:** `CSVLoader`

**Config Class:** `CSVLoaderConfig`

## Install

<Note>
  Install the CSV loader optional dependency group:

  ```bash theme={null}
  uv pip install "upsonic[csv-loader]"
  ```
</Note>

## Examples

```python theme={null}
from upsonic import Agent, Task, KnowledgeBase
from upsonic.loaders.csv import CSVLoader
from upsonic.loaders.config import CSVLoaderConfig
from upsonic.embeddings import OpenAIEmbedding, OpenAIEmbeddingConfig
from upsonic.text_splitter.recursive import RecursiveChunker, RecursiveChunkingConfig
from upsonic.vectordb import ChromaProvider, ChromaConfig, ConnectionConfig, Mode

# Configure loader for per-row documents
loader_config = CSVLoaderConfig(
    split_mode="per_row",
    content_synthesis_mode="concatenated",
    include_columns=["name", "description"]
)
loader = CSVLoader(loader_config)

# Setup KnowledgeBase
embedding = OpenAIEmbedding(OpenAIEmbeddingConfig())
chunker = RecursiveChunker(RecursiveChunkingConfig())
vectordb = ChromaProvider(ChromaConfig(
    collection_name="csv_data",
    vector_size=1536,
    connection=ConnectionConfig(mode=Mode.IN_MEMORY)
))

kb = KnowledgeBase(
    sources=["data.csv"],
    embedding_provider=embedding,
    vectordb=vectordb,
    loaders=[loader],
    splitters=[chunker]
)

# Query with Agent
agent = Agent("anthropic/claude-sonnet-4-5")
task = Task("Find products matching 'laptop'", context=[kb])
result = agent.do(task)
print(result)
```

## Parameters

| Parameter                | Type                                            | Description                                       | Default            | Source   |
| ------------------------ | ----------------------------------------------- | ------------------------------------------------- | ------------------ | -------- |
| `encoding`               | `str \| None`                                   | File encoding (auto-detected if None)             | None               | Base     |
| `error_handling`         | `"ignore" \| "warn" \| "raise"`                 | How to handle loading errors                      | "warn"             | Base     |
| `include_metadata`       | `bool`                                          | Whether to include file metadata                  | True               | Base     |
| `custom_metadata`        | `dict`                                          | Additional metadata to include                    | {}                 | Base     |
| `max_file_size`          | `int \| None`                                   | Maximum file size in bytes                        | None               | Base     |
| `skip_empty_content`     | `bool`                                          | Skip documents with empty content                 | True               | Base     |
| `content_synthesis_mode` | `"concatenated" \| "json"`                      | How to create document content from rows          | "concatenated"     | Specific |
| `split_mode`             | `"single_document" \| "per_row" \| "per_chunk"` | How to split CSV into documents                   | "single\_document" | Specific |
| `rows_per_chunk`         | `int`                                           | Number of rows per document (for per\_chunk mode) | 100                | Specific |
| `include_columns`        | `list[str] \| None`                             | Only include these columns                        | None               | Specific |
| `exclude_columns`        | `list[str] \| None`                             | Exclude these columns                             | None               | Specific |
| `delimiter`              | `str`                                           | CSV delimiter                                     | ","                | Specific |
| `quotechar`              | `str`                                           | CSV quote character                               | '"'                | Specific |
| `has_header`             | `bool`                                          | Whether CSV has a header row                      | True               | Specific |
