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

# Text Loader

> Load plain text files with flexible processing options

## Overview

Text loader processes various text-based files (.txt, .rst, .log, code files, etc.) with options for whitespace handling and content filtering. Simple and efficient for plain text documents.

**Loader Class:** `TextLoader`

**Config Class:** `TextLoaderConfig`

## Install

<Note>
  Install the Text loader optional dependency group:

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

## Examples

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

# Configure loader
loader_config = TextLoaderConfig(
    strip_whitespace=True,
    min_chunk_length=10
)
loader = TextLoader(loader_config)

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

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

# Query with Agent
agent = Agent("anthropic/claude-sonnet-4-5")
task = Task("Summarize the document", 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 |
| `strip_whitespace` | `bool` | Remove leading/trailing whitespace | True | Specific |
| `min_chunk_length` | `int` | Minimum character length for chunks | 1 | Specific |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.