[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2026-05-25 06:38:58 +00:00
commit b931b0039b
18 changed files with 107 additions and 74 deletions

View file

@ -26,7 +26,9 @@ def test_chunk_pages_splits_long_text():
)
assert len(chunks) > 1
for chunk in chunks:
assert _wc_counter(chunk.text) <= 55 # max + small slack from atomic split granularity
assert (
_wc_counter(chunk.text) <= 55
) # max + small slack from atomic split granularity
def test_chunk_pages_short_text_is_one_chunk():

View file

@ -82,6 +82,7 @@ def test_late_chunk_encode_returns_one_vector_per_span():
pytest.importorskip("torch")
# all-MiniLM-L6-v2 is ~80MB and embeds at 384 dims.
import os
os.environ.setdefault(
"UNSLOTH_RAG_EMBEDDING_MODEL",
"sentence-transformers/all-MiniLM-L6-v2",

View file

@ -34,10 +34,10 @@ def test_html_parser_returns_images_when_requested(tmp_path):
img_path.write_bytes(png_bytes)
html_path = tmp_path / "sample.html"
html_path.write_text(
f'<html><body><h1>Doc</h1>'
f'<p>Body text.</p>'
f"<html><body><h1>Doc</h1>"
f"<p>Body text.</p>"
f'<img src="tiny.png" alt="A tiny figure">'
f'</body></html>',
f"</body></html>",
encoding = "utf-8",
)

View file

@ -168,6 +168,6 @@ def test_text_and_image_vectors_share_dimension(monkeypatch):
image_vectors = embeddings_module.encode_images([buf.getvalue()])
text_vectors = embeddings_module.encode(["a blue square"])
assert image_vectors[0].shape == text_vectors[0].shape, (
f"text dim {text_vectors[0].shape} != image dim {image_vectors[0].shape}"
)
assert (
image_vectors[0].shape == text_vectors[0].shape
), f"text dim {text_vectors[0].shape} != image dim {image_vectors[0].shape}"

View file

@ -27,7 +27,9 @@ def test_rerank_empty_returns_empty():
@pytest.mark.server
def test_rerank_reorders_by_relevance(monkeypatch):
"""Hide the relevant chunk at the back of the input and check it bubbles up."""
monkeypatch.setenv("UNSLOTH_RAG_RERANKER_MODEL", "cross-encoder/ms-marco-MiniLM-L-6-v2")
monkeypatch.setenv(
"UNSLOTH_RAG_RERANKER_MODEL", "cross-encoder/ms-marco-MiniLM-L-6-v2"
)
from core.rag.reranker import rerank, unload
from core.rag.retrieval import Hit
@ -35,7 +37,10 @@ def test_rerank_reorders_by_relevance(monkeypatch):
(Hit("noise1", 0.0), "Cats are small carnivorous mammals."),
(Hit("noise2", 0.0), "The Eiffel Tower is in Paris, France."),
(Hit("noise3", 0.0), "Python is a programming language."),
(Hit("answer", 0.0), "The speed of light in vacuum is approximately 299792458 meters per second."),
(
Hit("answer", 0.0),
"The speed of light in vacuum is approximately 299792458 meters per second.",
),
]
try:
ranked = rerank("How fast does light travel?", pairs, top_k = 2)
@ -47,7 +52,9 @@ def test_rerank_reorders_by_relevance(monkeypatch):
@pytest.mark.server
def test_unload_clears_singleton(monkeypatch):
monkeypatch.setenv("UNSLOTH_RAG_RERANKER_MODEL", "cross-encoder/ms-marco-MiniLM-L-6-v2")
monkeypatch.setenv(
"UNSLOTH_RAG_RERANKER_MODEL", "cross-encoder/ms-marco-MiniLM-L-6-v2"
)
from core.rag import reranker
from core.rag.retrieval import Hit

View file

@ -14,8 +14,10 @@ if str(STUDIO_BACKEND) not in sys.path:
def _make_hit(chunk_id: str):
"""Minimal stand-in for retrieval.Hit — just needs .chunk_id."""
class _Hit:
pass
h = _Hit()
h.chunk_id = chunk_id
h.score = 1.0
@ -55,9 +57,11 @@ def test_kb_takes_precedence_over_thread():
captured["scope"] = scope
return []
with patch.object(tool.__import__("core.rag.retrieval", fromlist = ["retrieve_hybrid"]),
"retrieve_hybrid",
_stub_retrieve):
with patch.object(
tool.__import__("core.rag.retrieval", fromlist = ["retrieve_hybrid"]),
"retrieve_hybrid",
_stub_retrieve,
):
result = tool.search_knowledge_base(
query = "x",
scope_kb_id = "kb-abc",
@ -78,9 +82,11 @@ def test_thread_scope_when_only_thread_set():
captured["scope"] = scope
return []
with patch.object(tool.__import__("core.rag.retrieval", fromlist = ["retrieve_hybrid"]),
"retrieve_hybrid",
_stub_retrieve):
with patch.object(
tool.__import__("core.rag.retrieval", fromlist = ["retrieve_hybrid"]),
"retrieve_hybrid",
_stub_retrieve,
):
tool.search_knowledge_base(
query = "x",
scope_thread_id = "thread-xyz",
@ -137,9 +143,17 @@ def test_execute_tool_dispatches_to_search_knowledge_base():
called = {}
def _stub(*, query, top_k = None, scope_kb_id = None, scope_thread_id = None,
enable_rerank = False, reranker_model = None, default_top_k = 5,
min_score = 0.0):
def _stub(
*,
query,
top_k = None,
scope_kb_id = None,
scope_thread_id = None,
enable_rerank = False,
reranker_model = None,
default_top_k = 5,
min_score = 0.0,
):
called["query"] = query
called["top_k"] = top_k
called["scope_kb_id"] = scope_kb_id