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

# DOCX 知识库

## 代码

```python theme={null}
from pathlib import Path

from agno.agent import Agent
from agno.knowledge.docx import DocxKnowledgeBase
from agno.vectordb.pgvector import PgVector

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

# 使用 data/docs 目录中的 DOCX 文件创建知识库
knowledge_base = DocxKnowledgeBase(
    path=Path("data/docs"),
    vector_db=PgVector(
        table_name="docx_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 something 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 python-docx 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/docx_kb.py
      ```

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