vicinity 0.3.3__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {vicinity-0.3.3 → vicinity-0.3.4}/PKG-INFO +1 -1
  2. {vicinity-0.3.3 → vicinity-0.3.4}/tests/test_vicinity.py +8 -0
  3. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/faiss.py +1 -0
  4. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/hnsw.py +1 -0
  5. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/usearch.py +3 -2
  6. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/voyager.py +1 -0
  7. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/version.py +1 -1
  8. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity.egg-info/PKG-INFO +1 -1
  9. {vicinity-0.3.3 → vicinity-0.3.4}/.github/workflows/ci.yaml +0 -0
  10. {vicinity-0.3.3 → vicinity-0.3.4}/.gitignore +0 -0
  11. {vicinity-0.3.3 → vicinity-0.3.4}/.pre-commit-config.yaml +0 -0
  12. {vicinity-0.3.3 → vicinity-0.3.4}/LICENSE +0 -0
  13. {vicinity-0.3.3 → vicinity-0.3.4}/Makefile +0 -0
  14. {vicinity-0.3.3 → vicinity-0.3.4}/README.md +0 -0
  15. {vicinity-0.3.3 → vicinity-0.3.4}/assets/images/vicinity_logo.png +0 -0
  16. {vicinity-0.3.3 → vicinity-0.3.4}/pyproject.toml +0 -0
  17. {vicinity-0.3.3 → vicinity-0.3.4}/setup.cfg +0 -0
  18. {vicinity-0.3.3 → vicinity-0.3.4}/tests/conftest.py +0 -0
  19. {vicinity-0.3.3 → vicinity-0.3.4}/tests/test_utils.py +0 -0
  20. {vicinity-0.3.3 → vicinity-0.3.4}/uv.lock +0 -0
  21. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/__init__.py +0 -0
  22. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/__init__.py +0 -0
  23. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/annoy.py +0 -0
  24. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/base.py +0 -0
  25. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/basic.py +0 -0
  26. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/backends/pynndescent.py +0 -0
  27. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/datatypes.py +0 -0
  28. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/py.typed +0 -0
  29. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/utils.py +0 -0
  30. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity/vicinity.py +0 -0
  31. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity.egg-info/SOURCES.txt +0 -0
  32. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity.egg-info/dependency_links.txt +0 -0
  33. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity.egg-info/requires.txt +0 -0
  34. {vicinity-0.3.3 → vicinity-0.3.4}/vicinity.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vicinity
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Lightweight Nearest Neighbors with Flexible Backends
5
5
  Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
6
6
  License: MIT License
@@ -58,6 +58,10 @@ def test_vicinity_query(vicinity_instance: Vicinity, query_vector: np.ndarray) -
58
58
 
59
59
  assert len(results) == 1
60
60
 
61
+ results = vicinity_instance.query(np.stack([query_vector, query_vector]), k=2)
62
+
63
+ assert results[0] == results[1]
64
+
61
65
 
62
66
  def test_vicinity_query_threshold(vicinity_instance: Vicinity, query_vector: np.ndarray) -> None:
63
67
  """
@@ -70,6 +74,10 @@ def test_vicinity_query_threshold(vicinity_instance: Vicinity, query_vector: np.
70
74
 
71
75
  assert len(results) >= 1
72
76
 
77
+ results = vicinity_instance.query_threshold(np.stack([query_vector, query_vector]), threshold=0.7)
78
+
79
+ assert results[0] == results[1]
80
+
73
81
 
74
82
  def test_vicinity_insert(vicinity_instance: Vicinity, query_vector: np.ndarray) -> None:
75
83
  """
@@ -146,6 +146,7 @@ class FaissBackend(AbstractBackend[FaissArgs]):
146
146
 
147
147
  def query(self, vectors: npt.NDArray, k: int) -> QueryResult:
148
148
  """Perform a k-NN search in the FAISS index."""
149
+ k = min(len(self), k)
149
150
  if self.arguments.metric == "cosine":
150
151
  vectors = normalize(vectors)
151
152
  distances, indices = self.index.search(vectors, k)
@@ -93,6 +93,7 @@ class HNSWBackend(AbstractBackend[HNSWArgs]):
93
93
 
94
94
  def query(self, vectors: npt.NDArray, k: int) -> QueryResult:
95
95
  """Query the backend."""
96
+ k = min(k, len(self))
96
97
  return list(zip(*self.index.knn_query(vectors, k)))
97
98
 
98
99
  def insert(self, vectors: npt.NDArray) -> None:
@@ -115,9 +115,10 @@ class UsearchBackend(AbstractBackend[UsearchArgs]):
115
115
 
116
116
  def query(self, vectors: npt.NDArray, k: int) -> QueryResult:
117
117
  """Query the backend and return results as tuples of keys and distances."""
118
+ k = min(k, len(self))
118
119
  results = self.index.search(vectors, k)
119
- keys = np.array(results.keys).reshape(-1, k)
120
- distances = np.array(results.distances, dtype=np.float32).reshape(-1, k)
120
+ keys = np.atleast_2d(results.keys)
121
+ distances = np.atleast_2d(results.distances)
121
122
  return list(zip(keys, distances))
122
123
 
123
124
  def insert(self, vectors: npt.NDArray) -> None:
@@ -68,6 +68,7 @@ class VoyagerBackend(AbstractBackend[VoyagerArgs]):
68
68
 
69
69
  def query(self, query: npt.NDArray, k: int) -> QueryResult:
70
70
  """Query the backend for the nearest neighbors."""
71
+ k = min(k, len(self))
71
72
  indices, distances = self.index.query(query, k)
72
73
  return list(zip(indices, distances))
73
74
 
@@ -1,2 +1,2 @@
1
- __version_triple__ = (0, 3, 3)
1
+ __version_triple__ = (0, 3, 4)
2
2
  __version__ = ".".join(map(str, __version_triple__))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vicinity
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Lightweight Nearest Neighbors with Flexible Backends
5
5
  Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
6
6
  License: MIT License
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes