Skip to content

fix(reranker): preserve memory text when sources are missing - #2634

Merged
endxxxx merged 1 commit into
dev-v2.0.37from
fix/bge-source-memory-fallback
Nov 19, 2026
Merged

endxxxx merged 1 commit into
dev-v2.0.37from
fix/bge-source-memory-fallback

Conversation

@endxxxx

@endxxxx endxxxx commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Description

With rerank_source="sources", an HTTP BGE candidate with valid memory text but missing or None sources was sent as an empty document. The concatenator now falls back to the cleaned primary memory text when none of the selected source fields exists.

Each candidate retains its document position, so returned scores map back to the correct original items. Tests cover normal source enrichment, empty source lists, missing metadata, custom selected fields, prefix stripping, both factory aliases and both supported HTTP response formats.

Fixes #2559.

Type of change

  • Bug fix

How Has This Been Tested?

  • Unit and regression tests use synthetic candidates and intercept only requests.Session.send
  • Test steps reproduced 15 failures and 4 passing controls before the fix
  • Automated HTTP request tests exercise the public reranker and configuration factory

Actual verification output

make format
All checks passed!
669 files left unchanged

poetry run pytest tests/reranker/ -q --tb=short
73 passed in 7.51s

The commit passed all applicable repository pre-commit hooks.

Checklist

  • Self-review completed
  • The fallback has an explanatory comment
  • Regression tests added
  • Documentation applicability reviewed for this internal bug fix
  • Related issue linked
  • Review context provided for @endxxxx

Reviewer Checklist

@Memtensor-AI Memtensor-AI added area:core MOS 编排层 / 框架底座 / 跨模块问题 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Nov 19, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2634
Task: b442dc8f47e02e26
Base: dev-v2.0.37
Head: fix/bge-source-memory-fallback
Head SHA: feaee5e91517965069eb0ab6196a589f00a1d858

🔍 OpenCodeReview found 1 issue(s) in this PR.


1. src/memos/reranker/concat.py (L102)

memory is not guaranteed to be a str here: line 88 deliberately keeps the raw value (_TAG1.sub(...) if isinstance(m, str) else m), so a non-string m (e.g. None or a dict/list) flows through unchanged. When there are no sources, memory or "" therefore returns that non-string value, and it is appended to a list[str] that is later serialized as the JSON documents payload sent to the reranker (http_bge.rerank, where non-string memories are otherwise filtered out). Use the empty-string fallback for non-string values to keep the return type and payload well-formed.

💡 Suggested Change

Before:

        concat_string = process_source(sources) if sources else (memory or "")

After:

        if sources:
            concat_string = process_source(sources)
        else:
            concat_string = memory if isinstance(memory, str) else ""

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Nov 19, 2026
@endxxxx
endxxxx merged commit 4bb7126 into dev-v2.0.37 Nov 19, 2026
18 checks passed
@endxxxx
endxxxx deleted the fix/bge-source-memory-fallback branch November 19, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core MOS 编排层 / 框架底座 / 跨模块问题 status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants