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

# Qdrant Agent 知识库

## 设置

请遵循 [Qdrant 设置指南](https://qdrant.tech/documentation/guides/installation/) 中的说明在本地安装 Qdrant。以下是获取 API 密钥的指南：[Qdrant API 密钥](https://qdrant.tech/documentation/cloud/authentication/)。

## 示例

```python agent_with_knowledge.py theme={null}
import os
import typer
from typing import Optional
from rich.prompt import Prompt

from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.qdrant import Qdrant

api_key = os.getenv("QDRANT_API_KEY")
qdrant_url = os.getenv("QDRANT_URL")
collection_name = "thai-recipe-index"

vector_db = Qdrant(
    collection=collection_name,
    url=qdrant_url,
    api_key=api_key,
)

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

def qdrant_agent(user: str = "user"):
    run_id: Optional[str] = None

    agent = Agent(
        run_id=run_id,
        user_id=user,
        knowledge=knowledge_base,
        tool_calls=True,
        use_tools=True,
        show_tool_calls=True,
        debug_mode=True,
    )

    if run_id is None:
        run_id = agent.run_id
        print(f"Started Run: {run_id}\n")
    else:
        print(f"Continuing Run: {run_id}\n")

    while True:
        message = Prompt.ask(f"[bold] :sunglasses: {user} [/bold]")
        if message in ("exit", "bye"):
            break
        agent.print_response(message)

if __name__ == "__main__":
    # 首次运行时注释掉此行
    knowledge_base.load(recreate=True, upsert=True)

    typer.run(qdrant_agent)
```

<Card title="异步支持 ⚡">
  <div className="mt-2">
    <p>
      Qdrant 也支持异步操作，能够实现并发并带来更好的性能。
    </p>

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

    from agno.agent import Agent
    from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
    from agno.vectordb.qdrant import Qdrant

    COLLECTION_NAME = "thai-recipes"

    # 使用本地实例初始化 Qdrant
    vector_db = Qdrant(
        collection=COLLECTION_NAME, 
        url="http://localhost:6333"
    )

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

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

    if __name__ == "__main__":
        # 异步加载知识库
        asyncio.run(knowledge_base.aload(recreate=False))  # 首次运行时注释掉此行

        # 异步创建和使用代理
        asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
    ```

    <Tip className="mt-4">
      使用 <code>aload()</code> 和 <code>aprint\_response()</code> 配合 asyncio 可实现非阻塞操作，使您的应用程序在负载下更具响应性。
    </Tip>
  </div>
</Card>

## Qdrant 参数

<Snippet file="vectordb_qdrant_params.mdx" />

## 开发者资源

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