Skip to content

fix(firestore): keep thought parts out of FirestoreMemoryService - #7831

Closed
adityasingh2400 wants to merge 1 commit into
google:mainfrom
adityasingh2400:fix/firestore-memory-skip-thoughts
Closed

adityasingh2400 wants to merge 1 commit into
google:mainfrom
adityasingh2400:fix/firestore-memory-skip-thoughts

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
FirestoreMemoryService built search keywords from every part of an event, including the model's thought parts. It stored those parts in the memory content, and search_memory returned them. Words that only appeared in the model's hidden reasoning made a memory match a query, load_memory / PreloadMemoryTool handed that reasoning back to the model, and a thought-only event still got a memory document.

Solution:

  • Ingest: keep only non-thought parts. They are the source of the keywords and of the stored content, and an event with no visible text is skipped as before.
  • Search: drop thought parts from returned content, so memories written before this change come back clean too (as fix(memory): exclude thought parts from SQLite search results #7691 did for SQLite).

This matches the in-memory and Vertex RAG memory services (#7473) and SQLite (#7691). Parts with thought=False or None are unchanged.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added to tests/unittests/integrations/firestore/test_firestore_memory_service.py:

  • test_add_session_to_memory_keeps_thoughts_out: keywords and stored content come from the visible part only.
  • test_add_session_to_memory_skips_thought_only_events: no document is written.
  • test_search_memory_drops_stored_thought_parts: a document that already holds a thought part is returned without it.
# On main (before the fix)
AssertionError: assert {'brown', 'es...', 'weighing'} == {'brown', 'fox', 'quick'}
AssertionError: Expected 'set' to not have been called. Called 1 times.
AssertionError: assert ['weighing th...ck brown fox'] == ['quick brown fox']

# With the fix
$ pytest tests/unittests/integrations/firestore tests/unittests/memory
256 passed

pre-commit run passes on the changed files, and mypy reports no issues in firestore_memory_service.py.

Manual End-to-End (E2E) Tests:

I don't have a Firestore instance or emulator. The tests drive the service through the mocked Firestore client the existing tests use, and assert on what batch.set writes and what search_memory returns.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

None.

Memory ingestion built search keywords from every part, including the
model's thoughts, stored them in the memory content, and search returned
them, so load_memory handed the model its own earlier reasoning and words
that only appeared in it matched queries. Skip thought parts when writing
memories, and drop them from search results so memories written before
this change are clean too, as the in-memory, SQLite and Vertex RAG memory
services already do.

Fixes google#7830
copybara-service Bot pushed a commit that referenced this pull request Oct 31, 2026
Merge #7831

Keywords and stored content now come from non-thought parts only, an event
whose only text is a thought is no longer stored, and search_memory drops
thought parts from documents written before this change, skipping a
document left with no parts.

Part of #7830

PiperOrigin-RevId: 1010967300
@adk-bot

adk-bot commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Thank you @adityasingh2400 for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit af371b7.

Closing this PR as the changes are now in the main branch.

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

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FirestoreMemoryService indexes, stores and returns the model's thought parts

3 participants