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

# LanceDB Agent 知识

## 设置

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

## 示例

```python agent_with_knowledge.py theme={null}
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.lancedb import LanceDb
from agno.vectordb.search import SearchType

# LanceDB Vector DB
vector_db = LanceDb(
    table_name="recipes",
    uri="/tmp/lancedb",
    search_type=SearchType.keyword,
)

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

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

    agent = Agent(
        run_id=run_id,
        user_id=user,
        knowledge=knowledge_base,
        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)

    typer.run(lancedb_agent)
```

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

    ```python async_lance_db.py theme={null}
    # 安装 lancedb - `pip install lancedb`
    import asyncio

    from agno.agent import Agent
    from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
    from agno.vectordb.lancedb import LanceDb

    # 初始化 LanceDB
    vector_db = LanceDb(
        table_name="recipes",
        uri="tmp/lancedb",  # 您可以将此路径更改为存储其他数据的位置
    )

    # 创建知识库
    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, debug_mode=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">
      在吞吐量高的应用程序中使用 <code>aload()</code> 和 <code>aprint\_response()</code> 方法配合 <code>asyncio.run()</code> 进行非阻塞操作。
    </Tip>
  </div>
</Card>

## LanceDb 参数

<Snippet file="vectordb_lancedb_params.mdx" />

## 开发者资源

* 查看[食谱 (同步)](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/vector_dbs/lance_db/lance_db.py)
* 查看[食谱 (异步)](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/vector_dbs/lance_db/async_lance_db.py)
