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

# 组合知识库

> 了解如何将多个知识库组合成一个。

**CombinedKnowledgeBase** 将多个知识库合并为一个，适用于您的应用程序需要从多个来源获取信息的情况。

## 用法

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

```shell theme={null}
pip install pypdf bs4
```

```python knowledge_base.py theme={null}
from agno.knowledge.combined import CombinedKnowledgeBase
from agno.vectordb.pgvector import PgVector
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.knowledge.website import WebsiteKnowledgeBase
from agno.knowledge.pdf import PDFKnowledgeBase


url_pdf_knowledge_base = PDFUrlKnowledgeBase(
    urls=["pdf_url"],
    # 表名: ai.pdf_documents
    vector_db=PgVector(
        table_name="pdf_documents",
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
    ),
)

website_knowledge_base = WebsiteKnowledgeBase(
    urls=["https://docs.agno.com/introduction"],
    # 从种子 URL 跟踪的链接数量
    max_links=10,
    # 表名: ai.website_documents
    vector_db=PgVector(
        table_name="website_documents",
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
    ),
)

local_pdf_knowledge_base = PDFKnowledgeBase(
    path="data/pdfs",
    # 表名: ai.pdf_documents
    vector_db=PgVector(
        table_name="pdf_documents",
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
    ),
    reader=PDFReader(chunk=True),
)

knowledge_base = CombinedKnowledgeBase(
    sources=[
        url_pdf_knowledge_base,
        website_knowledge_base,
        local_pdf_knowledge_base,
    ],
    vector_db=PgVector(
        # 表名: ai.combined_documents
        table_name="combined_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("就知识库中的内容问我一些问题")
```

## 参数

| 参数        | 类型                     | 默认值  | 描述     |
| --------- | ---------------------- | ---- | ------ |
| `sources` | `List[AgentKnowledge]` | `[]` | 知识库列表。 |

`CombinedKnowledgeBase` 是 [AgentKnowledge](/reference/knowledge/base) 类的子类，拥有相同的参数。

## 开发者资源

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