💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Macfaiss (#818)
Jeffdceb40c774c4
diff --git a/docs/embeddings/configuration/ann.md b/docs/embeddings/configuration/ann.mdindex 53391875..162cda34 100644--- a/docs/embeddings/configuration/ann.md+++ b/docs/embeddings/configuration/ann.md@@ -40,6 +40,8 @@ See the following Faiss documentation links for more information.- [Binary Indexes](https://github.com/facebookresearch/faiss/wiki/Binary-indexes)- [Search Tuning](https://github.com/facebookresearch/faiss/wiki/Faster-search)+Note: For macOS users, an existing bug in an upstream package restricts the number of processing threads to 1. This limitation is managed internally to prevent system crashes.+### hnsw```yamlhnsw:diff --git a/docs/faq.md b/docs/faq.mdindex 33c3baf9..80db8704 100644--- a/docs/faq.md+++ b/docs/faq.md@@ -103,10 +103,11 @@ __Solution__Set the following environment parameters.-- Disable OpenMP threading via the environment variable `export OMP_NUM_THREADS=1`+- OpenMP threading is handled internally on macOS platforms, but it can be disabled by setting the environment variable OMP_NUM_THREADS to 1, e.g., export OMP_NUM_THREADS=1. For more details, refer to the related discussion on GitHub: kyamagu/faiss-wheels#100.- Disable PyTorch MPS device via `export PYTORCH_MPS_DISABLE=1`- Disable llama.cpp metal via `export LLAMA_NO_METAL=1`+----------__Issue__diff --git a/src/python/txtai/ann/faiss.py b/src/python/txtai/ann/faiss.pyindex 72be5547..75d0958e 100644--- a/src/python/txtai/ann/faiss.py+++ b/src/python/txtai/ann/faiss.py@@ -3,14 +3,23 @@ Faiss module"""import math+import platformimport numpy as np+from faiss import omp_set_num_threadsfrom faiss import index_factory, IO_FLAG_MMAP, METRIC_INNER_PRODUCT, read_index, write_indexfrom faiss import index_binary_factory, read_index_binary, write_index_binary, IndexBinaryIDMapfrom .base import ANN+if platform.system() == "Darwin":+ # Workaround for an open bug on macOS causing segmentation faults in FAISS.+ # Setting the number of threads in OpenMP to 1 avoids the issue for now.+ # Ref: https://github.com/kyamagu/faiss-wheels/issues/100+ # Remove this workaround once the upstream bug is patched.+ omp_set_num_threads(1)+class Faiss(ANN):"""diff --git a/test/python/testann.py b/test/python/testann.pyindex f313cb9c..c932be54 100644--- a/test/python/testann.py+++ b/test/python/testann.py@@ -136,6 +136,14 @@ class TestANN(unittest.TestCase):# Validate countself.assertEqual(ann.count(), 100)+ @patch("platform.system")+ def testFaissMacOS(self, mock_platform):+ """+ Test backend with OS Darwin+ """+ mock_platform.return_value = "Darwin"+ self.runTests("faiss")+@patch("sqlalchemy.orm.Query.limit")def testPGVector(self, query):"""