Skip to content

fix(retrieval): run the reranker on CPU under CoreML - #33

Merged
lemon07r merged 2 commits into
VeraTools:masterfrom
citron07r:fix/coreml-reranker-cpu-provider
Aug 19, 2026
Merged

lemon07r merged 2 commits into
VeraTools:masterfrom
citron07r:fix/coreml-reranker-cpu-provider

Conversation

@citron07r

@citron07r citron07r commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Closes #41.

Problem

On an onnx-jina-coreml backend the reranker fails at inference:

Non-zero status code returned while running 11619352191107991357_CoreML_11619352191107991357_3 node.
Name:'CoreMLExecutionProvider_11619352191107991357_CoreML_11619352191107991357_3_3'
Status Message: Error executing model: Unable to compute the prediction using a neural network
model. It can be an invalid input data or broken/unsupported model (error code: -1).

vera doctor --probe surfaces it as a probe-tiny-inference failure, with probe-reranker-session still green. Reproduced deterministically on three consecutive runs.

The user-visible effect is worse than the probe suggests. Searches do not fail. They log

reranker unavailable, returning unreranked results

and return fusion order, so the CoreML backend silently loses cross-encoder ranking while the command still exits 0.

Root cause

build_session in local_reranker.rs registered CoreMLExecutionProvider whenever the backend was CoreML.

#25 established that no prebuilt reranker export runs on the CoreML GPU and moved every backend onto the quantized INT8 export. The premise recorded alongside that change is that the CoreML EP can execute none of those ops, so ORT partitions zero nodes and falls back to CPU on its own, and vera doctor's probe-reranker-coreml-cpu warning was added on that basis.

That premise does not hold here. The failing node name carries a CoreMLExecutionProvider_ prefix and a subgraph index, so ORT did assign a fused subgraph to CoreML. Partitioning and CoreML model compilation both succeed, which is why probe-reranker-session passes; only the prediction fails.

The existing CPU retry cannot catch this. It wraps session construction only, and construction succeeds, so inference runs with no fallback behind it.

This is not an ORT version drift: ORT_VERSION is 1.24.4 at v0.12.13, at #25's merge commit, and at v1.0.0.

Fix

Select the CPU provider for the reranker up front, through a small mapping function placed next to RERANKER_ONNX_FILE where the reranker-asset reasoning already lives. This makes the behaviour that probe-reranker-coreml-cpu and docs/troubleshooting.md already describe actually true.

Embedding still registers CoreML. Only the reranker moves to CPU, which is what the quantized INT8 export is already chosen for.

The mapping is a pure function, so the regression is unit testable without ONNX Runtime or model assets. The pre-existing test_local_reranker could not have caught this: it pins OnnxExecutionProvider::Cpu and early-returns when ORT is unavailable.

docs/troubleshooting.md is corrected to stop asserting that ORT falls back on its own.

Verification

Apple M4, macOS 26.6.1, ONNX Runtime 1.24.4, backend onnx-jina-coreml, index of this repository (375 files, 4790 chunks). Same index and query for both runs.

released v1.0.0 this branch
probe-tiny-inference fail ok
probe-provider-confirmation skipped ok
search reranker unavailable, returning unreranked results reranks normally
[timing] reranking 166ms (failure path) 6418ms

cargo fmt --check clean. cargo clippy -p vera-core --lib introduces no new warnings; the 5 reported are pre-existing (pip_package_for_ep, CUDA_RUNTIME_LIBRARY_PREFIXES, parse_cuda_major_from_runtime_library_entry, an unused import, an unused variable). New test and the local_models suite pass.

Note

Unrelated to this change and present on both binaries against the same index: vector search failed, falling back to BM25-only results with storage error: vector search failed. Not addressed here.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reranker reliability on Apple Silicon by explicitly using CPU execution when CoreML is selected.
    • Added diagnostics for cases where CoreML accepts part of the workload but fails during inference.
  • Documentation

    • Updated troubleshooting guidance to explain CoreML reranker behavior and the resulting diagnostic warning.

