feat(memory): add DatabaseMemoryService with SQLAlchemy async backend#5339
Open
anmolg1997 wants to merge 1 commit intogoogle:mainfrom
Open
feat(memory): add DatabaseMemoryService with SQLAlchemy async backend#5339anmolg1997 wants to merge 1 commit intogoogle:mainfrom
anmolg1997 wants to merge 1 commit intogoogle:mainfrom
Conversation
Adds a durable, SQL-backed memory service that works with any SQLAlchemy-compatible async database (SQLite, PostgreSQL, MySQL/MariaDB). This fills the gap between the volatile InMemoryMemoryService and the cloud-only Firestore/Vertex AI options, giving self-hosted deployments a persistent memory backend with zero cloud dependencies. The implementation mirrors the keyword-extraction approach used by FirestoreMemoryService and reuses the existing SQLAlchemy patterns established by DatabaseSessionService. Closes google#2524 Closes google#2976
Collaborator
|
Response from ADK Triaging Agent Hello @anmolg1997, thank you for creating this PR! Could you please provide logs or a screenshot of the passed This information will help reviewers to review your PR more efficiently. Thanks! |
Contributor
Author
|
Hi @adk-bot — thanks for the prompt! Here are the full pytest results: New tests (19/19 passing): Full memory test suite (59/59 passing — no regressions): All CI checks (CLA, header-check, agent-triage) are also passing. |
Contributor
Author
|
Hi @wuliang229 — thank you for approving #5338! Would you be able to take a look at this one as well when you get a chance? It adds a SQL-backed |
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.
Summary
Adds
DatabaseMemoryService, a durable, SQL-backed memory service that works with any SQLAlchemy-compatible async database (SQLite viaaiosqlite, PostgreSQL viaasyncpg, MySQL/MariaDB, etc.).InMemoryMemoryServiceand the cloud-only Firestore/Vertex AI options — gives self-hosted deployments a persistent memory backend with zero cloud dependenciesFirestoreMemoryServiceand reuses the SQLAlchemy patterns fromDatabaseSessionServiceadd_session_to_memory,add_events_to_memory(delta ingestion), andsearch_memoryMotivation
Currently, developers not using Vertex AI or Google Cloud Firestore have no persistent memory option —
InMemoryMemoryServiceis explicitly volatile and loses all data on restart. This is a frequently requested feature:Design Decisions
google.adk.memory(notintegrations/)DatabaseSessionServiceplacement insessions/, and uses no external cloud SDKDynamicJSONfromsessions.schemas.shared_memory_schemas.pyfor ORM modelssessions/schemas/pattern, keeps concerns separatedSearchBackendabstraction__getattr__import in__init__.pyDatabaseSessionServicepattern — avoids hard SQLAlchemy dependency for users who don't need itChanges
src/google/adk/memory/database_memory_service.pyDatabaseMemoryServiceimplementationsrc/google/adk/memory/_memory_schemas.pyStorageMemoryEntry)src/google/adk/memory/__init__.pyDatabaseMemoryServicetests/unittests/memory/test_database_memory_service.pyUsage
Test plan
pytest tests/unittests/memory/test_database_memory_service.py)pytest tests/unittests/memory/)isort+pyinkper CONTRIBUTING.md__aenter__/__aexit__) verified