> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phidata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PgVector

The PgVector Agent uses PgVector as Knowledge Base and Storage for the Agent.

```python theme={null}
from phi.agent import Agent
from phi.storage.agent.postgres import PgAgentStorage
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector

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

agent = Agent(
    storage=PgAgentStorage(table_name="recipe_agent", db_url=db_url),
    knowledge_base=PDFUrlKnowledgeBase(
        urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
        vector_db=PgVector(table_name="recipe_documents", db_url=db_url),
    ),
    # Show tool calls in the response
    show_tool_calls=True,
    # Enable the agent to search the knowledge base
    search_knowledge=True,
    # Enable the agent to read the chat history
    read_chat_history=True,
)
# Comment out after first run
agent.knowledge_base.load(recreate=False)  # type: ignore

agent.print_response("How do I make pad thai?", markdown=True)
```

## Usage

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

  <Snippet file="run-pgvector-step.mdx" />

  <Step title="Install libraries">
    ```bash theme={null}
    pip install -U pgvector pypdf "psycopg[binary]" sqlalchemy phidata
    ```
  </Step>

  <Step title="Run PgVector Agent">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/integrations/pgvector/agent.py
      ```

      ```bash Windows theme={null}
      python cookbook/integrations/pgvector/agent.py
      ```
    </CodeGroup>
  </Step>
</Steps>

## Information

* View on [Github](https://github.com/agno-agi/phidata/tree/main/cookbook/integrations/pgvector/agent.py)
