Skip to content

fix(mcp): keep search index type in vector hydration#984

Closed
rudi193-cmd wants to merge 1 commit into
basicmachines-co:mainfrom
rudi193-cmd:fix/982-vector-search-id-collision-dco
Closed

fix(mcp): keep search index type in vector hydration#984
rudi193-cmd wants to merge 1 commit into
basicmachines-co:mainfrom
rudi193-cmd:fix/982-vector-search-id-collision-dco

Conversation

@rudi193-cmd

Copy link
Copy Markdown
Contributor

Fixes #982.

Summary

  • Key vector-search hydration by (type, id) instead of bare id, so entity/relation/observation rows with the same search_index id no longer overwrite each other.
  • Keep the existing broad WHERE id IN (...) query shape and apply type discrimination in Python, matching the existing filtered-search guard.
  • Update vector-search test mocks and add a regression test covering entity:4:0 and relation:4:0 both hydrating successfully.

Test plan

  • uv run pytest tests/repository/test_vector_threshold.py tests/repository/test_vector_pagination.py
  • uv run ruff format src/basic_memory/repository/search_repository_base.py tests/repository/test_vector_threshold.py tests/repository/test_vector_pagination.py
  • uv run ruff check src/basic_memory/repository/search_repository_base.py tests/repository/test_vector_threshold.py tests/repository/test_vector_pagination.py

Replaces #983, which had the same patch but missed the DCO sign-off trailer.

Signed-off-by: rudi193-cmd <rudi193@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df486d4b9e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

si_ids = list(similarity_by_si_id.keys())
search_index_rows = await self._fetch_search_index_rows_by_ids(si_ids)
si_keys = list(similarity_by_si_key.keys())
search_index_rows = await self._fetch_search_index_rows_by_ids(si_keys)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Carry typed keys through hybrid fusion

When this vector path is invoked from _search_hybrid (retrieval_mode=hybrid), the typed duplicate ids returned here are immediately collapsed because hybrid fusion still stores rows_by_id, fts_scores, vec_scores, and fused_scores by bare row.id. A query whose vector hits include both entity:4:0 and relation:4:0 will now return both in vector mode, but hybrid mode overwrites one of them, so the collision fix does not apply to MCP/API hybrid searches. Please carry (row.type, row.id) through the hybrid fusion maps as well.

Useful? React with 👍 / 👎.

@groksrc

groksrc commented Jun 12, 2026

Copy link
Copy Markdown
Member

Thanks for the PR! This has been fixed in #986 but if you continue to find trouble with it we are happy to accept your PRs.

@groksrc groksrc closed this Jun 12, 2026
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.

Vector search silently drops results when entity and relation search_index ids collide

2 participants