Skip to content

fix(memory): return custom_metadata from VertexAiMemoryBankService.search_memory - #6947

Open
Yatsuiii wants to merge 1 commit into
google:mainfrom
Yatsuiii:fix/vertex-memory-bank-custom-metadata-readback
Open

fix(memory): return custom_metadata from VertexAiMemoryBankService.search_memory#6947
Yatsuiii wants to merge 1 commit into
google:mainfrom
Yatsuiii:fix/vertex-memory-bank-custom-metadata-readback

Conversation

@Yatsuiii

Copy link
Copy Markdown

Fixes #6946

Summary

search_memory constructed every returned MemoryEntry with only author, content, and timestamp, silently dropping custom_metadata even though this service's own write path already treats it as first-class: _add_memories_via_create merges MemoryEntry.custom_metadata via _merge_custom_metadata_for_memory before writing, and add_memory's own docstring documents metadata as meaningful, round-tripped data. The write side reads it; the read side never returned it.

Adds _from_vertex_metadata / _from_vertex_metadata_value as the symmetric read-side counterpart to the existing write-side _to_vertex_metadata_value, handling the same four value kinds (bool/double/string/timestamp) rather than only strings.

Why this matters

A caller that writes custom_metadata at creation time -- an application-specific identifier used to correlate a memory back to its source, for example -- had no way to get it back through search_memory. No error, no warning; the field was silently empty on every returned MemoryEntry.

Testing plan

  • Verified with a live create -> retrieve round trip against a real Vertex AI Memory Bank instance before implementing the fix, confirming the underlying SDK genuinely returns populated metadata that this class was never reading (details in VertexAiMemoryBankService.search_memory never returns MemoryEntry.custom_metadata, even though the write path treats it as first-class #6946).
  • Added test_search_memory_returns_custom_metadata (covers bool/double/string values) and test_search_memory_with_no_metadata_returns_empty_dict (backward-compat: no metadata -> {}, never None), using the existing mock_vertexai_client / _AsyncListIterator fixtures already in the test file.
  • Added an assertion to the existing test_search_memory confirming custom_metadata == {} for the pre-existing no-metadata case.
  • pytest tests/unittests/memory/ : 89 passed.
  • pytest tests/unittests (full suite): 13493 passed, 0 failed (90 skipped / 31 xfailed / 2 xpassed are pre-existing and unrelated).
  • pre-commit run --all-files on the changed files: all hooks pass, including the repo's own "ADK Compliance Checks".

Scope note

An earlier draft of #6946 also claimed MemoryEntry.id / memory_id forwarding was broken. Testing that specific claim live contradicted it (forwarding is conditional on an SDK-version compatibility check this file's own code already handles correctly via _get_create_memory_config_keys, and a direct low-level SDK call bypassing that check isn't a fair test of it). That claim was cut from the issue before filing and is out of scope for this PR.

…arch_memory

search_memory constructed every returned MemoryEntry with only author,
content, and timestamp, silently dropping custom_metadata even though
this service's own write path already treats it as first-class:
_add_memories_via_create merges MemoryEntry.custom_metadata via
_merge_custom_metadata_for_memory before writing, and add_memory's own
docstring documents metadata as meaningful, round-tripped data.

Adds _from_vertex_metadata / _from_vertex_metadata_value as the
symmetric read-side counterpart to the existing write-side
_to_vertex_metadata_value, handling the same four value kinds
(bool/double/string/timestamp) rather than only strings.

Verified with a live create -> retrieve round trip against a real
Vertex AI Memory Bank instance before implementing, confirming the
underlying SDK genuinely returns populated metadata that this class
was never reading.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VertexAiMemoryBankService.search_memory never returns MemoryEntry.custom_metadata, even though the write path treats it as first-class

2 participants