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 support for embeddings generated by Ollama.

Daniel Petti23dc6c424315
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_local.py b/src/local_deep_research/web_search_engines/engines/search_engine_local.py
index 8a0529806c..fe262316bc 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_local.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_local.py
@@ -10,6 +10,7 @@ import logging
import re
import pickle
+from faiss import normalize_L2
from langchain_core.language_models import BaseLLM
from langchain_community.document_loaders import (
PyPDFLoader,
@@ -23,6 +24,7 @@ from langchain_community.document_loaders import (
from langchain_community.document_loaders.base import BaseLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import FAISS
+from langchain_community.vectorstores.utils import DistanceStrategy
from langchain_community.embeddings import (
HuggingFaceEmbeddings,
OllamaEmbeddings,
@@ -136,7 +138,8 @@ class LocalEmbeddingManager:
vector_store = FAISS.load_local(
str(vector_store_path),
self.embeddings,
- allow_dangerous_deserialization=True
+ allow_dangerous_deserialization=True,
+ normalize_L2=True
)
# Add this code to show document count
@@ -268,7 +271,8 @@ class LocalEmbeddingManager:
self.vector_stores[folder_hash] = FAISS.load_local(
str(index_path),
self.embeddings,
- allow_dangerous_deserialization=True
+ allow_dangerous_deserialization=True,
+ normalize_L2=True,
)
logger.info(f"Loaded index for {folder_path} from disk")
except Exception as e:
@@ -328,7 +332,11 @@ class LocalEmbeddingManager:
# Create vector store
logger.info(f"Creating vector store with {len(splits)} chunks")
- vector_store = FAISS.from_documents(splits, self.embeddings)
+ vector_store = FAISS.from_documents(
+ splits,
+ self.embeddings,
+ normalize_L2=True
+ )
# Save the vector store to disk
logger.info(f"Saving index to {index_path}")
@@ -421,7 +429,8 @@ class LocalEmbeddingManager:
self.vector_stores[folder_hash] = FAISS.load_local(
str(index_path),
self.embeddings,
- allow_dangerous_deserialization=True
+ allow_dangerous_deserialization=True,
+ nomalize_L2=True
)
except Exception as e:
logger.error(f"Error loading index for {folder_path}: {e}")
@@ -431,14 +440,14 @@ class LocalEmbeddingManager:
vector_store = self.vector_stores[folder_hash]
try:
- docs_with_scores = vector_store.similarity_search_with_score(query, k=limit)
+ docs_with_scores = (
+ vector_store.similarity_search_with_relevance_scores(
+ query,
+ k=limit
+ )
+ )
- for doc, score in docs_with_scores:
- # Convert score from distance to similarity (lower distance = higher similarity)
- # FAISS cosine distance is in [0, 2], where 0 is identical and 2 is opposite
- # Convert to a similarity score in [0, 1]
- similarity = 1.0 - (score / 2.0)
-
+ for doc, similarity in docs_with_scores:
# Skip results below the threshold
if similarity < score_threshold:
continue