Skip to content

feat(api): add owning-entity external_id to search results - #1101

Merged
jope-bm merged 1 commit into
mainfrom
search-result-external-id
Jul 18, 2026
Merged

feat(api): add owning-entity external_id to search results#1101
jope-bm merged 1 commit into
mainfrom
search-result-external-id

Conversation

@jope-bm

@jope-bm jope-bm commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Why

External agents calling the hosted Basic Memory Cloud /mcp search_notes tool have no way to link a search hit back to the note in the web app. Every other content tool already returns web-app links, but search was excluded because SearchResult did not expose the entity external_id UUID that link-building needs (#1423).

What

  • SearchResult gains external_id: Optional[str] — the owning entity's UUID (the parent entity for observation and relation hits, the note itself for entity hits).
  • to_search_results() populates it from parent_entity.external_id, which is already batch-fetched to shape the existing entity/permalink fields.

Pure plumbing: no search-index column, no reindex.

How it was tested

  • tests/api/v2/test_search_hydration.py: _make_entity now carries external_id; added test_external_id_populated_for_all_result_types (entity/observation/relation all resolve to the owning entity's UUID) and test_external_id_none_when_owning_entity_missing.
  • Fixed the fake entities in tests/api/v2/test_utils_telemetry.py.
  • uv run pytest tests/api/v2/test_search_hydration.py tests/api/v2/test_utils_telemetry.py tests/api/v2/test_search_router_telemetry.py tests/schemas/test_search.py → 22 passed. Lint + pyright clean.

Companion

The consumer is a basic-memory-cloud PR that builds /notes?id=cloud|... deep-links per search result from this field. That PR pins its basic-memory git rev to this branch's commit and must be re-pinned to the merged commit here.

🤖 Generated with Claude Code

SearchResult now carries the owning entity's external_id UUID (the parent entity for observation and relation hits), populated in to_search_results from the already-batch-fetched entity. This lets the hosted MCP layer build stable web-app deep-links to the note each search hit matched (#1423).

No search-index column and no reindex is needed: the parent entity is already loaded to shape the entity/permalink fields.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Joe P <joe@basicmemory.com>
@jope-bm jope-bm changed the title feat(search): add owning-entity external_id to search results feat(api): add owning-entity external_id to search results Jul 18, 2026
@jope-bm
jope-bm merged commit 55fea20 into main Jul 18, 2026
22 of 24 checks passed
@jope-bm
jope-bm deleted the search-result-external-id branch July 18, 2026 14:27
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.

1 participant