Skip to content

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

Closed as not planned

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

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Sep 25, 2026
  2. llalitkumarrr commented on Sep 25, 2026

    @llalitkumarrr
    Collaborator

    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.

  3. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    pythonPull requests that update python code
    and removed
    pythonPull requests that update python code
    on Sep 25, 2026
  4. Nanduu24 commented on Sep 25, 2026

    @Nanduu24
    Author

    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 optional pgvector extra, 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?

  5. added a commit that references this issue on Sep 25, 2026
    a04727e
  6. DeanChensj commented on Oct 26, 2026

    @DeanChensj
    Collaborator

    Thanks again for proposing this and for the implementation in #7274, @Nanduu24.

    We're closing this as not planned for core google-adk for 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 via VertexAiMemoryBankService, and for self-hosted setups BaseMemoryService can 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.

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