google / google/adk-python-community
feat(memory): add MongoDBMemoryService with Atlas Vector Search support
- Vorherrschende Sprache
- Python
- Sterne
- 182
- Forks
- 75
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
## Motivation
The community repo has memory service proposals for Valkey (#155/#156), Milvus (#69), Firestore (#38), and SQL backends (#99), but no MongoDB-backed memory service. MongoDB is one of the most widely deployed document databases, and MongoDB Atlas provides native vector search (`$vectorSearch`), making it a natural backend for agent long-term memory with semantic recall.
Related: #31/#32 add a MongoDB *session* service. This proposal is complementary — a `MemoryService` implementation for long-term memory retrieval, not session/state storage. If #32 merges, the two modules together would give ADK users a full MongoDB persistence story.
## Proposed API
A `MongoDBMemoryService` implementing ADK's `BaseMemoryService` interface:
- `add_session_to_memory(session)` — extracts session events, generates embeddings via a pluggable embedding function, and stores documents (`app_name`, `user_id`, `session_id`, `content`, `embedding`, `timestamp`) in a configurable collection
- `search_memory(app_name, user_id, query)` — semantic retrieval via Atlas `$vectorSearch` with top-k limits, similarity threshold, and app/user isolation via pre-filters; falls back to Atlas text search for deployments without a vector index
Configuration options: connection string, database/collection names, embedding function, vector index name, `top_k`, similarity threshold.
## Dependencies
- `pymongo>=4.15,<5.0` (matching the pin in #32) as an optional dependency under a `[mongodb]` extra
## Testing Plan
- Unit tests (mocked client): cover all public methods, edge cases, error conditions
- Integration tests: run against the `mongodb/mongodb-atlas-local` Docker image (supports vector search locally), covering vector similarity search, user/app isolation, top-k limits, distance threshold filtering, metadata preservation, and index idempotency
---
I'd like to implement this myself and will follow the module structure and contribution lifecycle in CONTRIBUTING.md. Happy to adjust the approach based on maintainer feedback.
Beitragsleitfaden
Rechercherichtung
Beginne mit CONTRIBUTING.md und der bestehenden Modulstruktur rund um das BaseMemoryService-Interface. Überprüfe die vorgeschlagenen öffentlichen Methoden, die optionale pymongo-Abhängigkeit sowie den Plan für Tests mit Mocking und Atlas-local Docker. Als abgeschlossen gilt die Aufgabe, wenn der MongoDB-Speicherdienst die aufgeführten Abruf-, Isolations-, Filterungs-, Metadaten-, Fehler- und Indexverhaltensweisen abdeckt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- docker, mongodb, python
- Bereich
- backend, databases
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100