Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Make faiss a required library for all platforms (#98)

davidmezzettib90b2f4460c8
diff --git a/src/python/txtai/ann/factory.py b/src/python/txtai/ann/factory.py
index 8f84ea70..6767b4d7 100644
--- a/src/python/txtai/ann/factory.py
+++ b/src/python/txtai/ann/factory.py
@@ -3,7 +3,7 @@ Factory module
"""
from .annoy import Annoy, ANNOY
-from .faiss import Faiss, FAISS
+from .faiss import Faiss
from .hnsw import HNSW, HNSWLIB
@@ -26,11 +26,7 @@ class ANNFactory:
# ANN model
model = None
- backend = config.get("backend")
-
- # Default backend if not provided, based on available libraries
- if not backend:
- backend = "faiss" if FAISS else "hnsw"
+ backend = config.get("backend", "faiss")
# Create ANN instance
if backend == "annoy":
@@ -44,9 +40,6 @@ class ANNFactory:
model = HNSW(config)
else:
- if not FAISS:
- raise ImportError("Faiss library is not available for this platform")
-
model = Faiss(config)
# Store config back
diff --git a/src/python/txtai/ann/faiss.py b/src/python/txtai/ann/faiss.py
index 72f891fd..677e16c9 100644
--- a/src/python/txtai/ann/faiss.py
+++ b/src/python/txtai/ann/faiss.py
@@ -4,15 +4,9 @@ Faiss module
import numpy as np
-from .base import ANN
-
-# Conditional import
-try:
- from faiss import index_factory, METRIC_INNER_PRODUCT, read_index, write_index
+from faiss import index_factory, METRIC_INNER_PRODUCT, read_index, write_index
- FAISS = True
-except ImportError:
- FAISS = False
+from .base import ANN
class Faiss(ANN):
diff --git a/test/python/testoptional.py b/test/python/testoptional.py
index 0c198523..776bb6f3 100644
--- a/test/python/testoptional.py
+++ b/test/python/testoptional.py
@@ -25,7 +25,6 @@ class TestOptional(unittest.TestCase):
"""
txtai.ann.factory.ANNOY = not txtai.ann.factory.ANNOY
- txtai.ann.factory.FAISS = not txtai.ann.factory.FAISS
txtai.ann.factory.HNSWLIB = not txtai.ann.factory.HNSWLIB
txtai.pipeline.segmentation.NLTK = not txtai.pipeline.segmentation.NLTK
@@ -65,10 +64,6 @@ class TestOptional(unittest.TestCase):
with self.assertRaises(ImportError):
ANNFactory.create({"backend": "annoy"})
- if not txtai.ann.factory.FAISS:
- with self.assertRaises(ImportError):
- ANNFactory.create({"backend": "faiss"})
-
with self.assertRaises(ImportError):
ANNFactory.create({"backend": "hnsw"})