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

# PgVector Hybrid Search

> Combine PgVector embedding similarity and PostgreSQL full-text rank in one search score.

```python pgvector_hybrid_search.py theme={null}
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector, SearchType

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="hybrid_recipes",
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        search_type=SearchType.hybrid,
        vector_score_weight=0.7,
    )
)
agent = Agent(knowledge=knowledge, search_knowledge=True)

if __name__ == "__main__":
    knowledge.insert(
        name="Recipes",
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
        metadata={"doc_type": "recipe_book"},
    )
    agent.print_response(
        "How do I make chicken and galangal in coconut milk soup?",
        markdown=True,
    )
```

`vector_score_weight` controls the weighted score. `0.7` assigns 70 percent to vector similarity and 30 percent to normalized full-text rank. The value must be between `0` and `1`.

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai pgvector psycopg pypdf sqlalchemy
    ```
  </Step>

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

  <Step title="Export the API key">
    ```bash theme={null}
    export OPENAI_API_KEY=your_openai_api_key_here
    ```
  </Step>

  <Step title="Run the example">
    ```bash theme={null}
    python pgvector_hybrid_search.py
    ```
  </Step>
</Steps>

## Next Steps

| Task                 | Guide                                                                     |
| -------------------- | ------------------------------------------------------------------------- |
| Compare search modes | [Search and retrieval](/knowledge/concepts/search-and-retrieval/overview) |
| Configure PgVector   | [PgVector overview](/knowledge/vector-stores/pgvector/overview)           |

## Developer Resources

* [pgvector hybrid search](https://github.com/pgvector/pgvector#hybrid-search)
