Skip to content

Conversation

@atopx
Copy link
Contributor

@atopx atopx commented May 20, 2025

Add HuggingFace API (text-embeddings-inference for rerank model)

Proposed Changes:

How did you test it?

Unit tests have been added in test/components/rankers/test_hugging_face_api.py

Notes for the reviewer

Running unit tests requires setting up the text-embeddings-inference service and running the reranker model BAAI/bge-reranker-v2-m3

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@atopx atopx requested a review from a team as a code owner May 20, 2025 14:12
@atopx atopx requested review from vblagoje and removed request for a team May 20, 2025 14:12
@github-actions github-actions bot added topic:tests topic:DX Developer Experience type:documentation Improvements on the docs labels May 20, 2025
@CLAassistant
Copy link

CLAassistant commented May 20, 2025

CLA assistant check
All committers have signed the CLA.

@vblagoje
Copy link
Member

Hey @atopx thanks for your effort, have a look at contributing guide - you need to add reno note to this PR. We use it to generate beautiful release notes for Haystack 🙏

@atopx atopx requested a review from a team as a code owner May 21, 2025 12:20
@atopx atopx requested review from dfokina and removed request for a team May 21, 2025 12:20
@atopx
Copy link
Contributor Author

atopx commented May 21, 2025

Hey @atopx thanks for your effort, have a look at contributing guide - you need to add reno note to this PR. We use it to generate beautiful release notes for Haystack 🙏

reno note added: releasenotes/notes/add-huggingface-api-text-embeddings-inference-to-component-rankers-0e3f54e523e42141.yaml

atopx and others added 2 commits May 21, 2025 20:52
@vblagoje
Copy link
Member

Hey @atopx this looks good. Please note that we can't serialize tokens directly as that is sensitive info and we have to use our Secret API This will take you 5 min to update 🙏

@anakin87 just to confirm, we don't have these HF remote rankers already somewhere? Is this a good direction in general. TIA

atopx and others added 2 commits May 23, 2025 16:29
1. `hugging_face_api.HuggingFaceAPIRanker` rename to `hugging_face_tei.HuggingFaceAPIRanker`
2. HuggingFaceAPIRanker: use our Secret API for token
3. add the missing modules for `docs/pydoc/config/rankers_api.yml`
4. added function `async_request_with_retry` for `haystack/utils/requests_utils.py` and added unittest on `test/utils/test_requests_utils.py`
4. HuggingFaceAPIRanker: refactor the retry function to support configuration based on attempts and status code.
5. HuggingFaceAPIRanker: refactor the test into unit tests using mocks
@atopx atopx requested a review from anakin87 May 23, 2025 10:31
Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

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

Thanks for your work!
I found some opportunities for further improvement.

@dfokina could you please take a look at the docstrings?

atopx and others added 2 commits May 23, 2025 19:19
- Force keyword-only arguments in __init__ method by adding *,
- Clarify token docstring that it's not always required
- Copy documents to avoid modifying original objects
- Remove test file from slow workflow
- Add monkeypatch eånvironment variable cleanup in tests
- Fix missing module in rankers_api.yml and sort modules alphabetically
- Remove unnecessary test info from release notes
@atopx atopx requested a review from anakin87 May 23, 2025 11:20
@coveralls
Copy link
Collaborator

coveralls commented May 23, 2025

Pull Request Test Coverage Report for Build 15270742072

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 90.374%

Files with Coverage Reduction New Missed Lines %
components/rankers/init.py 2 46.15%
Totals Coverage Status
Change from base Build 15269350331: 0.2%
Covered Lines: 11491
Relevant Lines: 12715

💛 - Coveralls

@anakin87 anakin87 self-assigned this May 23, 2025
atopx and others added 3 commits May 23, 2025 21:06
- "None" of "Optional[Secret]" has no attribute "resolve_value"
- run/run_async: too many parameters
Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

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

This PR looks in a good state.

I would like to do some local tests (and refine the docstrings). I think I can do that next week.

@atopx, in the meantime, thanks for all the good work!

Copy link
Contributor

@dfokina dfokina left a comment

Choose a reason for hiding this comment

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

Leaving some suggestions from the writing perspective.

atopx and others added 2 commits May 25, 2025 13:00
…Ranker, improve the parameter descriptions, ensure consistency and clarity. Add error handling information to enhance the readability of the API response.
@atopx
Copy link
Contributor Author

atopx commented May 25, 2025

Leaving some suggestions from the writing perspective.

Thank you for pointing that out!

@atopx atopx requested a review from dfokina May 25, 2025 05:04
@anakin87
Copy link
Member

In e80f814, I made some minor refinements, mostly to make it clear that this component works both with:

  • self-hosted TEI service
  • Hugging Face Inference Endpoints

(I also tried it manually).

@dfokina could you take a final look at docstrings after my last changes?

Copy link
Contributor

@dfokina dfokina left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

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

@atopx thanks for this good work! 🥳

I'm merging this PR now...

@anakin87 anakin87 merged commit 3deaa20 into deepset-ai:main May 27, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:CI topic:DX Developer Experience topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants