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

# 知识库 Weaviate

请按照 [Weaviate 设置指南](https://weaviate.io/developers/weaviate/quickstart) 中的步骤来设置 Weaviate。

## 设置

安装 weaviate 包

```shell theme={null}
pip install weaviate-client
```

运行 weaviate

```shell theme={null}
docker run -d \
-p 8080:8080 \
-p 50051:50051 \
--name weaviate \
cr.weaviate.io/semitechnologies/weaviate:1.28.4
```

或者

```shell theme={null}
./cookbook/scripts/run_weaviate.sh
```

## 示例

```python agent_with_knowledge.py theme={null}
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.search import SearchType
from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate

vector_db = Weaviate(
    collection="recipes",
    search_type=SearchType.hybrid,
    vector_index=VectorIndex.HNSW,
    distance=Distance.COSINE,
    local=True,  # 如果使用 Weaviate Cloud，请设置为 False；如果使用本地实例，请设置为 True
)
# 创建知识库
knowledge_base = PDFUrlKnowledgeBase(
    urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
    vector_db=vector_db,
)
knowledge_base.load(recreate=False)  # 首次运行时注释此行

# 创建并使用 Agent
agent = Agent(
    knowledge=knowledge_base,
    search_knowledge=True,
    show_tool_calls=True,
)
agent.print_response("How to make Thai curry?", markdown=True)
```

<Card title="异步支持 ⚡">
  <div className="mt-2">
    <p>
      Weaviate 也支持异步操作，可实现并发并提高性能。
    </p>

    ```python async_weaviate_db.py theme={null}
    import asyncio

    from agno.agent import Agent
    from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
    from agno.vectordb.search import SearchType
    from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate

    vector_db = Weaviate(
        collection="recipes_async",
        search_type=SearchType.hybrid,
        vector_index=VectorIndex.HNSW,
        distance=Distance.COSINE,
        local=True,  # 如果使用 Weaviate Cloud，请设置为 False；如果使用本地实例，请设置为 True
    )

    # 创建知识库
    knowledge_base = PDFUrlKnowledgeBase(
        urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
        vector_db=vector_db,
    )

    agent = Agent(
        knowledge=knowledge_base,
        search_knowledge=True,
        show_tool_calls=True,
    )

    if __name__ == "__main__":
        # 首次运行时注释此行
        asyncio.run(knowledge_base.aload(recreate=False))

        # 创建并使用 Agent
        asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
    ```

    <Tip className="mt-4">
      Weaviate 的异步功能利用 <code>WeaviateAsyncClient</code> 来提供非阻塞向量操作。这对于需要高并发和吞吐量的应用程序特别有价值。
    </Tip>
  </div>
</Card>

## Weaviate 参数

<Snippet file="vectordb_weaviate_params.mdx" />

## 开发者资源

* 查看 [Cookbook (同步)](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/vector_dbs/weaviate_db/weaviate_db.py)
* 查看 [Cookbook (异步)](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/vector_dbs/weaviate_db/async_weaviate_db.py)
