[inference] Add DeepInfra sentence-similarity provider helper - #2369
[inference] Add DeepInfra sentence-similarity provider helper#2369ovuruska wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 999bc5e. Configure here.
| const { source_sentence, sentences } = params.args.inputs as { source_sentence: string; sentences: string[] }; | ||
| return { | ||
| ...(params.args.parameters as Record<string, unknown> | undefined), | ||
| input: [source_sentence, ...sentences], |
There was a problem hiding this comment.
Snippet payload crashes on string inputs
Medium Severity
preparePayload destructures inputs as { source_sentence, sentences } and spreads sentences. Default snippet generation passes getModelInputSnippet as a JSON string, so sentences is undefined and spreading it throws. That breaks DeepInfra sentence-similarity snippet generation (and any caller that does not pass a structured object).
Reviewed by Cursor Bugbot for commit 999bc5e. Configure here.
Add DeepInfraSentenceSimilarityTask alongside the existing feature-extraction helper (does not replace it). DeepInfra has no native sentence-similarity endpoint, so we embed the source sentence and the comparison sentences in one OpenAI-compatible embeddings request and compute cosine similarities from the returned vectors, ordering by the response index. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
999bc5e to
6ec5527
Compare


What
Adds a
sentence-similaritytask helper for the DeepInfra inference provider.DeepInfra serves its embedding models (bge, e5, gte, sentence-transformers, nvidia Nemotron-Embed, etc.) through an OpenAI-compatible
POST /v1/openai/embeddingsendpoint. Many of these repos carrypipeline_tag: sentence-similarityon the Hub, so a DeepInfra mapping can only be registered under thesentence-similaritytask. Until now there was nosentence-similarityhelper for any third-party provider (onlyhf-inference), so those mappings could not route.How
DeepInfraSentenceSimilarityTask:v1/openai/embeddings[source_sentence, ...sentences]in a single request (source first);modelis applied last so caller parameters cannot override the mapped provider model.index; item 0 is the source, items 1.. are the comparison sentences. We compute the cosine similarity of each sentence against the source and returnnumber[], matchingSentenceSimilarityOutput. This mirrors the task definition ("by comparing their embeddings").Registered under the
deepinfraprovider ingetProviderHelper.Tests
packages/inference/test/deepinfra-sentence-similarity.spec.ts— offline unit tests: route, payload ordering, cosine computation, responseindexordering, malformed-response handling (5 tests, all passing).InferenceClient.spec.ts.Validation:
vitest run(unit) ✅,tsc --noEmit✅,prettier --check✅,eslint✅.Note
Low Risk
Additive provider task with local similarity math and tests; no changes to auth or existing DeepInfra task behavior beyond a minor formatting tweak.
Overview
Adds DeepInfra routing for the
sentence-similaritytask so Hub embedding models mapped to DeepInfra can be used withInferenceClient.sentenceSimilarity.DeepInfraSentenceSimilarityTaskcallsv1/openai/embeddingswith[source_sentence, ...sentences]in one request, sorts embeddings by APIindex, and returns cosine similarities vs. the source asnumber[](same shape asSentenceSimilarityOutput). The helper is registered on thedeepinfraprovider ingetProviderHelper.Coverage includes a dedicated unit spec (
deepinfra-sentence-similarity.spec.ts) and a DeepInfra integration case inInferenceClient.spec.ts(e.g.BAAI/bge-m3).Reviewed by Cursor Bugbot for commit 999bc5e. Bugbot is set up for automated code reviews on this repo. Configure here.