Skip to content

[inference] Add DeepInfra sentence-similarity provider helper - #2369

Draft
ovuruska wants to merge 1 commit into
huggingface:mainfrom
ovuruska:deepinfra-sentence-similarity
Draft

[inference] Add DeepInfra sentence-similarity provider helper#2369
ovuruska wants to merge 1 commit into
huggingface:mainfrom
ovuruska:deepinfra-sentence-similarity

Conversation

@ovuruska

@ovuruska ovuruska commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What

Adds a sentence-similarity task 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/embeddings endpoint. Many of these repos carry pipeline_tag: sentence-similarity on the Hub, so a DeepInfra mapping can only be registered under the sentence-similarity task. Until now there was no sentence-similarity helper for any third-party provider (only hf-inference), so those mappings could not route.

How

DeepInfraSentenceSimilarityTask:

  • routev1/openai/embeddings
  • payload → embeds [source_sentence, ...sentences] in a single request (source first); model is applied last so caller parameters cannot override the mapped provider model.
  • response → the embeddings preserve request order via index; item 0 is the source, items 1.. are the comparison sentences. We compute the cosine similarity of each sentence against the source and return number[], matching SentenceSimilarityOutput. This mirrors the task definition ("by comparing their embeddings").

Registered under the deepinfra provider in getProviderHelper.

Tests

  • packages/inference/test/deepinfra-sentence-similarity.spec.ts — offline unit tests: route, payload ordering, cosine computation, response index ordering, malformed-response handling (5 tests, all passing).
  • An integration test in the existing DeepInfra block of 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-similarity task so Hub embedding models mapped to DeepInfra can be used with InferenceClient.sentenceSimilarity.

DeepInfraSentenceSimilarityTask calls v1/openai/embeddings with [source_sentence, ...sentences] in one request, sorts embeddings by API index, and returns cosine similarities vs. the source as number[] (same shape as SentenceSimilarityOutput). The helper is registered on the deepinfra provider in getProviderHelper.

Coverage includes a dedicated unit spec (deepinfra-sentence-similarity.spec.ts) and a DeepInfra integration case in InferenceClient.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.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 999bc5e. Configure here.

@ovuruska
ovuruska marked this pull request as draft August 13, 2026 13:58
@ovuruska ovuruska closed this Aug 17, 2026
@ovuruska ovuruska reopened this Aug 20, 2026
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>
@ovuruska
ovuruska force-pushed the deepinfra-sentence-similarity branch from 999bc5e to 6ec5527 Compare August 21, 2026 11:56
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.

1 participant