Repository navigation
FEAT: Add a self-hosted PostgreSQL/pgvector semantic MemoryService #7273
Description
🔴 Required Information
Is your feature request related to a specific problem?
ADK ships three memory services, and none of them offers persistent, semantic
memory on infrastructure a user controls:
InMemoryMemoryServiceranks by keyword overlap and its own docstring says it
is for "prototyping purpose only" — it loses everything on restart.VertexAiMemoryBankServiceandVertexAiRagMemoryServiceprovide semantic
memory but require Google Cloud.
So teams that need semantic long-term memory but run on-premise, in air-gapped
environments, or under data-residency constraints (e.g. EU/GDPR) have no
built-in option — the exact gap raised in #6254. The pending SQLite memory
service (#4116) adds persistence but, as noted in its own review, gives
"exact-match queries" rather than semantic retrieval. Postgres with pgvector
is the natural way to close the semantic half of that gap on self-hosted
infrastructure.
Describe the Solution You'd Like
A new PgVectorMemoryService (under google.adk.integrations.pgvector) that
implements BaseMemoryService and stores event embeddings in a PostgreSQL table
with the pgvector extension:
add_session_to_memory/add_events_to_memoryembed each event's text and
upsert it (idempotent per event) into the table, scoped by
(app_name, user_id).search_memoryembeds the query and returns the nearest memories by cosine
distance via a pgvector HNSW index.- Embeddings are produced through the existing
google-genaiclient by default,
and an injectableembeddercallable makes the service provider-agnostic. - Ships as an optional extra:
pip install "google-adk[pgvector]".
It follows the existing integrations/redis pattern (config object + injectable
client), so the store runs entirely on a database the user owns.
Impact on your work
Lets ADK agents keep persistent, semantically searchable memory without adopting
a managed cloud memory service — important for on-prem, air-gapped, and
data-residency-constrained deployments, and for local development against a real
(not in-memory) store.
Willingness to contribute
Yes — I have a working implementation with unit tests and am ready to open a PR.
I'd like to take this one: could a maintainer please assign it to me? I'll open
the PR once there's a maintainer go-ahead on the approach.
🟡 Recommended Information
Describe Alternatives You've Considered
InMemoryMemoryService— not persistent, keyword-only.- Vertex AI memory services — require GCP; unusable for the deployments
above. - SQLite memory service (feat(memory): add SQLite memory service #4116) — persistent but exact-match; complements
rather than replaces a vector backend. - A generic SQLAlchemy memory service — would still need a vector type and
index; targeting pgvector directly keeps the HNSW index and cosine operator
first-class.
Proposed API / Implementation
from google.adk.integrations.pgvector import PgVectorMemoryService
from google.adk.integrations.pgvector import PgVectorMemoryServiceConfig
memory_service = PgVectorMemoryService(
PgVectorMemoryServiceConfig(
dsn="postgresql://user:password@localhost:5432/adk",
embedding_model="gemini-embedding-001",
embedding_dimension=768,
)
)
await memory_service.add_session_to_memory(session)
response = await memory_service.search_memory(
app_name="my_app", user_id="user1", query="what did we decide about billing?"
)Implementation notes:
integrations/pgvector/package:PgVectorMemoryServiceConfig,
PgVectorMemoryService, and a README.- One table
adk_memory_entries(configurable) with avector(dim)column, a
(app_name, user_id)index, and an HNSW index usingvector_cosine_ops;
created on first use. psycopg(v3) async +psycopg_pool.AsyncConnectionPool; the connection pool
and the embedder are both injectable, which keeps the service unit-testable
without a live database.- New optional extra
pgvector(psycopg[binary],psycopg-pool,pgvector).
Additional Context
The design mirrors the existing integrations/redis session service and the
google-genai embedding usage already in tools/spanner and
integrations/mongodb. Happy to align the storage schema with the direction of
#4116 if the maintainers prefer a shared table layout.
Activity
llalitkumarrr commentedon Sep 25, 2026
Hi @Nanduu24,
Thank you for your request. We will review it and take the necessary action. We will reach out if we require any additional details, we appreciate your patience in the meantime.
Nanduu24 commentedon Sep 25, 2026
Hi @chelsealong — thanks for flagging, and appreciate you checking first! I'm already on this one: I opened this issue and noted above that I have a complete implementation ready (
PgVectorMemoryService+ config + README, an optionalpgvectorextra, and passing unit tests that run without a live DB), and asked to be assigned. I'm opening my PR now and will link it here. Since you offered to step aside if someone's already on it, I'll gratefully take you up on that — and I'm happy to fold in any feedback you have. @wyf7107 @llalitkumarrr could you assign this to me?feat(memory): add self-hosted PostgreSQL/pgvector memory service
DeanChensj commentedon Oct 26, 2026
Thanks again for proposing this and for the implementation in #7274, @Nanduu24.
We're closing this as not planned for core
google-adkfor now. The full reasoning (maintenance burden, a few design points, and alternatives) is in #7274 (comment). In short: for managed infrastructure we recommend Vertex AI Memory Bank viaVertexAiMemoryBankService, and for self-hosted setupsBaseMemoryServicecan be implemented in a standalone package or contributed to google/adk-python-community.If more people need a first-party Postgres/pgvector memory service, please add a 👍 or describe your use case here. We'll keep watching this issue and will re-evaluate if the demand is there.