Skip to content

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

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

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

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

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

Copy link
Copy Markdown
Contributor Author

Closing in favor of #984, which contains the same patch with the required DCO sign-off trailer.

@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: 16144196fc

ℹ️ 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".

Comment on lines +2015 to +2016
for si_key, similarity in similarity_by_si_key.items():
row = search_index_rows.get(si_key)

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 Preserve row type during hybrid fusion

Now that vector hydration can append multiple SearchIndexRows with the same numeric id but different type, default hybrid searches still drop one of them because _search_hybrid stores FTS/vector rows in rows_by_id, fts_scores, and vec_scores keyed only by row.id (see src/basic_memory/repository/search_repository_base.py around lines 2207-2239). In semantic-enabled clients where hybrid is the default, a vector match for entity:4 and relation:4 will collapse to whichever row is assigned last, so the collision this patch fixes for vector-only remains user-visible in hybrid mode; carry the (type, id) key through the fusion maps as well.

Useful? React with 👍 / 👎.

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

1 participant