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

# ArXiv 知识库

## Code

```python theme={null}
from agno.agent import Agent
from agno.knowledge.arxiv import ArxivKnowledgeBase
from agno.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

# 使用 ArXiv 文档创建知识库
knowledge_base = ArxivKnowledgeBase(
    queries=["Generative AI", "Machine Learning"],
    # 表名：ai.arxiv_documents
    vector_db=PgVector(
        table_name="arxiv_documents",
        db_url=db_url,
    ),
)
# 加载知识库
knowledge_base.load(recreate=False)

# 创建一个带有知识库的 Agent
agent = Agent(
    knowledge=knowledge_base,
    search_knowledge=True,
)

# 询问 Agent 关于知识库的问题
agent.print_response(
    "Ask me about generative ai from the knowledge base", markdown=True
)
```

## 使用方法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="安装库">
    ```bash theme={null}
    pip install -U sqlalchemy 'psycopg[binary]' pgvector agno
    ```
  </Step>

  <Step title="运行 PgVector">
    ```bash theme={null}
    docker run -d \
      -e POSTGRES_DB=ai \
      -e POSTGRES_USER=ai \
      -e POSTGRES_PASSWORD=ai \
      -e PGDATA=/var/lib/postgresql/data/pgdata \
      -v pgvolume:/var/lib/postgresql/data \
      -p 5532:5432 \
      --name pgvector \
      agnohq/pgvector:16
    ```
  </Step>

  <Step title="运行 Agent">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/agent_concepts/knowledge/arxiv_kb.py
      ```

      ```bash Windows theme={null}
      python cookbook/agent_concepts/knowledge/arxiv_kb.py
      ```
    </CodeGroup>
  </Step>
</Steps>