The reranker session registered the CoreML execution provider whenever the
backend was onnx-jina-coreml. No prebuilt reranker ONNX export can run on the
CoreML GPU, and the assumption behind that was that ONNX Runtime would
therefore partition zero nodes and fall back to CPU on its own.

It does not. ORT still assigns a fused subgraph to CoreML. The session builds
successfully, so the CPU retry in LocalReranker::new_with_ep never fires, and
the failure lands at inference instead:

  Non-zero status code returned while running
  ..._CoreML_..._3 node. Name:'CoreMLExecutionProvider_..._3_3'
  Status Message: Error executing model: Unable to compute the prediction
  using a neural network model (error code: -1)

In practice searches did not error out. They logged "reranker unavailable,
returning unreranked results" and returned BM25 and vector fusion order, so
the CoreML backend silently lost cross-encoder ranking while still exiting 0.
vera doctor --probe reported it as a probe-tiny-inference failure.

Select the CPU provider for the reranker up front via a small mapping
function next to RERANKER_ONNX_FILE, where the reasoning about reranker
assets already lives. This makes the behaviour that doctor's
probe-reranker-coreml-cpu warning and the troubleshooting docs already
describe actually true, and it is unit testable without model assets.

Verified on an Apple M4, macOS 26.6.1, ONNX Runtime 1.24.4, backend
onnx-jina-coreml:

  before: probe-tiny-inference fails; search logs "reranker unavailable";
          [timing] reranking: 166ms
  after:  probe-tiny-inference and probe-provider-confirmation pass;
          search reranks normally; [timing] reranking: 6418ms

Embedding still runs on CoreML; only the reranker moves to CPU.
@lemon07r

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

@cubic-dev-ai review

@lemon07r I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 3 files

Re-trigger cubic

@lemon07r

Copy link
Copy Markdown
Collaborator

Follow-up commit 9b743a2 pushed: the two stale comments (local_models/mod.rs near RERANKER_ONNX_FILE, doctor.rs probe-reranker-coreml-cpu) now describe the explicit CPU pinning via reranker_execution_provider instead of claiming ORT silently falls back on its own.

@lemon07r

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 964a6efb-40af-49a6-879c-2d47cdf6ce48

📥 Commits

Reviewing files that changed from the base of the PR and between 8c6239a and 9b743a2.

📒 Files selected for processing (4)
  • crates/vera-cli/src/commands/doctor.rs
  • crates/vera-core/src/local_models/mod.rs
  • crates/vera-core/src/retrieval/local_reranker.rs
  • docs/troubleshooting.md

Included review availability: Your plan provides up to 3 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The reranker now maps CoreML execution to CPU before session construction. Other providers remain unchanged. Tests cover the mapping, and diagnostic and troubleshooting text describe CoreML inference behavior.

Changes

CoreML reranker execution

Layer / File(s) Summary
Reranker provider mapping
crates/vera-core/src/local_models/mod.rs
reranker_execution_provider maps CoreML to CPU and preserves CPU, CUDA, ROCm, DirectML, and OpenVINO. Tests verify both behaviors.
Session integration and diagnostics
crates/vera-core/src/retrieval/local_reranker.rs, crates/vera-cli/src/commands/doctor.rs, docs/troubleshooting.md
Reranker session construction applies the provider mapping. Diagnostics and troubleshooting guidance describe explicit CPU execution and CoreML inference failures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 9b743

The change makes CoreML reranking use the CPU provider while preserving CoreML for embeddings, restoring reranked search results on the affected backend. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: lemon07r

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: running the reranker on CPU when CoreML is selected.
Linked Issues check ✅ Passed The changes explicitly map CoreML reranker execution to CPU, preserve other providers, and update related tests and documentation [#41].
Out of Scope Changes check ✅ Passed All code, test, comment, and documentation changes directly support the CoreML reranker CPU execution fix [#41].
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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.

CoreML backend: reranker fails at inference and searches silently return unreranked results

2 participants