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

# S3 文本知识库

> 了解如何在知识库中使用来自 S3 存储桶的文本文件。

**S3TextKnowledgeBase** 从 S3 存储桶读取**文本**文件，将它们转换为向量嵌入并加载到向量数据库中。

## 用法

<Note>
  我们在此示例中使用本地 PgVector 数据库。[确保它正在运行](https://docs.agno.com/vectordb/pgvector)
</Note>

```shell theme={null}
pip install textract
```

```python theme={null}
from agno.knowledge.s3.text import S3TextKnowledgeBase
from agno.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge_base = S3TextKnowledgeBase(
    bucket_name="agno-public",
    key="recipes/recipes.docx",
    vector_db=PgVector(table_name="recipes", db_url=db_url),
)
```

然后将 `knowledge_base` 与 `Agent` 一起使用：

```python theme={null}
from agno.agent import Agent
from knowledge_base import knowledge_base

agent = Agent(
    knowledge=knowledge_base,
    search_knowledge=True,
)
agent.knowledge.load(recreate=False)

agent.print_response("How to make Hummus?")
```

## 参数

| 参数            | 类型             | 默认值                 | 描述                                                      |
| ------------- | -------------- | ------------------- | ------------------------------------------------------- |
| `bucket_name` | `str`          | `None`              | 文件所在 S3 存储桶的名称。                                         |
| `key`         | `str`          | `None`              | 存储桶中文件的 key。                                            |
| `formats`     | `List[str]`    | `[".doc", ".docx"]` | 此知识库接受的格式。                                              |
| `reader`      | `S3TextReader` | `S3TextReader()`    | 一个 `S3TextReader`，用于将 `Text` 文件转换为用于向量数据库的 `Documents`。 |

`S3TextKnowledgeBase` 是 [AgentKnowledge](/reference/knowledge/base) 类的子类，可以访问相同的参数。

## 开发者资源

* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/s3_text_kb.py)
