SystemsAgentsStory 5 of 5Sample

Postgres + pgvector hybrid search as agent memory

Sample story. Combining keyword and vector search in one database, and merging the rankings with reciprocal rank fusion.

Two librarians#

Ask one librarian for "books about a boy wizard" and she understands what you mean even if you never say the title. Ask another for "ISBN 0-7475-3269-9" and he finds it instantly, but would be lost with a vague description. Hybrid search asks both and merges their answers.

One query, two rankings#

What this sample leaves out#

A full story would include the SQL for both queries and the fusion step, index choices (HNSW vs IVFFlat), how to tune kk in reciprocal rank fusion, and when Postgres stops being enough. This sample stops here.

You are reading the overview. Switch to “Full deep dive” in the top bar for the mechanics, maths and code.

Sources

  1. pgvector: Open-source vector similarity search for Postgres · GitHub
  2. PostgreSQL documentation: Full Text Search · PostgreSQL