Skip to content

fix: score a tuple of pairs in rerank_pairs instead of treating it as one pair - #797

Open
michaelkillgta wants to merge 1 commit into
qdrant:mainfrom
michaelkillgta:fix/rerank-pairs-tuple-of-pairs
Open

michaelkillgta wants to merge 1 commit into
qdrant:mainfrom
michaelkillgta:fix/rerank-pairs-tuple-of-pairs

Conversation

@michaelkillgta

@michaelkillgta michaelkillgta commented Oct 9, 2026 •

Copy link
Copy Markdown

Fixes #796

OnnxCrossEncoderModel._rerank_pairs treated every tuple input as a single (query, document) pair and wrapped it in a list. A tuple of pairs (still a valid Iterable[tuple[str, str]]) became one malformed pair, and the tokenizer raised TypeError: TextInputSequence must be str.

Change

  • Treat a tuple as a single pair only when it is exactly two strings. Any other tuple is converted to a list of pairs, so it also gets the same small-input fast path that lists already get.
  • Behaviour for lists, generators and a single (query, document) tuple is unchanged.

Test

  • test_rerank_pairs_tuple_input checks that a tuple of two pairs and a tuple of three pairs give the same scores as the equivalent list, and that a single pair still works. It fails on main with the TypeError above and passes with this change.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  • Does your submission pass the existing tests?
  • Have you added tests for your feature?
  • Have you installed pre-commit ...? (Not installed as a hook. I ran the pinned ruff 0.3.4 check and format directly.)

Local runs: tests/test_text_cross_encoder.py and tests/test_custom_models.py give 15 passed. The one failure, test_rerank, already fails on main on my machine because of the bge-reranker-v2-m3-int8 canonical scores, so it is unrelated. ruff 0.3.4 (the pre-commit pin) check and format pass, and mypy fastembed with the CI flags passes.

@michaelkillgta
michaelkillgta requested a review from joein as a code owner October 9, 2026 13:11
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c71b3413-aee2-416f-9b90-367b367516d6

📥 Commits

Reviewing files that changed from the base of the PR and between d076f08 and 04e9688.


📒 Files selected for processing (2)
  • fastembed/rerank/cross_encoder/onnx_text_model.py
  • tests/test_text_cross_encoder.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

_rerank_pairs now treats a tuple of exactly two strings as one query-document pair. It converts other tuples to lists of pairs. Tests check that tuples of two and three pairs produce the same scores as equivalent lists, and that a single query-document tuple remains accepted.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to 04e96

Tuples of query-document pairs are now scored like equivalent lists, and a single (query, document) tuple still works. No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #796 requires rerank_pairs() to score a tuple of (query, document) pairs like an equivalent list and to preserve a single pair tuple. The change in OnnxCrossEncoderModel._rerank_pairs trea…
Out of Scope Changes check Passed The diff contains only the tuple-input fix in fastembed/rerank/cross_encoder/onnx_text_model.py and its regression test in tests/test_text_cross_encoder.py. Both changes directly support issue #79…
Title check Passed The title clearly and concisely identifies the main change: correcting tuple-of-pairs handling in rerank_pairs.
Description check Passed The description directly explains the tuple-handling bug, the implementation change, preserved behavior, tests, and validation results.


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

[Bug]: rerank_pairs raises TypeError when pairs are passed as a tuple of pairs

1 participant