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

# Wikipedia 知识库

> 了解如何在知识库中使用 Wikipedia 主题。

**WikipediaKnowledgeBase** 会读取 Wikipedia 主题，将它们转换为向量嵌入，然后加载到向量数据库中。

## 用法

<Note>
  我们在示例中使用了本地的 PgVector 数据库。[请确保它正在运行](http://localhost:3333/vectordb/pgvector)
</Note>

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

```python knowledge_base.py theme={null}
from agno.knowledge.wikipedia import WikipediaKnowledgeBase
from agno.vectordb.pgvector import PgVector

knowledge_base = WikipediaKnowledgeBase(
    topics=["Manchester United", "Real Madrid"],
    # 表名：ai.wikipedia_documents
    vector_db=PgVector(
        table_name="wikipedia_documents",
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
    ),
)
```

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

```python agent.py 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("Ask me about something from the knowledge base")
```

## 参数

| 参数       | 类型          | 默认值 | 描述     |
| -------- | ----------- | --- | ------ |
| `topics` | `List[str]` | \[] | 要读取的主题 |

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

## 开发者资源

* 查看 [同步加载食谱](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/wikipedia_kb.py)
* 查看 [异步加载食谱](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/wikipedia_kb_async.py)
