Skip to content

armgit / LEANN

Public Imported from GitHub
0

[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.

Fix Linux default threading to prevent FAISS/ZMQ hangs (issue #208)

aakash34b91134df8e
diff --git a/packages/leann-core/src/leann/__init__.py b/packages/leann-core/src/leann/__init__.py
index 7ac156d..fa75745 100644
--- a/packages/leann-core/src/leann/__init__.py
+++ b/packages/leann-core/src/leann/__init__.py
@@ -2,8 +2,11 @@
import os
import platform
-# Fix OpenMP threading issues on macOS ARM64
-if platform.system() == "Darwin":
+# Fix OpenMP/FAISS threading defaults for common platforms
+system = platform.system()
+
+if system == "Darwin":
+ # macOS ARM64: prevent runaway threading and duplicate lib issues
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
@@ -12,6 +15,12 @@ if platform.system() == "Darwin":
if os.environ.get("CI") == "true":
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "0"
os.environ["TOKENIZERS_PARALLELISM"] = "false"
+elif system == "Linux":
+ # Linux CPU-only: default to single-thread to avoid FAISS/ZMQ hangs (issue #208)
+ os.environ.setdefault("OMP_NUM_THREADS", "1")
+ os.environ.setdefault("MKL_NUM_THREADS", "1")
+ os.environ.setdefault("FAISS_NUM_THREADS", "1")
+ os.environ.setdefault("OMP_WAIT_POLICY", "PASSIVE")
from .api import LeannBuilder, LeannChat, LeannSearcher
from .registry import BACKEND_REGISTRY, autodiscover_backends