Skip to content

feat: support HF_ENDPOINT environment variable for model downloads - #667

Open
pangwangshu wants to merge 6 commits into
qdrant:mainfrom
pangwangshu:copilot/find-issues-to-work-on
Open

feat: support HF_ENDPOINT environment variable for model downloads#667
pangwangshu wants to merge 6 commits into
qdrant:mainfrom
pangwangshu:copilot/find-issues-to-work-on

Conversation

@pangwangshu

Copy link
Copy Markdown

Summary

Closes #502. Adds support for the HF_ENDPOINT environment variable so
fastembed can download models from a custom/mirrored Hugging Face
endpoint (e.g. a Nexus repository, per the linked feature request).

  • ModelManagement.download_files_from_huggingface now reads HF_ENDPOINT
    from the environment and forwards it to snapshot_download. For
    model_info and list_repo_tree, forwarding is done via an HfApi(endpoint=...)
    instance rather than the module-level functions, since those are bound
    methods of a default HfApi() singleton that doesn't accept an endpoint
    kwarg directly.
  • When HF_ENDPOINT is unset, behavior is unchanged (endpoint resolves to
    huggingface_hub's default).

Test plan

  • Added test_hf_endpoint_forwarded_to_hub_calls / test_no_hf_endpoint_no_extra_kwarg
    in tests/test_common.py, using autospec=True so the mocks are
    checked against the real huggingface_hub call signatures.
  • pytest tests/test_common.py passes.
  • ruff check / ruff format --check clean on changed files.
  • Manually verified against real huggingface_hub (v1.26.1) that
    HfApi(endpoint=...).model_info() succeeds where the naive
    model_info(..., endpoint=...) approach raises TypeError.

Copilot AI and others added 3 commits August 7, 2026 05:51
…d_files_from_huggingface

Co-authored-by: pangwangshu <1851324+pangwangshu@users.noreply.github.com>
Co-authored-by: pangwangshu <1851324+pangwangshu@users.noreply.github.com>
…ctions

model_info and list_repo_tree, as imported from huggingface_hub, are bound
methods of a module-level HfApi() singleton and don't accept an `endpoint`
kwarg — only snapshot_download does. Passing `endpoint=` to them raised
TypeError at runtime whenever HF_ENDPOINT was set. Construct an HfApi
instance with the endpoint instead, and use autospec=True in the tests so
mocks are checked against the real huggingface_hub signatures.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3015671f-6874-4a10-8f9f-740b4a1b9ec7

📥 Commits

Reviewing files that changed from the base of the PR and between c9fb9e3 and e04e5f4.

📒 Files selected for processing (1)
  • tests/test_common.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

ModelManagement.download_files_from_huggingface now resolves HF_ENDPOINT, creates an endpoint-specific HfApi, and passes the endpoint to metadata, repository-tree, local-only, and regular snapshot operations. Tests cover endpoint precedence, empty and unset values, local-only propagation, mocked call signatures, and right- and left-padding behavior in last_token_pooling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to e04e5

The change is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Suggested reviewers: joein

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The pull request adds last_token_pooling tests, which are unrelated to the linked HF_ENDPOINT feature [#502]. Move the unrelated last_token_pooling tests to a separate pull request or link an issue that requires them.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes support for the HF_ENDPOINT environment variable for model downloads.
Description check ✅ Passed The description explains the HF_ENDPOINT feature, implementation approach, and related tests.
Linked Issues check ✅ Passed The changes implement HF_ENDPOINT support for custom Hugging Face endpoints and preserve default behavior when unset [#502].
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/test_common.py (1)

64-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the local-only endpoint path.

The helper always uses the default local_files_only=False. The tests therefore do not execute the local-only snapshot_download call, so a regression in that endpoint forwarding would pass this suite.

Add a helper parameter and a test that invokes local_files_only=True.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_common.py` around lines 64 - 68, Add a local_files_only parameter
to the relevant test helper around
ModelManagement.download_files_from_huggingface, forward it to the download
call, and add coverage invoking the helper with local_files_only=True. Preserve
the existing default behavior for tests that omit the parameter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fastembed/common/model_management.py`:
- Around line 218-219: Normalize the HF_ENDPOINT value in the model-management
flow before constructing HfApi or calling snapshot_download: treat an empty
environment value as unset and pass None or omit the endpoint, or raise a clear
configuration error. Update the hf_endpoint handling adjacent to
HfApi(endpoint=hf_endpoint), preserving configured non-empty endpoints.
- Around line 235-236: Remove endpoint from kwargs before forwarding download
arguments in the model download flow, resolve that value once, and reuse it
consistently when constructing HfApi and in both snapshot_download calls.
Preserve other kwargs unchanged to avoid passing endpoint twice.

In `@tests/test_common.py`:
- Around line 37-55: Update _run_download_with_mocks to use the autospecced
mock_hf_api_cls.return_value directly instead of replacing it with a plain
MagicMock via return_value. Configure model_info and list_repo_tree on that
autospecced instance while preserving the HfApi patch with autospec=True, so
invalid method calls still raise TypeError.

---

Nitpick comments:
In `@tests/test_common.py`:
- Around line 64-68: Add a local_files_only parameter to the relevant test
helper around ModelManagement.download_files_from_huggingface, forward it to the
download call, and add coverage invoking the helper with local_files_only=True.
Preserve the existing default behavior for tests that omit the parameter.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c06c512-85b0-437b-8f1d-f040eb518d79

📥 Commits

Reviewing files that changed from the base of the PR and between f613647 and 1c05361.

📒 Files selected for processing (2)
  • fastembed/common/model_management.py
  • tests/test_common.py

Comment thread fastembed/common/model_management.py Outdated
Comment thread fastembed/common/model_management.py
Comment thread tests/test_common.py Outdated
Addresses CodeRabbit review on PR qdrant#667:
- Treat an empty-string HF_ENDPOINT as unset instead of forwarding "" as
  the endpoint.
- Pop endpoint out of kwargs before resolving hf_endpoint, so callers who
  pass endpoint= directly no longer collide with the explicit endpoint=
  kwarg passed to snapshot_download.
- Stop overwriting the autospecced HfApi instance mock with a plain
  MagicMock, so method calls on it stay signature-checked.
- Add test coverage for the above plus the local_files_only download path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_common.py`:
- Line 48: Update the environment patching setup in the test around patch.dict
so HF_ENDPOINT is removed whenever it is absent from extra_env, while preserving
any explicitly provided endpoint value. Ensure the unset-endpoint test does not
inherit HF_ENDPOINT from the runner environment.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cf4a5dc1-5100-41db-a06c-b4c9def58256

📥 Commits

Reviewing files that changed from the base of the PR and between 1c05361 and b831744.

📒 Files selected for processing (2)
  • fastembed/common/model_management.py
  • tests/test_common.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • fastembed/common/model_management.py

Comment thread tests/test_common.py
pangwangshu and others added 2 commits August 7, 2026 01:17
Addresses CodeRabbit review on PR qdrant#667. patch.dict(os.environ, extra_env)
only adds/overrides keys, it never removes ones already present. If
HF_ENDPOINT happens to be set in the runner's environment, tests calling
_run_download_with_mocks with an extra_env that omits it would silently
inherit that value instead of exercising the unset case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Both branches added independent tests to the same file; kept both
sets of imports and test functions.
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.

[Feature]: support HF_ENDPOINT environment variable

2 participants