Skip to content

Handle vector outputs from ONNX cross-encoders - #945

Open
remote-controlled-man wants to merge 1 commit into
qdrant:mainfrom
remote-controlled-man:codex/prflow-aa4b502ff962
Open

remote-controlled-man wants to merge 1 commit into
qdrant:mainfrom
remote-controlled-man:codex/prflow-aa4b502ff962

Conversation

@remote-controlled-man

Copy link
Copy Markdown
Contributor

All Submissions

  • Followed the contributing guidelines.
  • Checked for existing issues and pull requests covering this change.

A custom ONNX cross-encoder can emit one score per pair as a vector with shape [batch]. FastEmbed currently indexes that vector as a matrix, raising IndexError instead of returning scores.

Use the vector directly when the first ONNX output is one-dimensional. For matrix outputs, keep selecting the first column.

Validation

  • Two tiny local ONNX models exercise vector and column outputs through rerank, serial rerank_pairs, and parallel rerank_pairs. On the original implementation, the three vector cases fail and the three column controls pass. All six pass with the change.
  • On macOS arm64 with Python 3.13.15, 11 offline custom-model tests passed, both Ruff pre-commit hooks passed, and mypy reported no issues in 71 source files. GitHub Actions covers the model-backed suite, Pyright, and the OS/Python matrix.

Developed and tested with Codex assistance.

Copilot AI balanced review requested due to automatic review settings December 5, 2026 10:46

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ONNX cross-encoder scoring path now accepts one-dimensional model output as scores. For outputs with additional dimensions, it continues to select the first column. Parameterized tests cover vector and column outputs through rerank and sequential and parallel rerank_pairs.

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

Change: Bug fix

Possibly related PRs

  • qdrant/fastembed#882: Addresses the same vector-shaped ONNX score output case in the scoring path.
Merge Risk: Minimal · up to a5576

Custom cross-encoders whose first output is a per-pair score vector now work instead of failing with an IndexError, and matrix outputs behave as before. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: ONNX cross-encoder outputs that are one-dimensional vectors are now handled. The raw summary and objectives confirm that onnx_embed_pairs uses one-dimensional output d…
Description check Passed The description states the problem (a one-dimensional [batch] ONNX output raises IndexError), the fix (use the vector directly, keep first-column selection for matrices), and the validation performed.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: ONNX cross-encoder outputs that are one-dimensional vectors are now handled. The raw summary and objectives confirm that onnx_embed_pairs uses one-dimensional output directly and keeps first-column selection for matrix outputs.

Full details: Description check

Explanation

The description states the problem (a one-dimensional [batch] ONNX output raises IndexError), the fix (use the vector directly, keep first-column selection for matrices), and the validation performed. This matches the raw summary and objectives.

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 698c92d6-8fd7-49bb-834e-e2cb5321fcd4
Commits

Reviewing files that changed from the base of the PR and between ac9ab5c and a55761a.

Files selected for processing: 4

  • fastembed/rerank/cross_encoder/onnx_text_model.py
  • tests/misc/reranker_scores_column.onnx
  • tests/misc/reranker_scores_vector.onnx
  • tests/test_custom_models.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.

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.

2 participants