Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(search): preserve semantic ranking precision (#5448)

Ziyang Guo09d2413d0468
diff --git a/changelog.d/+unified-search-similarity-precision.bugfix.md b/changelog.d/+unified-search-similarity-precision.bugfix.md
new file mode 100644
index 0000000000..e376f45710
--- /dev/null
+++ b/changelog.d/+unified-search-similarity-precision.bugfix.md
@@ -0,0 +1 @@
+Sort Unified Search semantic results using full similarity precision before rounding response values.
diff --git a/src/local_deep_research/web/routes/unified_search_routes.py b/src/local_deep_research/web/routes/unified_search_routes.py
index ab7b8e058a..118fa100a0 100644
--- a/src/local_deep_research/web/routes/unified_search_routes.py
+++ b/src/local_deep_research/web/routes/unified_search_routes.py
@@ -411,7 +411,7 @@ def semantic_search():
"content_preview": (r.get("snippet", "") or "")[
:PREVIEW_LEN
],
- "similarity": round(float(score), 3),
+ "similarity": float(score),
}
)
@@ -463,6 +463,7 @@ def semantic_search():
hit["url"] = _document_url(
source_type_name, hit["id"], research_id
)
+ hit["similarity"] = round(hit["similarity"], 3)
results.append(hit)
if len(results) >= limit:
break
diff --git a/tests/web/routes/test_unified_search_routes.py b/tests/web/routes/test_unified_search_routes.py
index 9e902a0e76..865fa487de 100644
--- a/tests/web/routes/test_unified_search_routes.py
+++ b/tests/web/routes/test_unified_search_routes.py
@@ -506,6 +506,43 @@ class TestSemanticSearch:
assert results[1]["url"] == "/results/res-9"
assert results[1]["source_type"] == "research_report"
+ def test_sorts_by_full_precision_before_rounding_response(self):
+ collections = [
+ ("lib-1", "Library", "default_library"),
+ ("notes-1", "Notes", "notes"),
+ ]
+ lower_score = {
+ "relevance_score": 0.90041,
+ "title": "Lower score",
+ "snippet": "first collection",
+ "metadata": {"document_id": "lower"},
+ }
+ higher_score = {
+ "relevance_score": 0.90049,
+ "title": "Higher score",
+ "snippet": "second collection",
+ "metadata": {"document_id": "higher"},
+ }
+
+ (payload, status), _, _ = self._call(
+ collections=collections,
+ engine_side_effect=[[lower_score], [higher_score]],
+ doc_rows=[
+ ("lower", "note", None),
+ ("higher", "note", None),
+ ],
+ )
+
+ assert status == 200
+ assert [result["id"] for result in payload["results"]] == [
+ "higher",
+ "lower",
+ ]
+ assert [result["similarity"] for result in payload["results"]] == [
+ 0.9,
+ 0.9,
+ ]
+
def test_faiss_orphan_hits_are_dropped(self):
# A hit whose Document row is gone (deleted doc, lingering
# vectors) must not surface as a dead link.