Skip to content

Commit

Permalink
Fix: FAISS banchmarks compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Aug 23, 2023
1 parent 3355e64 commit da771e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions python/scripts/index_faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from faiss import IndexHNSWFlat, IndexIVFPQ, read_index

from usearch.index import Matches
from usearch.index import Matches, BatchMatches
from usearch.index import (
DEFAULT_CONNECTIVITY,
DEFAULT_EXPANSION_ADD,
Expand Down Expand Up @@ -45,9 +45,9 @@ def add(self, keys, vectors):
# self._faiss.add_with_ids(vectors, keys)
self._faiss.add(vectors)

def search(self, queries, k: int) -> Matches:
def search(self, queries, k: int) -> BatchMatches:
distances, keys = self._faiss.search(queries, k)
return Matches(keys, distances, np.array([k] * queries.shape[0]))
return BatchMatches(keys, distances, np.array([k] * queries.shape[0]))

def __len__(self) -> int:
return self._faiss.ntotal
Expand Down
8 changes: 4 additions & 4 deletions python/usearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ class Matches:
keys: np.ndarray
distances: np.ndarray

visited_members: int
computed_distances: int
visited_members: int = 0
computed_distances: int = 0

def __len__(self) -> int:
return len(self.keys)
Expand Down Expand Up @@ -304,8 +304,8 @@ class BatchMatches:
distances: np.ndarray
counts: np.ndarray

visited_members: int
computed_distances: int
visited_members: int = 0
computed_distances: int = 0

def __len__(self) -> int:
return len(self.counts)
Expand Down

0 comments on commit da771e6

Please sign in to comment.