From 89c9f0c308c7186ae2a53a3bd75d0eb02f859be3 Mon Sep 17 00:00:00 2001 From: Pringled Date: Fri, 18 Sep 2026 08:06:02 +0200 Subject: [PATCH 1/3] fix: Hide Hugging Face unauthenticated-request warning on model download --- src/semble/index/dense.py | 7 +++++++ tests/test_search.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/semble/index/dense.py b/src/semble/index/dense.py index f7f91e2a..1ce7e420 100644 --- a/src/semble/index/dense.py +++ b/src/semble/index/dense.py @@ -1,5 +1,6 @@ from __future__ import annotations +import logging from functools import cache from pathlib import Path @@ -15,11 +16,17 @@ from semble.utils import resolve_model_name +def _drop_hf_token_warning(record: logging.LogRecord) -> bool: + """Drop the Hub's unauthenticated-request warning; the public model downloads fine without a token.""" + return "HF_TOKEN" not in record.getMessage() + + @cache def _load_cached(model_path: str) -> StaticModel: """Load a model and cache it, but only after the path resolves.""" # Disable HF progress bars since the model is loaded silently in the background during indexing. disable_progress_bars() + logging.getLogger("huggingface_hub.utils._http").addFilter(_drop_hf_token_warning) try: try: model = StaticModel.from_pretrained(model_path, force_download=False) diff --git a/tests/test_search.py b/tests/test_search.py index fa3d3bd1..b4f667e8 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,3 +1,4 @@ +import logging from typing import Any from unittest.mock import MagicMock, call, patch @@ -159,6 +160,21 @@ def test_load_model(model_path: str | None, expected_call_arg: str, incomplete_c assert mock_fp.call_args_list == expected_calls +@pytest.mark.parametrize( + ("message", "shown"), + [ + ("You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN.", False), + ("Rate limited. Waiting 1s before retry [Retry 1/5].", True), + ], +) +def test_load_model_hides_only_hf_token_warning(caplog: pytest.LogCaptureFixture, message: str, shown: bool) -> None: + """Loading the model hides the Hub's HF_TOKEN nag but keeps other Hub warnings.""" + with patch("semble.index.dense.StaticModel.from_pretrained"): + load_model(f"filter/test-{shown}") + logging.getLogger("huggingface_hub.utils._http").warning(message) + assert (message in caplog.text) is shown + + def test_embed_chunks_empty_returns_empty_array(mock_model: Any) -> None: """embed_chunks with an empty list returns a (0, 256) float32 array.""" result = embed_chunks(mock_model, []) From 38ec2127885eea939d57d287105bb6a92c902a09 Mon Sep 17 00:00:00 2001 From: Pringled Date: Fri, 18 Sep 2026 08:12:12 +0200 Subject: [PATCH 2/3] test: Use exact Hub warning text in HF_TOKEN filter test --- tests/test_search.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_search.py b/tests/test_search.py index b4f667e8..ecad16df 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -163,7 +163,11 @@ def test_load_model(model_path: str | None, expected_call_arg: str, incomplete_c @pytest.mark.parametrize( ("message", "shown"), [ - ("You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN.", False), + ( + "Warning: You are sending unauthenticated requests to the HF Hub. " + "Please set a HF_TOKEN to enable higher rate limits and faster downloads.", + False, + ), ("Rate limited. Waiting 1s before retry [Retry 1/5].", True), ], ) From 1b1a9393a3bdc6f9869fc79a259a7712c39e7deb Mon Sep 17 00:00:00 2001 From: Pringled Date: Fri, 18 Sep 2026 08:20:42 +0200 Subject: [PATCH 3/3] fix: Narrow HF warning filter to the unauthenticated-request message --- src/semble/index/dense.py | 6 +++--- tests/test_search.py | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/semble/index/dense.py b/src/semble/index/dense.py index 1ce7e420..ada1f875 100644 --- a/src/semble/index/dense.py +++ b/src/semble/index/dense.py @@ -16,9 +16,9 @@ from semble.utils import resolve_model_name -def _drop_hf_token_warning(record: logging.LogRecord) -> bool: +def _drop_unauthenticated_warning(record: logging.LogRecord) -> bool: """Drop the Hub's unauthenticated-request warning; the public model downloads fine without a token.""" - return "HF_TOKEN" not in record.getMessage() + return "unauthenticated requests" not in record.getMessage() @cache @@ -26,7 +26,7 @@ def _load_cached(model_path: str) -> StaticModel: """Load a model and cache it, but only after the path resolves.""" # Disable HF progress bars since the model is loaded silently in the background during indexing. disable_progress_bars() - logging.getLogger("huggingface_hub.utils._http").addFilter(_drop_hf_token_warning) + logging.getLogger("huggingface_hub.utils._http").addFilter(_drop_unauthenticated_warning) try: try: model = StaticModel.from_pretrained(model_path, force_download=False) diff --git a/tests/test_search.py b/tests/test_search.py index ecad16df..d17a7d8e 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -169,10 +169,13 @@ def test_load_model(model_path: str | None, expected_call_arg: str, incomplete_c False, ), ("Rate limited. Waiting 1s before retry [Retry 1/5].", True), + ("Your HF_TOKEN expires soon.", True), ], ) -def test_load_model_hides_only_hf_token_warning(caplog: pytest.LogCaptureFixture, message: str, shown: bool) -> None: - """Loading the model hides the Hub's HF_TOKEN nag but keeps other Hub warnings.""" +def test_load_model_hides_only_unauthenticated_warning( + caplog: pytest.LogCaptureFixture, message: str, shown: bool +) -> None: + """Loading the model hides the Hub's unauthenticated-request nag but keeps other Hub warnings.""" with patch("semble.index.dense.StaticModel.from_pretrained"): load_model(f"filter/test-{shown}") logging.getLogger("huggingface_hub.utils._http").warning(message)