Skip to main content
Vector search compares an embedded query with the embeddings stored for knowledge documents.

How It Works

  1. The embedder converts the query to a vector.
  2. The vector database compares it with stored document vectors.
  3. The database orders results using its configured distance metric.
PgVector uses cosine distance by default. It also supports L2 distance and maximum inner product. Test hybrid or keyword search when specific tokens such as IDs and error codes affect relevance.

Configuration

Basic Setup

Set the API key used by OpenAIEmbedder:

With Reranking

Set the API keys used by the default OpenAI embedder and Cohere reranker:
Apply CohereReranker to the vector-search candidates:

Example

1

Install dependencies

2

Run PgVector

3

Export the OpenAI API key

vector_search.py

Next Steps

Hybrid Search

Combine vector search with keyword matching

Embedders

Choose the right embedding model