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(library): don't quarantine healthy FAISS index when embedding provider is down (#4512)

LearningCircuit6762ccfaf523
diff --git a/changelog.d/4512.bugfix.md b/changelog.d/4512.bugfix.md
new file mode 100644
index 0000000000..72cb19b946
--- /dev/null
+++ b/changelog.d/4512.bugfix.md
@@ -0,0 +1 @@
+A temporarily unreachable embedding provider (e.g. Ollama not running) no longer quarantines a healthy collection index and silently replaces it with an empty one; the search now fails with a clear provider error and the index survives untouched.
diff --git a/src/local_deep_research/research_library/services/library_rag_service.py b/src/local_deep_research/research_library/services/library_rag_service.py
index 07509629ab..a15948006d 100644
--- a/src/local_deep_research/research_library/services/library_rag_service.py
+++ b/src/local_deep_research/research_library/services/library_rag_service.py
@@ -722,15 +722,22 @@ class LibraryRAGService:
)
self._quarantine_corrupt_index(index_path, reason)
else:
- try:
- # Check for embedding dimension mismatch before loading
- current_dim = len(
- self.embedding_manager.embeddings.embed_query(
- "dimension_check"
- )
+ # Probe the embedding model OUTSIDE the quarantine
+ # try-block: embed_query fails when the embedding
+ # provider is unreachable (e.g. Ollama down), which
+ # says nothing about the index files. Inside the try
+ # it would quarantine a healthy index and silently
+ # replace it with an empty one; here it propagates a
+ # clear provider error instead.
+ current_dim = len(
+ self.embedding_manager.embeddings.embed_query(
+ "dimension_check"
)
- stored_dim = rag_index.embedding_dimension
+ )
+ stored_dim = rag_index.embedding_dimension
+ try:
+ # Check for embedding dimension mismatch before loading
if stored_dim and current_dim != stored_dim:
logger.warning(
f"Embedding dimension mismatch detected! "
diff --git a/tests/research_library/services/test_library_rag_service_coverage.py b/tests/research_library/services/test_library_rag_service_coverage.py
index e90f37138f..2826452e08 100644
--- a/tests/research_library/services/test_library_rag_service_coverage.py
+++ b/tests/research_library/services/test_library_rag_service_coverage.py
@@ -550,6 +550,45 @@ class TestLoadOrCreateFaissIndex:
# Should fall through and create new index
mock_faiss_cls.assert_called_once()
+ @patch(f"{_MOD}.FAISS")
+ @patch(f"{_MOD}.InMemoryDocstore")
+ @patch(f"{_MOD}.IndexFlatIP")
+ def test_embedding_provider_failure_raises_and_preserves_index(
+ self, mock_flat_ip, mock_docstore, mock_faiss_cls, tmp_path
+ ):
+ """When the embedding provider is unreachable (e.g. Ollama down),
+ the dimension-check embed_query raises. That says nothing about
+ the index files, so the error must propagate WITHOUT quarantining
+ the healthy index or replacing it with an empty one.
+ """
+ svc = _make_service()
+ svc.embedding_manager = MagicMock()
+ svc.embedding_manager.embeddings.embed_query.side_effect = (
+ ConnectionError("Ollama connection refused")
+ )
+ svc.integrity_manager = MagicMock()
+ svc.integrity_manager.verify_file.return_value = (True, None)
+
+ idx_path = tmp_path / "healthy.faiss"
+ pkl_path = tmp_path / "healthy.pkl"
+ idx_path.write_bytes(b"faiss-bytes")
+ pkl_path.write_bytes(b"pkl-bytes")
+
+ rag_idx = self._make_rag_index(dim=384)
+ rag_idx.index_path = str(idx_path)
+ self._patch_get_or_create(svc, rag_idx)
+
+ with pytest.raises(ConnectionError, match="Ollama"):
+ svc.load_or_create_faiss_index("coll-1")
+
+ # The healthy index files must be untouched — not quarantined
+ assert idx_path.read_bytes() == b"faiss-bytes"
+ assert pkl_path.read_bytes() == b"pkl-bytes"
+ assert list(tmp_path.glob("*.corrupt-*")) == []
+ # And no empty replacement index was created
+ mock_faiss_cls.load_local.assert_not_called()
+ mock_faiss_cls.assert_not_called()
+
@patch(f"{_MOD}.FAISS")
@patch(f"{_MOD}.InMemoryDocstore")
@patch(f"{_MOD}.IndexFlatIP")