Skip to content

armgit / txtai

Public Imported from GitHub
0

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

Re-add Windows specific logic for Faiss as full support isn't quite ready

davidmezzettif6024014427f
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index ce4e18ed..76e14da1 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,49 +1,36 @@
-name: txtai build
+name: txtai
on: ["push", "pull_request"]
jobs:
- linux:
- runs-on: ubuntu-latest
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.6
+
+ # macos pre-install
+ - run: brew install libomp
+ if: ${{ matrix.os == "ubuntu-latest"}}
+
+ # Windows pre-install
+ - run: python -m pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
+ if: ${{ matrix.os == "windows-latest"}}
+
+ # Common steps
- run: pip install -U pip wheel coverage coveralls
- run: pip install .
- - run: python --version
+ - run: python --version || python --version
- run: make coverage
+
+ # Only create test coverage once
- run: coveralls
+ if: ${{ matrix.os == "ubuntu-latest"}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
-# macos:
-# runs-on: macos-latest
-
-# steps:
-# - uses: actions/checkout@v2
-# - uses: actions/setup-python@v2
-# with:
-# python-version: 3.6
-# - run: brew install libomp
-# - run: pip3 install -U pip wheel coverage coveralls
-# - run: pip3 install .
-# - run: python3 --version
-# - run: make PYTHON=python3 test
-
-# windows:
-# runs-on: windows-latest
-
-# steps:
-# - uses: actions/checkout@v2
-# - uses: actions/setup-python@v2
-# with:
-# python-version: 3.6
-# - run: python -m pip install -U pip wheel
-# - run: python -m pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
-# - run: pip install -U pip wheel coverage coveralls
-# - run: pip install .
-# - run: python --version
-# - run: make test
diff --git a/setup.py b/setup.py
index 7c5213e5..2add1877 100644
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ setup(name="txtai",
python_requires=">=3.6",
install_requires=[
"annoy>=1.16.3",
- "faiss-cpu>=1.6.4",
+ "faiss-cpu>=1.6.3; os_name != 'nt'",
"fastapi>=0.61.1",
"fasttext>=0.9.2",
"hnswlib>=0.4.0",
diff --git a/src/python/txtai/ann.py b/src/python/txtai/ann.py
index c0bdab61..49c1a1e3 100644
--- a/src/python/txtai/ann.py
+++ b/src/python/txtai/ann.py
@@ -4,12 +4,17 @@ ANN (Approximate Nearest Neighbors) module
import numpy as np
-import faiss
-
# pylint: disable=E0611
from annoy import AnnoyIndex
from hnswlib import Index
+# Conditionally import Faiss as it's only supported on Linux/macOS
+try:
+ import faiss
+ FAISS = True
+except ImportError:
+ FAISS = False
+
class ANN(object):
"""
Base class for ANN models.
@@ -31,9 +36,9 @@ class ANN(object):
model = None
backend = config.get("backend")
- # Default backend if not provided
+ # Default backend if not provided, based on available libraries
if not backend:
- backend = "faiss"
+ backend = "faiss" if FAISS else "annoy"
# Create ANN instance
if backend == "annoy":
@@ -41,6 +46,10 @@ class ANN(object):
elif backend == "hnsw":
model = HNSW(config)
else:
+ # Raise error if trying to create a Faiss index without Faiss installed
+ if not FAISS:
+ raise ImportError("Faiss library is not installed")
+
model = Faiss(config)
# Store config back
diff --git a/test/python/testann.py b/test/python/testann.py
index 42f13156..8d763637 100644
--- a/test/python/testann.py
+++ b/test/python/testann.py
@@ -22,6 +22,7 @@ class TestANN(unittest.TestCase):
self.assertEqual(self.backend("annoy").config["backend"], "annoy")
+ @unittest.skipIf(os.name == "nt", "Faiss not installed on Windows")
def testFaiss(self):
"""
Test Faiss backend