feat(memory): add self-hosted PostgreSQL/pgvector memory backend (PgvectorMemory) - #8307
Open
Nantha kumar (Nanduu24) wants to merge 1 commit into
Open
Nantha kumar (Nanduu24) wants to merge 1 commit into
Nantha kumar (Nanduu24) wants to merge 1 commit into
Conversation
Adds PgvectorMemory under autogen_ext.memory.pgvector, a Memory component backed by PostgreSQL with the pgvector extension. Content is embedded and stored, with its vector, in a table the user owns; query returns the nearest memories by cosine distance using a pgvector HNSW index, and update_context injects them as a system message. The existing memory backends cover Chroma, mem0, and Redis, but none offers vector memory on a general-purpose SQL database the user already controls. PgvectorMemory fills that gap for on-premise, air-gapped, and data-residency constrained deployments. It follows the redis/chromadb component pattern: a serializable config plus an injectable connection pool and embedder, which keeps it unit-testable without a live database. Embeddings use a local SentenceTransformers model by default (configurable), with an injectable override. Ships as the optional extra autogen-ext[pgvector]. Includes unit tests that run against a fake pool and a deterministic embedder (no live database or network), covering add/query ranking, the distance threshold, JSON round-trips, update_context, clear, the connection-pool lifecycle, and component config serialization.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
autogen-ext/memoryshipschromadb,mem0,redis, andcanvas, but none offers semantic vector memory on a general-purpose SQL database the user already controls. Teams running on PostgreSQL that need agent memory on-premise, in air-gapped environments, or under data-residency constraints have no built-in option.This PR adds
PgvectorMemory(autogen_ext.memory.pgvector), aMemorycomponent backed by PostgreSQL with the pgvector extension:addembeds aMemoryContent(TEXT / MARKDOWN / JSON) and stores it, with its vector, in a table the user owns (extension, table, and HNSW index created on first use).queryembeds the query and returns the nearest memories by cosine distance via a pgvector HNSW index, with an optionaldistance_threshold.update_contextinjects the relevant memories as aSystemMessage, matching the other backends.clear/closebehave as expected.model_name), with an injectableembedding_functionoverride.autogen-ext[pgvector].It follows the existing
redis/chromadbcomponent pattern (a serializableComponentconfig), and the connection pool and embedder are both injectable, which keeps it unit-testable without a live database.Testing
tests/memory/test_pgvector_memory.pyrun against an in-process fake pool and a deterministic embedder (no live DB, driver calls, or network), covering add/query ranking, the distance threshold, JSON round-trips,update_context,clear, the connection-pool lifecycle, and component config serialization — 9 passing.psycopgdriver): semantic ranking, JSON round-trip,update_context, cross-instance persistence, thevectorcolumn + HNSW index, andclear().ruff format,ruff check, andpyrightare clean on the changed files.Related issue number
Feature suggestion: #8306
Checks