Skip to content

fix: preserve backend relevance order in textual memory search - #2388

Open
Shy7777 wants to merge 1 commit into
MemTensor:dev-v2.0.35from
Shy7777:fix/preserve-text-memory-search-ranking
Open

Shy7777 wants to merge 1 commit into
MemTensor:dev-v2.0.35from
Shy7777:fix/preserve-text-memory-search-ranking

Conversation

@Shy7777

@Shy7777 Shy7777 commented Sep 18, 2026

Copy link
Copy Markdown

Description

With a Qdrant collection configured for Euclidean distance, GeneralTextMemory.search() returns its matches in the wrong order. For example, a query with distances 0.0, 0.7071, and 2.0 comes back with the farthest match first, even though Qdrant returned the nearest one first. This also reverses the order within a limited top-k result.

The memory layer currently re-sorts every score descending. That works for similarity scores, but Euclidean scores are distances. This change keeps the backend's relevance order when converting vector results into memory items. It leaves the scores, selected memories, and public API unchanged.

The regression stores three memories in a real embedded Qdrant collection and searches them using fixed embeddings. It covers Euclidean, cosine, and dot-product collections, plus a smaller top-k. Only the LLM and embedding providers are mocked; the memory and vector-store paths run normally.

Fixes #2387

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Before the fix: the two Euclidean cases failed with reversed order; the four cosine/dot cases passed.
  • poetry run pytest tests/memories/textual/ tests/vec_dbs/test_qdrant.py -q: 76 passed.
  • make format: passed.
  • Repository pre-commit hooks on both changed files: passed.

Validated on macOS 15.5 / Python 3.12.14 with qdrant-client 1.19.1. The tests use embedded Qdrant; a remote Qdrant server, Milvus, and the full project/API suite were not run.

  • Unit Test
  • Test Script Or Test Steps (the regression command above)

Checklist

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

Documentation: no public API or configuration change; a separate documentation PR is not needed. No specific reviewer has been requested.

Reviewer Checklist

  • Made sure Checks passed
  • Tests have been provided

Copilot AI lite review requested due to automatic review settings September 18, 2026 19:23
@Memtensor-AI Memtensor-AI added area:memory 记忆存储、检索、更新、召回逻辑 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2388
Task: 2cc661095714f2f5
Base: dev-v2.0.35
Head: fix/preserve-text-memory-search-ranking

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

⚠️ Automated Test Results: INCONCLUSIVE

Automated tests inconclusive (auto-generated test defect); treated as non-blocking. Manual review recommended. Details: The newly added parametrized test fails during setup because GeneralTextMemory construction reaches the real VecDBFactory instead of a mocked one, causing initialization to fail before any assertion runs.

Branch: fix/preserve-text-memory-search-ranking

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

Labels

area:memory 记忆存储、检索、更新、召回逻辑 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants