Skip to content

FEAT: Add a self-hosted PostgreSQL/pgvector semantic MemoryService #7273

Description

@Nanduu24

🔴 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:

  • InMemoryMemoryService ranks by keyword overlap and its own docstring says it
    is for "prototyping purpose only" — it loses everything on restart.
  • VertexAiMemoryBankService and VertexAiRagMemoryService provide 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_memory embed each event's text and
    upsert it (idempotent per event) into the table, scoped by
    (app_name, user_id).
  • search_memory embeds the query and returns the nearest memories by cosine
    distance via a pgvector HNSW index.
  • Embeddings are produced through the existing google-genai client by default,
    and an injectable embedder callable 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 a vector(dim) column, a
    (app_name, user_id) index, and an HNSW index using vector_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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

needs review[Status] The PR/issue is awaiting review from the maintainerservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions