fix(huggingface_api): serialize raw_scores in HuggingFaceTEIRanker - #3809
fix(huggingface_api): serialize raw_scores in HuggingFaceTEIRanker#3809pcbeingused333 wants to merge 1 commit into
Conversation
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.
|
Hi @pcbeingused333, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
|
Folding this into #3808 together with the same fix in |
Related Issues
to_dictagainst__init__across the integrations.Proposed Changes:
HuggingFaceTEIRanker.__init__acceptsraw_scores, stores it, and puts it directly into the request payload — on both paths:to_dictdoes not serialize it, so a ranker built withraw_scores=Truecomes back fromfrom_dictwith theFalsedefault. 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_scoresis the only one missing.from_dictneeded no change —default_from_dictpassesinit_parametersthrough to__init__.How did you test it?
test_raw_scores_survives_a_serialization_round_trip: builds the ranker withraw_scores=True, runs it throughto_dictthenfrom_dict, and asserts the flag is stillTrue.ranker.pyreverted tomainit fails withassert False is Trueon 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:typesclean (10 source files),hatch run fmt-checkclean.Notes for the reviewer
The existing
test_to_dictasserts 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 whenraw_scoreswas added.This came out of a sweep comparing every component's
to_dictagainst 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