Skip to content

Commit

Permalink
Added lsh
Browse files Browse the repository at this point in the history
  • Loading branch information
Pringled committed Nov 15, 2024
1 parent 9dc0c11 commit f7e6d09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
19 changes: 11 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

# Define supported FAISS index types
FAISS_INDEX_TYPES = [
"flat",
# "flat",
# "ivf",
# "hnsw",
# "lsh",
"hnsw",
"lsh",
# "scalar",
# "pq",
# "ivf_scalar",
Expand Down Expand Up @@ -42,26 +42,29 @@ def query_vector() -> np.ndarray:

BACKEND_PARAMS = [(Backend.FAISS, index_type) for index_type in FAISS_INDEX_TYPES] + [
(Backend.BASIC, None),
(Backend.HNSW, None),
(Backend.ANNOY, None),
(Backend.PYNNDESCENT, None),
# (Backend.HNSW, None),
# (Backend.ANNOY, None),
# (Backend.PYNNDESCENT, None),
]

# Create human-readable ids for each backend type
BACKEND_IDS = [f"{backend.name}-{index_type}" if index_type else backend.name for backend, index_type in BACKEND_PARAMS]


@pytest.fixture(params=BACKEND_PARAMS)
def backend_type(request: pytest.FixtureRequest) -> Backend:
"""Fixture parametrizing over all backend types defined in Backend."""
return request.param


@pytest.fixture(params=BACKEND_PARAMS)
@pytest.fixture(params=BACKEND_PARAMS, ids=BACKEND_IDS)
def vicinity_instance(request: pytest.FixtureRequest, items: list[str], vectors: np.ndarray) -> Vicinity:
"""Fixture providing a Vicinity instance for each backend type."""
backend_type, index_type = request.param
# Handle FAISS backend with specific FAISS index types
if backend_type == Backend.FAISS:
return Vicinity.from_vectors_and_items(
vectors, items, backend_type=backend_type, index_type=index_type, nlist=4
vectors, items, backend_type=backend_type, index_type=index_type, nlist=4, nbits=32
)

# Handle non-FAISS backends without passing `index_type`
Expand Down
9 changes: 3 additions & 6 deletions tests/test_vicinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_vicinity_from_vectors_and_items(
:param items: A list of item names.
:param vectors: An array of vectors.
"""
backend: Backend = backend_type[0]
backend = backend_type[0]
vicinity = Vicinity.from_vectors_and_items(vectors, items, backend_type=backend)

assert len(vicinity) == len(items)
Expand Down Expand Up @@ -104,11 +104,8 @@ def test_vicinity_delete(vicinity_instance: Vicinity, items: list[str], vectors:
# Don't test delete for Annoy and Pynndescent backend
return

if vicinity_instance.backend.backend_type == Backend.FAISS and vicinity_instance.backend.arguments.index_type in {
"pq",
"scalar",
"ivfpq",
"ivfpqr",
elif vicinity_instance.backend.backend_type == Backend.FAISS and vicinity_instance.backend.arguments.index_type in {
"hnsw"
}:
# Skip delete test for FAISS index types that do not support deletion
return
Expand Down

0 comments on commit f7e6d09

Please sign in to comment.