Skip to content

fix(huggingface_api): serialize raw_scores in HuggingFaceTEIRanker - #3809

Closed
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/tei-ranker-raw-scores-serde
Closed

fix(huggingface_api): serialize raw_scores in HuggingFaceTEIRanker#3809
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/tei-ranker-raw-scores-serde

Conversation

@pcbeingused333

Copy link
Copy Markdown

Related Issues

  • No issue; found while auditing to_dict against __init__ across the integrations.

Proposed Changes:

HuggingFaceTEIRanker.__init__ accepts raw_scores, stores it, and puts it directly into the request payload — on both paths:

payload: dict[str, Any] = {"query": query, "texts": texts, "raw_scores": self.raw_scores}

to_dict does not serialize it, so a ranker built with raw_scores=True comes back from from_dict with the False default. Save a pipeline containing that ranker, reload it, and it silently stops asking the TEI endpoint for raw relevance scores — the request body changes, and nothing in the serialized dict shows why.

Everything else __init__ takes (url, top_k, timeout, token, max_retries, retry_status_codes) is already serialized; raw_scores is the only one missing.

from_dict needed no change — default_from_dict passes init_parameters through to __init__.

How did you test it?

  • New unit test test_raw_scores_survives_a_serialization_round_trip: builds the ranker with raw_scores=True, runs it through to_dict then from_dict, and asserts the flag is still True.
  • I checked it is not vacuous: with ranker.py reverted to main it fails with assert False is True on the restored component — the round trip losing the flag, not an incidental assertion mismatch.
  • hatch run test:pytest tests/test_ranker.py — 16 passed.
  • hatch run test:types clean (10 source files), hatch run fmt-check clean.

Notes for the reviewer

The existing test_to_dict asserts key by key rather than comparing the whole dict, so it did not need changing — which is also why the gap survived: a full-dict assertion would have flagged the missing key when raw_scores was added.

This came out of a sweep comparing every component's to_dict against its __init__ signature. It found the same class of gap in a few other packages, and since each integration ships separately I am opening those as their own PRs rather than one cross-package change.

I used an AI assistant while writing this change. I have reviewed it, reproduced the behaviour, and run the tests.

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title.
  • I have documented my code.
  • I have run pre-commit hooks and fixed any issue.

to_dict left raw_scores out, so a ranker built with raw_scores=True came back
from from_dict with it at False. The flag goes straight into the request
payload sent to the TEI endpoint, on both the sync and the async path, so a
pipeline saved and reloaded stops asking the service for raw relevance
scores.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner August 18, 2026 00:19
@pcbeingused333
pcbeingused333 requested review from anakin87 and removed request for a team August 18, 2026 00:19
@github-actions

Copy link
Copy Markdown
Contributor

Hi @pcbeingused333, thanks for your interest in contributing to Haystack! 🙏

⚠️ You currently have 3 open pull requests in this repository (#3808, #3790 and this one). Our review capacity is limited, so please hold off opening more PRs until we've had a chance to review your first 2 open PRs. This helps us give each contribution the attention it deserves. Thank you!

This is an automated message to help us keep the review queue healthy.

@github-actions

Copy link
Copy Markdown
Contributor

Heads-up for maintainers

This PR is from a fork and touches integrations whose integration tests require API keys.
Those tests are skipped in CI because fork PRs don't have access to repo secrets for security reasons.

Affected integrations:

  • huggingface_api

Please run the integration tests locally (hatch run test:integration inside each folder) before approving.

@github-actions github-actions Bot added the type:documentation Improvements or additions to documentation label Aug 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (huggingface_api)

This PR does not seem to contain any modification to coverable code.

@pcbeingused333

Copy link
Copy Markdown
Author

Folding this into #3808 together with the same fix in TransformersZeroShotTextRouter and RagasEvaluator — it is one class of bug from one sweep, and it reads better reviewed as a whole than as three near-identical PRs. The commit for raw_scores is carried over unchanged; closing here to keep the review in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:huggingface-api type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant