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

# Pinecone Agent 知识库

## 设置

请遵循 [Pinecone 设置指南](https://docs.pinecone.io/guides/get-started/quickstart) 中的说明，快速开始使用 Pinecone。

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

<Info>
  我们目前暂不支持 Pinecone v6.x.x。我们正在积极努力实现兼容性。在此期间，我们建议使用 **Pinecone v5.4.2** 以获得最佳体验。
</Info>

## 示例

```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.pineconedb import PineconeDb

api_key = os.getenv("PINECONE_API_KEY")
index_name = "thai-recipe-hybrid-search"

vector_db = PineconeDb(
    name=index_name,
    dimension=1536,
    metric="cosine",
    spec={"serverless": {"cloud": "aws", "region": "us-east-1"}},
    api_key=api_key,
    use_hybrid_search=True,
    hybrid_alpha=0.5,
)

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

def pinecone_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, upsert=True)

    typer.run(pinecone_agent)
```

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

    ```python async_pinecone.py theme={null}
    import asyncio
    from os import getenv

    from agno.agent import Agent
    from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
    from agno.vectordb.pineconedb import PineconeDb

    api_key = getenv("PINECONE_API_KEY")
    index_name = "thai-recipe-index"

    vector_db = PineconeDb(
        name=index_name,
        dimension=1536,
        metric="cosine",
        spec={"serverless": {"cloud": "aws", "region": "us-east-1"}},
        api_key=api_key,
    )

    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,
        # 启用代理搜索知识库
        search_knowledge=True,
        # 启用代理读取聊天记录
        read_chat_history=True,
    )

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

        # 创建并使用代理
        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>

## PineconeDb 参数

<Snippet file="vectordb_pineconedb_params.mdx" />

## 开发者资源

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