vicinity 0.3.2__tar.gz → 0.3.3__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.
- {vicinity-0.3.2 → vicinity-0.3.3}/PKG-INFO +9 -4
- {vicinity-0.3.2 → vicinity-0.3.3}/README.md +8 -3
- {vicinity-0.3.2 → vicinity-0.3.3}/tests/conftest.py +1 -1
- {vicinity-0.3.2 → vicinity-0.3.3}/tests/test_vicinity.py +34 -5
- {vicinity-0.3.2 → vicinity-0.3.3}/uv.lock +41 -1
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/version.py +1 -1
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/vicinity.py +4 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity.egg-info/PKG-INFO +9 -4
- {vicinity-0.3.2 → vicinity-0.3.3}/.github/workflows/ci.yaml +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/.gitignore +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/.pre-commit-config.yaml +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/LICENSE +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/Makefile +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/assets/images/vicinity_logo.png +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/pyproject.toml +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/setup.cfg +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/tests/test_utils.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/__init__.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/__init__.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/annoy.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/base.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/basic.py +4 -4
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/faiss.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/hnsw.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/pynndescent.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/usearch.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/backends/voyager.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/datatypes.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/py.typed +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity/utils.py +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity.egg-info/SOURCES.txt +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity.egg-info/dependency_links.txt +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/vicinity.egg-info/requires.txt +0 -0
- {vicinity-0.3.2 → vicinity-0.3.3}/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
|
+
Version: 0.3.3
|
|
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
|
|
@@ -153,10 +153,14 @@ vicinity = Vicinity.from_vectors_and_items(
|
|
|
153
153
|
query_vector = np.random.rand(128)
|
|
154
154
|
|
|
155
155
|
# Query for nearest neighbors with a top-k search
|
|
156
|
-
results = vicinity.query(
|
|
156
|
+
results = vicinity.query(query_vector, k=3)
|
|
157
157
|
|
|
158
158
|
# Query for nearest neighbors with a threshold search
|
|
159
|
-
results = vicinity.query_threshold(
|
|
159
|
+
results = vicinity.query_threshold(query_vector, threshold=0.9)
|
|
160
|
+
|
|
161
|
+
# Query with a list of query vectors
|
|
162
|
+
query_vectors = np.random.rand(5, 128)
|
|
163
|
+
results = vicinity.query(query_vectors, k=3)
|
|
160
164
|
```
|
|
161
165
|
|
|
162
166
|
Saving and loading a vector store:
|
|
@@ -191,7 +195,7 @@ The following backends are supported:
|
|
|
191
195
|
- [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
|
|
192
196
|
- [USEARCH](https://github.com/unum-cloud/usearch): ANN search using Usearch. This uses a highly optimized version of the HNSW algorithm.
|
|
193
197
|
- [ANNOY](https://github.com/spotify/annoy): "Approximate Nearest Neighbors Oh Yeah" for approximate nearest neighbor search.
|
|
194
|
-
- [
|
|
198
|
+
- [PYNNDESCENT](https://github.com/lmcinnes/pynndescent): ANN search using PyNNDescent.
|
|
195
199
|
- [FAISS](https://github.com/facebookresearch/faiss): All FAISS indexes are supported:
|
|
196
200
|
- `flat`: Exact search.
|
|
197
201
|
- `ivf`: Inverted file search.
|
|
@@ -213,6 +217,7 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
|
|
|
213
217
|
|
|
214
218
|
| Backend | Parameter | Description | Default Value |
|
|
215
219
|
|-----------------|---------------------|-----------------------------------------------------------------------------------------------|---------------------|
|
|
220
|
+
| **BASIC** | `metric` | Similarity metric to use (`cosine`, `euclidean`). | `"cosine"` |
|
|
216
221
|
| **ANNOY** | `metric` | Similarity metric to use (`dot`, `euclidean`, `cosine`). | `"cosine"` |
|
|
217
222
|
| | `trees` | Number of trees to use for indexing. | `100` |
|
|
218
223
|
| | `length` | Optional length of the dataset. | `None` |
|
|
@@ -71,10 +71,14 @@ vicinity = Vicinity.from_vectors_and_items(
|
|
|
71
71
|
query_vector = np.random.rand(128)
|
|
72
72
|
|
|
73
73
|
# Query for nearest neighbors with a top-k search
|
|
74
|
-
results = vicinity.query(
|
|
74
|
+
results = vicinity.query(query_vector, k=3)
|
|
75
75
|
|
|
76
76
|
# Query for nearest neighbors with a threshold search
|
|
77
|
-
results = vicinity.query_threshold(
|
|
77
|
+
results = vicinity.query_threshold(query_vector, threshold=0.9)
|
|
78
|
+
|
|
79
|
+
# Query with a list of query vectors
|
|
80
|
+
query_vectors = np.random.rand(5, 128)
|
|
81
|
+
results = vicinity.query(query_vectors, k=3)
|
|
78
82
|
```
|
|
79
83
|
|
|
80
84
|
Saving and loading a vector store:
|
|
@@ -109,7 +113,7 @@ The following backends are supported:
|
|
|
109
113
|
- [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
|
|
110
114
|
- [USEARCH](https://github.com/unum-cloud/usearch): ANN search using Usearch. This uses a highly optimized version of the HNSW algorithm.
|
|
111
115
|
- [ANNOY](https://github.com/spotify/annoy): "Approximate Nearest Neighbors Oh Yeah" for approximate nearest neighbor search.
|
|
112
|
-
- [
|
|
116
|
+
- [PYNNDESCENT](https://github.com/lmcinnes/pynndescent): ANN search using PyNNDescent.
|
|
113
117
|
- [FAISS](https://github.com/facebookresearch/faiss): All FAISS indexes are supported:
|
|
114
118
|
- `flat`: Exact search.
|
|
115
119
|
- `ivf`: Inverted file search.
|
|
@@ -131,6 +135,7 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
|
|
|
131
135
|
|
|
132
136
|
| Backend | Parameter | Description | Default Value |
|
|
133
137
|
|-----------------|---------------------|-----------------------------------------------------------------------------------------------|---------------------|
|
|
138
|
+
| **BASIC** | `metric` | Similarity metric to use (`cosine`, `euclidean`). | `"cosine"` |
|
|
134
139
|
| **ANNOY** | `metric` | Similarity metric to use (`dot`, `euclidean`, `cosine`). | `"cosine"` |
|
|
135
140
|
| | `trees` | Number of trees to use for indexing. | `100` |
|
|
136
141
|
| | `length` | Optional length of the dataset. | `None` |
|
|
@@ -110,6 +110,6 @@ def vicinity_instance_with_stored_vectors(
|
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
@pytest.fixture()
|
|
113
|
-
def
|
|
113
|
+
def vicinity_with_basic_backend_and_store(vectors: np.ndarray, items: list[str]) -> Vicinity:
|
|
114
114
|
"""Fixture providing a BasicBackend instance."""
|
|
115
115
|
return Vicinity.from_vectors_and_items(vectors, items, backend_type=Backend.BASIC, store_vectors=True)
|
|
@@ -154,25 +154,25 @@ def test_vicinity_save_and_load_vector_store(tmp_path: Path, vicinity_instance_w
|
|
|
154
154
|
assert v.vector_store is not None
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def test_index_vector_store(
|
|
157
|
+
def test_index_vector_store(vicinity_with_basic_backend_and_store: Vicinity, vectors: np.ndarray) -> None:
|
|
158
158
|
"""
|
|
159
159
|
Index vectors in the Vicinity instance.
|
|
160
160
|
|
|
161
161
|
:param vicinity_instance: A Vicinity instance.
|
|
162
162
|
:param vectors: Array of vectors to index.
|
|
163
163
|
"""
|
|
164
|
-
v =
|
|
164
|
+
v = vicinity_with_basic_backend_and_store.get_vector_by_index(0)
|
|
165
165
|
assert np.allclose(v, vectors[0])
|
|
166
166
|
|
|
167
167
|
idx = [0, 1, 2, 3, 4, 10]
|
|
168
|
-
v =
|
|
168
|
+
v = vicinity_with_basic_backend_and_store.get_vector_by_index(idx)
|
|
169
169
|
assert np.allclose(v, vectors[idx])
|
|
170
170
|
|
|
171
171
|
with pytest.raises(ValueError):
|
|
172
|
-
|
|
172
|
+
vicinity_with_basic_backend_and_store.get_vector_by_index([10_000])
|
|
173
173
|
|
|
174
174
|
with pytest.raises(ValueError):
|
|
175
|
-
|
|
175
|
+
vicinity_with_basic_backend_and_store.get_vector_by_index([-1])
|
|
176
176
|
|
|
177
177
|
|
|
178
178
|
def test_vicinity_insert_duplicate(vicinity_instance: Vicinity, query_vector: np.ndarray) -> None:
|
|
@@ -203,6 +203,35 @@ def test_vicinity_delete_nonexistent(vicinity_instance: Vicinity) -> None:
|
|
|
203
203
|
vicinity_instance.delete(["item10002"])
|
|
204
204
|
|
|
205
205
|
|
|
206
|
+
def test_vicinity_insert_with_store(vicinity_with_basic_backend_and_store: Vicinity) -> None:
|
|
207
|
+
"""
|
|
208
|
+
Test that Vicinity.insert raises ValueError when trying to insert vectors into a Vicinity instance with stored vectors.
|
|
209
|
+
|
|
210
|
+
:param vicinity_with_basic_backend_and_store: A Vicinity instance with stored vectors.
|
|
211
|
+
"""
|
|
212
|
+
new_item = ["item10002"]
|
|
213
|
+
new_vector = np.full((1, vicinity_with_basic_backend_and_store.dim), 0.5)
|
|
214
|
+
|
|
215
|
+
vicinity_with_basic_backend_and_store.insert(new_item, new_vector)
|
|
216
|
+
assert vicinity_with_basic_backend_and_store.vector_store is not None
|
|
217
|
+
assert len(vicinity_with_basic_backend_and_store) == len(vicinity_with_basic_backend_and_store.vector_store)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def test_vicinity_delete_with_store(vicinity_with_basic_backend_and_store: Vicinity) -> None:
|
|
221
|
+
"""
|
|
222
|
+
Test Vicinity.delete method by verifying that the vector for a deleted item is not returned in subsequent queries.
|
|
223
|
+
|
|
224
|
+
:param vicinity_with_basic_backend_and_store: A Vicinity instance.
|
|
225
|
+
"""
|
|
226
|
+
assert vicinity_with_basic_backend_and_store.vector_store is not None
|
|
227
|
+
# Delete "item2" from the Vicinity instance
|
|
228
|
+
vicinity_with_basic_backend_and_store.delete(["item2"])
|
|
229
|
+
|
|
230
|
+
# Ensure "item2" is no longer in the items list
|
|
231
|
+
assert "item2" not in vicinity_with_basic_backend_and_store.items
|
|
232
|
+
assert len(vicinity_with_basic_backend_and_store) == len(vicinity_with_basic_backend_and_store.vector_store)
|
|
233
|
+
|
|
234
|
+
|
|
206
235
|
def test_vicinity_insert_mismatched_lengths(vicinity_instance: Vicinity, query_vector: np.ndarray) -> None:
|
|
207
236
|
"""
|
|
208
237
|
Test that Vicinity.insert raises ValueError when tokens and vectors lengths do not match.
|
|
@@ -1087,7 +1087,7 @@ wheels = [
|
|
|
1087
1087
|
|
|
1088
1088
|
[[package]]
|
|
1089
1089
|
name = "vicinity"
|
|
1090
|
-
version = "0.3.
|
|
1090
|
+
version = "0.3.1"
|
|
1091
1091
|
source = { editable = "." }
|
|
1092
1092
|
dependencies = [
|
|
1093
1093
|
{ name = "numpy" },
|
|
@@ -1105,6 +1105,7 @@ all = [
|
|
|
1105
1105
|
{ name = "numpy" },
|
|
1106
1106
|
{ name = "pynndescent" },
|
|
1107
1107
|
{ name = "usearch" },
|
|
1108
|
+
{ name = "voyager" },
|
|
1108
1109
|
]
|
|
1109
1110
|
annoy = [
|
|
1110
1111
|
{ name = "annoy" },
|
|
@@ -1134,6 +1135,9 @@ pynndescent = [
|
|
|
1134
1135
|
usearch = [
|
|
1135
1136
|
{ name = "usearch" },
|
|
1136
1137
|
]
|
|
1138
|
+
voyager = [
|
|
1139
|
+
{ name = "voyager" },
|
|
1140
|
+
]
|
|
1137
1141
|
|
|
1138
1142
|
[package.metadata]
|
|
1139
1143
|
requires-dist = [
|
|
@@ -1164,6 +1168,8 @@ requires-dist = [
|
|
|
1164
1168
|
{ name = "tqdm" },
|
|
1165
1169
|
{ name = "usearch", marker = "extra == 'all'" },
|
|
1166
1170
|
{ name = "usearch", marker = "extra == 'usearch'" },
|
|
1171
|
+
{ name = "voyager", marker = "extra == 'all'" },
|
|
1172
|
+
{ name = "voyager", marker = "extra == 'voyager'" },
|
|
1167
1173
|
]
|
|
1168
1174
|
|
|
1169
1175
|
[[package]]
|
|
@@ -1180,6 +1186,40 @@ wheels = [
|
|
|
1180
1186
|
{ url = "https://files.pythonhosted.org/packages/ae/92/78324ff89391e00c8f4cf6b8526c41c6ef36b4ea2d2c132250b1a6fc2b8d/virtualenv-20.27.1-py3-none-any.whl", hash = "sha256:f11f1b8a29525562925f745563bfd48b189450f61fb34c4f9cc79dd5aa32a1f4", size = 3117838 },
|
|
1181
1187
|
]
|
|
1182
1188
|
|
|
1189
|
+
[[package]]
|
|
1190
|
+
name = "voyager"
|
|
1191
|
+
version = "2.0.9"
|
|
1192
|
+
source = { registry = "https://pypi.org/simple" }
|
|
1193
|
+
dependencies = [
|
|
1194
|
+
{ name = "numpy" },
|
|
1195
|
+
]
|
|
1196
|
+
wheels = [
|
|
1197
|
+
{ url = "https://files.pythonhosted.org/packages/79/d9/62399eb8a907da7f9eba0e2facf78925d54ba644a9be671cd98e7b4f547f/voyager-2.0.9-cp310-cp310-macosx_10_13_universal2.whl", hash = "sha256:f3cfe84666314daaf51836f77dabaafeb064bcbe5d9435d9c97886af19ae2876", size = 731200 },
|
|
1198
|
+
{ url = "https://files.pythonhosted.org/packages/51/70/0d90ebf90ca6fa415513b63925f4b21aeebd9f6400ecce5dffdb3743039f/voyager-2.0.9-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:956a60f864a586991cdde09373caf5630ab3319c47b6cdad4bf05ea8ba96a578", size = 377180 },
|
|
1199
|
+
{ url = "https://files.pythonhosted.org/packages/6e/af/76bb88b390bbf9c1dcbab90acd669168294c6d20b6a230b7333b432eee1b/voyager-2.0.9-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:56e6e7d6f1597207141d224d5420dc690ae27a2feb6c4164180cecc453cd5816", size = 356644 },
|
|
1200
|
+
{ url = "https://files.pythonhosted.org/packages/2b/b9/a514e2f88b7cdf35cb182064d5859258488cfe7e7b82bfff012d9cffd746/voyager-2.0.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7be032a8ae5447ce289f1c95f349e825e9d4edc915db7ea1b2c273940de2acbe", size = 4211154 },
|
|
1201
|
+
{ url = "https://files.pythonhosted.org/packages/db/95/1032e54e27eeac13f9affaf1fdeb834cc389f728316c9e7244c0e57c3e98/voyager-2.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ed85d23006f98091a137f637894560d1020ba25217b5332729417ac0a200b0bd", size = 4280843 },
|
|
1202
|
+
{ url = "https://files.pythonhosted.org/packages/2c/dc/395551a312110ad53cdac4f0126708d02c2d5c11c9f63ecf6a64985fab56/voyager-2.0.9-cp310-cp310-win_amd64.whl", hash = "sha256:053f22b23bd090f6376cf026c31653d3c040f9eaf0c6d1267e766a442a5b8ff8", size = 199722 },
|
|
1203
|
+
{ url = "https://files.pythonhosted.org/packages/c2/17/ace9aaf1e65553dae2ce3ba947e922e6bd16aa89abe558543471b5fe065c/voyager-2.0.9-cp311-cp311-macosx_10_13_universal2.whl", hash = "sha256:d270b29bafb5a133abd611a03b1b9ec7b03a44361966609abef72dde2518eb5e", size = 734474 },
|
|
1204
|
+
{ url = "https://files.pythonhosted.org/packages/3b/73/83d047ad7f6cb4fad426ed6f8b6c249c3ffecffa85ebb017e6d4e725aa0c/voyager-2.0.9-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:216c517dd66e0095f5f14277627a233c081797119028737f71168f094bacb9d0", size = 378460 },
|
|
1205
|
+
{ url = "https://files.pythonhosted.org/packages/92/3e/7648441cf72258fc2e5cb9be6f39890684f15a06f66db42f12a8041e4e30/voyager-2.0.9-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a2ea7f5e61bb7de06d0196b1fbd43826908c6f2811576c94d97e353e7b32cb78", size = 358415 },
|
|
1206
|
+
{ url = "https://files.pythonhosted.org/packages/42/02/0f7c5e4d9eaf83d932ab0c89e93117166575163f670a6200f55a56dae268/voyager-2.0.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4c451b25d449ac6923f7424a3255995f97263ed694fa873119703da01a09f6d7", size = 4237185 },
|
|
1207
|
+
{ url = "https://files.pythonhosted.org/packages/38/7c/47598f5630b97cf7cf8f29ac390b8beab24adeb3f322d004244660b96e8f/voyager-2.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ecd1e690a69a044b988fd102676bb8584ed423af4b7aa9e69349203690263aad", size = 4304425 },
|
|
1208
|
+
{ url = "https://files.pythonhosted.org/packages/1a/95/fa3f090d8e1bdbd8401e9944080f3c12d1e8f1385980da4151f6ab62a783/voyager-2.0.9-cp311-cp311-win_amd64.whl", hash = "sha256:5e1c264f4202b551ca8cb5a33d456f451c598ea7b9680134177dc5443819f328", size = 200738 },
|
|
1209
|
+
{ url = "https://files.pythonhosted.org/packages/22/fa/455fbd3a709403dd98f910b1ba5bfd9bf38db3e718edd03c8758ecb3b750/voyager-2.0.9-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:2d344617a1c97d6b317f13e801b3377a55f1e5b91786f9354dcde12b7945b3e0", size = 736030 },
|
|
1210
|
+
{ url = "https://files.pythonhosted.org/packages/d4/9f/ee29e306901be0ea521b464c3533bd95d49dbe08c54df64cd49bbb13918e/voyager-2.0.9-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d58682f2f8d9cfccb95d2278eeec01ed76f90636cf6123db7850eb9a4b7e70e7", size = 380145 },
|
|
1211
|
+
{ url = "https://files.pythonhosted.org/packages/e5/83/d9b40742c17f674cbafec55b751804e68ee9b492cfb02fddc72f060beb17/voyager-2.0.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:510485dafa539ae130f2ad8bf7c95b21a2fa454f0b25581b37be3ca36bab29a1", size = 358094 },
|
|
1212
|
+
{ url = "https://files.pythonhosted.org/packages/33/61/e705ee3154450802912d35e881261182c01ba0e65cc83c6ef16b84c56e1b/voyager-2.0.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a4015db48c0c5d596e8bc536f4b05b601a2138e6439e00b06410e18286896273", size = 4234321 },
|
|
1213
|
+
{ url = "https://files.pythonhosted.org/packages/13/7a/4ac271fb5a8068f97dd6446622d679d26237a772ab12d1e6241cc0848dca/voyager-2.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:805f1736e5fe309ae8884e572b78d9816ff4fd6f1ef364298a2f62566ea86bc9", size = 4312789 },
|
|
1214
|
+
{ url = "https://files.pythonhosted.org/packages/b4/f6/906b21d4b42df264fc231c74753ca164f14cb09d40cd6b3a32d293aa0418/voyager-2.0.9-cp312-cp312-win_amd64.whl", hash = "sha256:abc7041ba8047d25942afe457db597be6f33161a669aac00dfffc00b7d833bfa", size = 201868 },
|
|
1215
|
+
{ url = "https://files.pythonhosted.org/packages/9f/9a/f5467d52356995c9f64cb27a99211142abead24290bfb8ccfb38168ef91d/voyager-2.0.9-cp39-cp39-macosx_10_13_universal2.whl", hash = "sha256:a38b7a232367095ef28350889b0c4ec8ce9f53c0a7839f2b06f517b652938e2c", size = 731403 },
|
|
1216
|
+
{ url = "https://files.pythonhosted.org/packages/ab/be/ecef9dfce07c535af6d11a4011a4a8693c4174ca8f87495e9ba30c8c7884/voyager-2.0.9-cp39-cp39-macosx_10_13_x86_64.whl", hash = "sha256:e5968f516a94832a599c9c1b64246b7f81344ed3fb49247fbdaba7e673c1e8a9", size = 377365 },
|
|
1217
|
+
{ url = "https://files.pythonhosted.org/packages/55/99/d31f596e887d998c81671b8e345925f07ccc36dee7144dbf80f1c86fb187/voyager-2.0.9-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f4095d4012479fa53b21f8a65c7790e844c3634a8ead1fca04f69a4a34ebc362", size = 356976 },
|
|
1218
|
+
{ url = "https://files.pythonhosted.org/packages/6f/43/096fcfa3443d37d8b5e4163b49b0d91f0456022df59017a8ae25ae4482d9/voyager-2.0.9-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d55f85d36111e950d42e7d78accca84c582d5606ec1bae2d4b2da41ccc3e7f2e", size = 4209912 },
|
|
1219
|
+
{ url = "https://files.pythonhosted.org/packages/ff/51/c35a343471746e8964cb5d002a3367f5e28f5787c2c0689e0566a7406f66/voyager-2.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:83e1dd648040df093ddda74a6f361ec912caf981d20dfdd4b0d3bd7fb230147b", size = 4280035 },
|
|
1220
|
+
{ url = "https://files.pythonhosted.org/packages/ba/6c/5643effb7e495f8ee5c346e7b41961cb8d4dd6ef6952b24ec929a868f41c/voyager-2.0.9-cp39-cp39-win_amd64.whl", hash = "sha256:a2b17036c9b825f7062eb09ac613ca1e3fdb11712b1fc6d58bbbc201698e09c9", size = 196377 },
|
|
1221
|
+
]
|
|
1222
|
+
|
|
1183
1223
|
[[package]]
|
|
1184
1224
|
name = "wcwidth"
|
|
1185
1225
|
version = "0.2.13"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_triple__ = (0, 3,
|
|
1
|
+
__version_triple__ = (0, 3, 3)
|
|
2
2
|
__version__ = ".".join(map(str, __version_triple__))
|
|
@@ -243,6 +243,8 @@ class Vicinity:
|
|
|
243
243
|
raise ValueError(f"Token {token} is already in the vector space.")
|
|
244
244
|
self.items.append(token)
|
|
245
245
|
self.backend.insert(vectors)
|
|
246
|
+
if self.vector_store is not None:
|
|
247
|
+
self.vector_store.insert(vectors)
|
|
246
248
|
|
|
247
249
|
def delete(self, tokens: Sequence[str]) -> None:
|
|
248
250
|
"""
|
|
@@ -260,6 +262,8 @@ class Vicinity:
|
|
|
260
262
|
raise ValueError(f"Token {exc} was not in the vector space.") from exc
|
|
261
263
|
|
|
262
264
|
self.backend.delete(curr_indices)
|
|
265
|
+
if self.vector_store is not None:
|
|
266
|
+
self.vector_store.delete(curr_indices)
|
|
263
267
|
|
|
264
268
|
# Delete items starting from the highest index
|
|
265
269
|
for index in sorted(curr_indices, reverse=True):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vicinity
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
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
|
|
@@ -153,10 +153,14 @@ vicinity = Vicinity.from_vectors_and_items(
|
|
|
153
153
|
query_vector = np.random.rand(128)
|
|
154
154
|
|
|
155
155
|
# Query for nearest neighbors with a top-k search
|
|
156
|
-
results = vicinity.query(
|
|
156
|
+
results = vicinity.query(query_vector, k=3)
|
|
157
157
|
|
|
158
158
|
# Query for nearest neighbors with a threshold search
|
|
159
|
-
results = vicinity.query_threshold(
|
|
159
|
+
results = vicinity.query_threshold(query_vector, threshold=0.9)
|
|
160
|
+
|
|
161
|
+
# Query with a list of query vectors
|
|
162
|
+
query_vectors = np.random.rand(5, 128)
|
|
163
|
+
results = vicinity.query(query_vectors, k=3)
|
|
160
164
|
```
|
|
161
165
|
|
|
162
166
|
Saving and loading a vector store:
|
|
@@ -191,7 +195,7 @@ The following backends are supported:
|
|
|
191
195
|
- [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
|
|
192
196
|
- [USEARCH](https://github.com/unum-cloud/usearch): ANN search using Usearch. This uses a highly optimized version of the HNSW algorithm.
|
|
193
197
|
- [ANNOY](https://github.com/spotify/annoy): "Approximate Nearest Neighbors Oh Yeah" for approximate nearest neighbor search.
|
|
194
|
-
- [
|
|
198
|
+
- [PYNNDESCENT](https://github.com/lmcinnes/pynndescent): ANN search using PyNNDescent.
|
|
195
199
|
- [FAISS](https://github.com/facebookresearch/faiss): All FAISS indexes are supported:
|
|
196
200
|
- `flat`: Exact search.
|
|
197
201
|
- `ivf`: Inverted file search.
|
|
@@ -213,6 +217,7 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
|
|
|
213
217
|
|
|
214
218
|
| Backend | Parameter | Description | Default Value |
|
|
215
219
|
|-----------------|---------------------|-----------------------------------------------------------------------------------------------|---------------------|
|
|
220
|
+
| **BASIC** | `metric` | Similarity metric to use (`cosine`, `euclidean`). | `"cosine"` |
|
|
216
221
|
| **ANNOY** | `metric` | Similarity metric to use (`dot`, `euclidean`, `cosine`). | `"cosine"` |
|
|
217
222
|
| | `trees` | Number of trees to use for indexing. | `100` |
|
|
218
223
|
| | `length` | Optional length of the dataset. | `None` |
|
|
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
|
|
@@ -90,6 +90,10 @@ class BasicVectorStore:
|
|
|
90
90
|
self._vectors = matrix
|
|
91
91
|
self._update_precomputed_data()
|
|
92
92
|
|
|
93
|
+
def __len__(self) -> int:
|
|
94
|
+
"""Get the number of vectors."""
|
|
95
|
+
return self.vectors.shape[0]
|
|
96
|
+
|
|
93
97
|
|
|
94
98
|
class BasicBackend(BasicVectorStore, AbstractBackend[BasicArgs], ABC):
|
|
95
99
|
argument_class = BasicArgs
|
|
@@ -100,10 +104,6 @@ class BasicBackend(BasicVectorStore, AbstractBackend[BasicArgs], ABC):
|
|
|
100
104
|
"""Initialize the backend."""
|
|
101
105
|
super().__init__(vectors=vectors, arguments=arguments)
|
|
102
106
|
|
|
103
|
-
def __len__(self) -> int:
|
|
104
|
-
"""Get the number of vectors."""
|
|
105
|
-
return self.vectors.shape[0]
|
|
106
|
-
|
|
107
107
|
@property
|
|
108
108
|
def backend_type(self) -> Backend:
|
|
109
109
|
"""The type of the backend."""
|
|
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
|