← AI GitHub

AI GitHub

pgvector for embedding search in Postgres

Run exact and approximate vector queries alongside existing relational data.

Data and RetrievalPublished 2 min read

Key Takeaways

  • The extension adds vector types, distance operators and index methods to PostgreSQL.
  • Enable the extension in a test database and choose a distance operator that matches the model.
  • Start with exact search, then add an approximate index and compare query plans, recall and latency.
  • Approximate indexes can return fewer candidates after filtering.

How it works

The extension adds vector types, distance operators and index methods to PostgreSQL. Embeddings can be queried with joins and filters using the same database as application records.

What you need

Enable the extension in a test database and choose a distance operator that matches the model. Use the same schema and constraints as the target application where possible.

What to try first

Start with exact search, then add an approximate index and compare query plans, recall and latency. Use the same tenant or category filters production requests will carry.

Try the same query for a tenant with ten records and one with ten thousand. Inspect the plan in both cases before setting a global search parameter.

Where to look for failures

Approximate indexes can return fewer candidates after filtering. Measure that behavior and consider the cost of updates and index maintenance.

Related Franklin pages

Decide whether search belongs in your existing database or in an index inside the process. Compare operational needs such as persistence, filtering and updates as well as nearest-neighbor speed.

For the role of the index in nearest-neighbor search, see Franklin’s glossary. Vector indexes

Project documentation

Try it for your workflow

Explore the project’s documentation for setup and usage, or save this page to a collection for later.

Read the project documentation ↗