vicinity 0.4.0__tar.gz → 0.4.2__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.4.0 → vicinity-0.4.2}/PKG-INFO +58 -25
- {vicinity-0.4.0 → vicinity-0.4.2}/README.md +41 -22
- vicinity-0.4.2/assets/images/vicinity_logo.png +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/pyproject.toml +22 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/tests/conftest.py +13 -1
- {vicinity-0.4.0 → vicinity-0.4.2}/tests/test_vicinity.py +23 -7
- vicinity-0.4.2/uv.lock +2201 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/voyager.py +2 -1
- vicinity-0.4.2/vicinity/integrations/dataset_card_template.md +30 -0
- vicinity-0.4.2/vicinity/integrations/huggingface.py +130 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/version.py +1 -1
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/vicinity.py +74 -24
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity.egg-info/PKG-INFO +58 -25
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity.egg-info/SOURCES.txt +3 -1
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity.egg-info/requires.txt +18 -0
- vicinity-0.4.0/assets/images/vicinity_logo.png +0 -0
- vicinity-0.4.0/uv.lock +0 -1230
- {vicinity-0.4.0 → vicinity-0.4.2}/.github/workflows/ci.yaml +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/.gitignore +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/.pre-commit-config.yaml +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/LICENSE +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/Makefile +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/setup.cfg +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/tests/test_utils.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/__init__.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/__init__.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/annoy.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/base.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/basic.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/faiss.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/hnsw.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/pynndescent.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/backends/usearch.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/datatypes.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/py.typed +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity/utils.py +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity.egg-info/dependency_links.txt +0 -0
- {vicinity-0.4.0 → vicinity-0.4.2}/vicinity.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: vicinity
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
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
|
|
@@ -41,7 +41,6 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
41
41
|
Classifier: Programming Language :: Python :: 3.12
|
|
42
42
|
Requires-Python: >=3.9
|
|
43
43
|
Description-Content-Type: text/markdown
|
|
44
|
-
License-File: LICENSE
|
|
45
44
|
Requires-Dist: numpy
|
|
46
45
|
Requires-Dist: orjson
|
|
47
46
|
Requires-Dist: tqdm
|
|
@@ -54,6 +53,10 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
54
53
|
Requires-Dist: pytest-coverage; extra == "dev"
|
|
55
54
|
Requires-Dist: ruff; extra == "dev"
|
|
56
55
|
Requires-Dist: setuptools; extra == "dev"
|
|
56
|
+
Provides-Extra: huggingface
|
|
57
|
+
Requires-Dist: datasets; extra == "huggingface"
|
|
58
|
+
Provides-Extra: integrations
|
|
59
|
+
Requires-Dist: datasets; extra == "integrations"
|
|
57
60
|
Provides-Extra: hnsw
|
|
58
61
|
Requires-Dist: hnswlib; extra == "hnsw"
|
|
59
62
|
Provides-Extra: pynndescent
|
|
@@ -69,7 +72,18 @@ Provides-Extra: usearch
|
|
|
69
72
|
Requires-Dist: usearch; extra == "usearch"
|
|
70
73
|
Provides-Extra: voyager
|
|
71
74
|
Requires-Dist: voyager; extra == "voyager"
|
|
75
|
+
Provides-Extra: backends
|
|
76
|
+
Requires-Dist: hnswlib; extra == "backends"
|
|
77
|
+
Requires-Dist: pynndescent>=0.5.10; extra == "backends"
|
|
78
|
+
Requires-Dist: numba>=0.59.0; extra == "backends"
|
|
79
|
+
Requires-Dist: llvmlite>=0.42.0; extra == "backends"
|
|
80
|
+
Requires-Dist: numpy>=1.24.0; extra == "backends"
|
|
81
|
+
Requires-Dist: annoy; extra == "backends"
|
|
82
|
+
Requires-Dist: faiss-cpu; extra == "backends"
|
|
83
|
+
Requires-Dist: usearch; extra == "backends"
|
|
84
|
+
Requires-Dist: voyager; extra == "backends"
|
|
72
85
|
Provides-Extra: all
|
|
86
|
+
Requires-Dist: datasets; extra == "all"
|
|
73
87
|
Requires-Dist: hnswlib; extra == "all"
|
|
74
88
|
Requires-Dist: pynndescent>=0.5.10; extra == "all"
|
|
75
89
|
Requires-Dist: numba>=0.59.0; extra == "all"
|
|
@@ -81,30 +95,30 @@ Requires-Dist: usearch; extra == "all"
|
|
|
81
95
|
Requires-Dist: voyager; extra == "all"
|
|
82
96
|
|
|
83
97
|
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</a>
|
|
89
|
-
</div>
|
|
90
|
-
|
|
91
|
-
<div align="center">
|
|
92
|
-
<h2>Lightweight Nearest Neighbors with Flexible Backends</h2>
|
|
93
|
-
</div>
|
|
98
|
+
<h2 align="center">
|
|
99
|
+
<img width="35%" alt="Vicinity logo" src="assets/images/vicinity_logo.png"><br/>
|
|
100
|
+
Lightweight Nearest Neighbors with Flexible Backends
|
|
101
|
+
</h2>
|
|
94
102
|
|
|
95
103
|
<div align="center">
|
|
96
104
|
<h2>
|
|
97
105
|
<a href="https://pypi.org/project/vicinity/"><img src="https://img.shields.io/pypi/v/vicinity?color=%23007ec6&label=pypi%20package" alt="Package version"></a>
|
|
98
106
|
<a href="https://pypi.org/project/vicinity/"><img src="https://img.shields.io/pypi/pyversions/vicinity" alt="Supported Python versions"></a>
|
|
99
107
|
<a href="https://pepy.tech/project/vicinity">
|
|
100
|
-
|
|
108
|
+
<img src="https://static.pepy.tech/badge/vicinity" alt="Downloads">
|
|
101
109
|
</a>
|
|
102
110
|
<a href="https://app.codecov.io/gh/MinishLab/vicinity">
|
|
103
|
-
|
|
111
|
+
<img src="https://codecov.io/gh/MinishLab/vicinity/graph/badge.svg?token=0MQ2945OZL" alt="Codecov">
|
|
112
|
+
</a>
|
|
113
|
+
<a href="https://discord.gg/4BDPR5nmtK">
|
|
114
|
+
<img src="https://img.shields.io/badge/Join-Discord-5865F2?logo=discord&logoColor=white" alt="Join Discord">
|
|
115
|
+
</a>
|
|
116
|
+
<a href="https://github.com/MinishLab/vicinity/blob/main/LICENSE">
|
|
117
|
+
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
104
118
|
</a>
|
|
105
|
-
<a href="https://github.com/MinishLab/vicinity/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT"></a>
|
|
106
119
|
</h2>
|
|
107
120
|
|
|
121
|
+
|
|
108
122
|
[Quickstart](#quickstart) •
|
|
109
123
|
[Main Features](#main-features) •
|
|
110
124
|
[Supported Backends](#supported-backends) •
|
|
@@ -112,13 +126,11 @@ Requires-Dist: voyager; extra == "all"
|
|
|
112
126
|
|
|
113
127
|
</div>
|
|
114
128
|
|
|
115
|
-
|
|
116
129
|
Vicinity is a light-weight, low-dependency vector store. It provides a simple and intuitive interface for nearest neighbor search, with support for different backends and evaluation.
|
|
117
130
|
|
|
118
131
|
There are many nearest neighbors packages and methods out there. However, we found it difficult to compare them. Every package has its own interface, quirks, and limitations, and learning a new package can be time-consuming. In addition to that, how do you effectively evaluate different packages? How do you know which one is the best for your use case?
|
|
119
132
|
|
|
120
|
-
|
|
121
|
-
This is where Vicinity comes in. Instead of learning a new interface for each new package or backend, Vicinity provides a unified interface for all backends. This allows you to easily experiment with different indexing methods and distance metrics and choose the best one for your use case. Vicinity also provides a simple way to evaluate the performance of different backends, allowing you to measure the queries per second and recall.
|
|
133
|
+
This is where Vicinity comes in. Instead of learning a new interface for each new package or backend, Vicinity provides a unified interface for all backends. This allows you to easily experiment with different indexing methods and distance metrics and choose the best one for your use case. Vicinity also provides a simple way to evaluate the performance of different backends, allowing you to measure the queries per second and recall.
|
|
122
134
|
|
|
123
135
|
## Quickstart
|
|
124
136
|
|
|
@@ -126,18 +138,18 @@ Install the package with:
|
|
|
126
138
|
```bash
|
|
127
139
|
pip install vicinity
|
|
128
140
|
```
|
|
129
|
-
Optionally, [install
|
|
141
|
+
Optionally, [install specific backends and integrations](#installation), or simply install all of them with:
|
|
130
142
|
```bash
|
|
131
143
|
pip install vicinity[all]
|
|
132
144
|
```
|
|
133
145
|
|
|
134
|
-
|
|
135
146
|
The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
|
|
147
|
+
|
|
136
148
|
```python
|
|
137
149
|
import numpy as np
|
|
138
150
|
from vicinity import Vicinity, Backend, Metric
|
|
139
151
|
|
|
140
|
-
# Create some dummy data
|
|
152
|
+
# Create some dummy data as strings or other serializable objects
|
|
141
153
|
items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
|
|
142
154
|
vectors = np.random.rand(len(items), 128)
|
|
143
155
|
|
|
@@ -164,12 +176,21 @@ results = vicinity.query(query_vectors, k=3)
|
|
|
164
176
|
```
|
|
165
177
|
|
|
166
178
|
Saving and loading a vector store:
|
|
179
|
+
|
|
167
180
|
```python
|
|
168
181
|
vicinity.save('my_vector_store')
|
|
169
182
|
vicinity = Vicinity.load('my_vector_store')
|
|
170
183
|
```
|
|
171
184
|
|
|
185
|
+
Pushing and loading a vector store from the Hugging Face Hub (note that you can optionally add the model used for generating embeddings to the metadata, e.g. `vicinity.metadata["model"] = "minishlab/potion-base-8M"`):
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
vicinity.push_to_hub(repo_id='minishlab/my-vicinity-repo')
|
|
189
|
+
vicinity = Vicinity.load_from_hub(repo_id='minishlab/my-vicinity-repo')
|
|
190
|
+
```
|
|
191
|
+
|
|
172
192
|
Evaluating a backend:
|
|
193
|
+
|
|
173
194
|
```python
|
|
174
195
|
# Use the first 1000 vectors as query vectors
|
|
175
196
|
query_vectors = vectors[:1000]
|
|
@@ -182,14 +203,17 @@ qps, recall = vicinity.evaluate(
|
|
|
182
203
|
```
|
|
183
204
|
|
|
184
205
|
## Main Features
|
|
206
|
+
|
|
185
207
|
Vicinity provides the following features:
|
|
186
208
|
- Lightweight: Minimal dependencies and fast performance.
|
|
187
209
|
- Flexible Backend Support: Use different backends for vector storage and search.
|
|
188
210
|
- Serialization: Save and load vector stores for persistence.
|
|
211
|
+
- HuggingFace Hub Integration: Push and load vector stores directly to and from the HuggingFace Hub.
|
|
189
212
|
- Evaluation: Easily evaluate the performance of different backends.
|
|
190
213
|
- Easy to Use: Simple and intuitive API.
|
|
191
214
|
|
|
192
215
|
## Supported Backends
|
|
216
|
+
|
|
193
217
|
The following backends are supported:
|
|
194
218
|
- `BASIC`: A simple (exact matching) flat index for vector storage and search.
|
|
195
219
|
- [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
|
|
@@ -208,8 +232,6 @@ The following backends are supported:
|
|
|
208
232
|
- `ivfpqr`: Inverted file search with product quantizer and refinement.
|
|
209
233
|
- [VOYAGER](https://github.com/spotify/voyager): Voyager is a library for performing fast approximate nearest-neighbor searches on an in-memory collection of vectors.
|
|
210
234
|
|
|
211
|
-
|
|
212
|
-
|
|
213
235
|
NOTE: the ANN backends do not support dynamic deletion. To delete items, you need to recreate the index. Insertion is supported in the following backends: `FAISS`, `HNSW`, and `Usearch`. The `BASIC` backend supports both insertion and deletion.
|
|
214
236
|
|
|
215
237
|
### Backend Parameters
|
|
@@ -241,14 +263,25 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
|
|
|
241
263
|
| | `m` | The number of connections between nodes in the tree’s internal data structure. | `16` |
|
|
242
264
|
|
|
243
265
|
## Installation
|
|
266
|
+
|
|
244
267
|
The following installation options are available:
|
|
268
|
+
|
|
245
269
|
```bash
|
|
246
270
|
# Install the base package
|
|
247
271
|
pip install vicinity
|
|
248
272
|
|
|
249
|
-
# Install all backends
|
|
273
|
+
# Install all integrations and backends
|
|
250
274
|
pip install vicinity[all]
|
|
251
275
|
|
|
276
|
+
# Install all integrations
|
|
277
|
+
pip install vicinity[integrations]
|
|
278
|
+
|
|
279
|
+
# Install specific integrations
|
|
280
|
+
pip install vicinity[huggingface]
|
|
281
|
+
|
|
282
|
+
# Install all backends
|
|
283
|
+
pip install vicinity[backends]
|
|
284
|
+
|
|
252
285
|
# Install specific backends
|
|
253
286
|
pip install vicinity[annoy]
|
|
254
287
|
pip install vicinity[faiss]
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
</a>
|
|
7
|
-
</div>
|
|
8
|
-
|
|
9
|
-
<div align="center">
|
|
10
|
-
<h2>Lightweight Nearest Neighbors with Flexible Backends</h2>
|
|
11
|
-
</div>
|
|
2
|
+
<h2 align="center">
|
|
3
|
+
<img width="35%" alt="Vicinity logo" src="assets/images/vicinity_logo.png"><br/>
|
|
4
|
+
Lightweight Nearest Neighbors with Flexible Backends
|
|
5
|
+
</h2>
|
|
12
6
|
|
|
13
7
|
<div align="center">
|
|
14
8
|
<h2>
|
|
15
9
|
<a href="https://pypi.org/project/vicinity/"><img src="https://img.shields.io/pypi/v/vicinity?color=%23007ec6&label=pypi%20package" alt="Package version"></a>
|
|
16
10
|
<a href="https://pypi.org/project/vicinity/"><img src="https://img.shields.io/pypi/pyversions/vicinity" alt="Supported Python versions"></a>
|
|
17
11
|
<a href="https://pepy.tech/project/vicinity">
|
|
18
|
-
|
|
12
|
+
<img src="https://static.pepy.tech/badge/vicinity" alt="Downloads">
|
|
19
13
|
</a>
|
|
20
14
|
<a href="https://app.codecov.io/gh/MinishLab/vicinity">
|
|
21
|
-
|
|
15
|
+
<img src="https://codecov.io/gh/MinishLab/vicinity/graph/badge.svg?token=0MQ2945OZL" alt="Codecov">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/4BDPR5nmtK">
|
|
18
|
+
<img src="https://img.shields.io/badge/Join-Discord-5865F2?logo=discord&logoColor=white" alt="Join Discord">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://github.com/MinishLab/vicinity/blob/main/LICENSE">
|
|
21
|
+
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
22
22
|
</a>
|
|
23
|
-
<a href="https://github.com/MinishLab/vicinity/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT"></a>
|
|
24
23
|
</h2>
|
|
25
24
|
|
|
25
|
+
|
|
26
26
|
[Quickstart](#quickstart) •
|
|
27
27
|
[Main Features](#main-features) •
|
|
28
28
|
[Supported Backends](#supported-backends) •
|
|
@@ -30,13 +30,11 @@
|
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
Vicinity is a light-weight, low-dependency vector store. It provides a simple and intuitive interface for nearest neighbor search, with support for different backends and evaluation.
|
|
35
34
|
|
|
36
35
|
There are many nearest neighbors packages and methods out there. However, we found it difficult to compare them. Every package has its own interface, quirks, and limitations, and learning a new package can be time-consuming. In addition to that, how do you effectively evaluate different packages? How do you know which one is the best for your use case?
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
This is where Vicinity comes in. Instead of learning a new interface for each new package or backend, Vicinity provides a unified interface for all backends. This allows you to easily experiment with different indexing methods and distance metrics and choose the best one for your use case. Vicinity also provides a simple way to evaluate the performance of different backends, allowing you to measure the queries per second and recall.
|
|
37
|
+
This is where Vicinity comes in. Instead of learning a new interface for each new package or backend, Vicinity provides a unified interface for all backends. This allows you to easily experiment with different indexing methods and distance metrics and choose the best one for your use case. Vicinity also provides a simple way to evaluate the performance of different backends, allowing you to measure the queries per second and recall.
|
|
40
38
|
|
|
41
39
|
## Quickstart
|
|
42
40
|
|
|
@@ -44,18 +42,18 @@ Install the package with:
|
|
|
44
42
|
```bash
|
|
45
43
|
pip install vicinity
|
|
46
44
|
```
|
|
47
|
-
Optionally, [install
|
|
45
|
+
Optionally, [install specific backends and integrations](#installation), or simply install all of them with:
|
|
48
46
|
```bash
|
|
49
47
|
pip install vicinity[all]
|
|
50
48
|
```
|
|
51
49
|
|
|
52
|
-
|
|
53
50
|
The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
|
|
51
|
+
|
|
54
52
|
```python
|
|
55
53
|
import numpy as np
|
|
56
54
|
from vicinity import Vicinity, Backend, Metric
|
|
57
55
|
|
|
58
|
-
# Create some dummy data
|
|
56
|
+
# Create some dummy data as strings or other serializable objects
|
|
59
57
|
items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
|
|
60
58
|
vectors = np.random.rand(len(items), 128)
|
|
61
59
|
|
|
@@ -82,12 +80,21 @@ results = vicinity.query(query_vectors, k=3)
|
|
|
82
80
|
```
|
|
83
81
|
|
|
84
82
|
Saving and loading a vector store:
|
|
83
|
+
|
|
85
84
|
```python
|
|
86
85
|
vicinity.save('my_vector_store')
|
|
87
86
|
vicinity = Vicinity.load('my_vector_store')
|
|
88
87
|
```
|
|
89
88
|
|
|
89
|
+
Pushing and loading a vector store from the Hugging Face Hub (note that you can optionally add the model used for generating embeddings to the metadata, e.g. `vicinity.metadata["model"] = "minishlab/potion-base-8M"`):
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
vicinity.push_to_hub(repo_id='minishlab/my-vicinity-repo')
|
|
93
|
+
vicinity = Vicinity.load_from_hub(repo_id='minishlab/my-vicinity-repo')
|
|
94
|
+
```
|
|
95
|
+
|
|
90
96
|
Evaluating a backend:
|
|
97
|
+
|
|
91
98
|
```python
|
|
92
99
|
# Use the first 1000 vectors as query vectors
|
|
93
100
|
query_vectors = vectors[:1000]
|
|
@@ -100,14 +107,17 @@ qps, recall = vicinity.evaluate(
|
|
|
100
107
|
```
|
|
101
108
|
|
|
102
109
|
## Main Features
|
|
110
|
+
|
|
103
111
|
Vicinity provides the following features:
|
|
104
112
|
- Lightweight: Minimal dependencies and fast performance.
|
|
105
113
|
- Flexible Backend Support: Use different backends for vector storage and search.
|
|
106
114
|
- Serialization: Save and load vector stores for persistence.
|
|
115
|
+
- HuggingFace Hub Integration: Push and load vector stores directly to and from the HuggingFace Hub.
|
|
107
116
|
- Evaluation: Easily evaluate the performance of different backends.
|
|
108
117
|
- Easy to Use: Simple and intuitive API.
|
|
109
118
|
|
|
110
119
|
## Supported Backends
|
|
120
|
+
|
|
111
121
|
The following backends are supported:
|
|
112
122
|
- `BASIC`: A simple (exact matching) flat index for vector storage and search.
|
|
113
123
|
- [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
|
|
@@ -126,8 +136,6 @@ The following backends are supported:
|
|
|
126
136
|
- `ivfpqr`: Inverted file search with product quantizer and refinement.
|
|
127
137
|
- [VOYAGER](https://github.com/spotify/voyager): Voyager is a library for performing fast approximate nearest-neighbor searches on an in-memory collection of vectors.
|
|
128
138
|
|
|
129
|
-
|
|
130
|
-
|
|
131
139
|
NOTE: the ANN backends do not support dynamic deletion. To delete items, you need to recreate the index. Insertion is supported in the following backends: `FAISS`, `HNSW`, and `Usearch`. The `BASIC` backend supports both insertion and deletion.
|
|
132
140
|
|
|
133
141
|
### Backend Parameters
|
|
@@ -159,14 +167,25 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
|
|
|
159
167
|
| | `m` | The number of connections between nodes in the tree’s internal data structure. | `16` |
|
|
160
168
|
|
|
161
169
|
## Installation
|
|
170
|
+
|
|
162
171
|
The following installation options are available:
|
|
172
|
+
|
|
163
173
|
```bash
|
|
164
174
|
# Install the base package
|
|
165
175
|
pip install vicinity
|
|
166
176
|
|
|
167
|
-
# Install all backends
|
|
177
|
+
# Install all integrations and backends
|
|
168
178
|
pip install vicinity[all]
|
|
169
179
|
|
|
180
|
+
# Install all integrations
|
|
181
|
+
pip install vicinity[integrations]
|
|
182
|
+
|
|
183
|
+
# Install specific integrations
|
|
184
|
+
pip install vicinity[huggingface]
|
|
185
|
+
|
|
186
|
+
# Install all backends
|
|
187
|
+
pip install vicinity[backends]
|
|
188
|
+
|
|
170
189
|
# Install specific backends
|
|
171
190
|
pip install vicinity[annoy]
|
|
172
191
|
pip install vicinity[faiss]
|
|
Binary file
|
|
@@ -42,6 +42,14 @@ dev = [
|
|
|
42
42
|
"ruff",
|
|
43
43
|
"setuptools"
|
|
44
44
|
]
|
|
45
|
+
|
|
46
|
+
# Integrations
|
|
47
|
+
huggingface = ["datasets"]
|
|
48
|
+
integrations = [
|
|
49
|
+
"datasets"
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
# Backends
|
|
45
53
|
hnsw = ["hnswlib"]
|
|
46
54
|
pynndescent = [
|
|
47
55
|
"pynndescent>=0.5.10",
|
|
@@ -53,7 +61,20 @@ annoy = ["annoy"]
|
|
|
53
61
|
faiss = ["faiss-cpu"]
|
|
54
62
|
usearch = ["usearch"]
|
|
55
63
|
voyager = ["voyager"]
|
|
64
|
+
backends = [
|
|
65
|
+
"hnswlib",
|
|
66
|
+
"pynndescent>=0.5.10",
|
|
67
|
+
"numba>=0.59.0",
|
|
68
|
+
"llvmlite>=0.42.0",
|
|
69
|
+
"numpy>=1.24.0",
|
|
70
|
+
"annoy",
|
|
71
|
+
"faiss-cpu",
|
|
72
|
+
"usearch",
|
|
73
|
+
"voyager"
|
|
74
|
+
]
|
|
75
|
+
|
|
56
76
|
all = [
|
|
77
|
+
"datasets",
|
|
57
78
|
"hnswlib",
|
|
58
79
|
"pynndescent>=0.5.10",
|
|
59
80
|
"numba>=0.59.0",
|
|
@@ -115,6 +136,7 @@ ignore_missing_imports = true
|
|
|
115
136
|
|
|
116
137
|
[tool.setuptools]
|
|
117
138
|
packages = ["vicinity"]
|
|
139
|
+
license-files = []
|
|
118
140
|
|
|
119
141
|
[tool.setuptools_scm]
|
|
120
142
|
# can be empty if no extra settings are needed, presence enables setuptools_scm
|
|
@@ -24,7 +24,19 @@ _faiss_index_types = [
|
|
|
24
24
|
@pytest.fixture(scope="session")
|
|
25
25
|
def items() -> list[str]:
|
|
26
26
|
"""Fixture providing a list of item names."""
|
|
27
|
-
return [f"item{i}" for i in range(1, 10001)]
|
|
27
|
+
return [f"item{i}" if i % 2 == 0 else {"name": f"item{i}", "id": i} for i in range(1, 10001)]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture(scope="session")
|
|
31
|
+
def non_serializable_items() -> list[str]:
|
|
32
|
+
"""Fixture providing a list of non-serializable items."""
|
|
33
|
+
|
|
34
|
+
class NonSerializable:
|
|
35
|
+
def __init__(self, name: str, id: int) -> None:
|
|
36
|
+
self.name = name
|
|
37
|
+
self.id = id
|
|
38
|
+
|
|
39
|
+
return [NonSerializable(f"item{i}", i) for i in range(1, 10001)]
|
|
28
40
|
|
|
29
41
|
|
|
30
42
|
@pytest.fixture(scope="session")
|
|
@@ -4,6 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import pytest
|
|
7
|
+
from orjson import JSONEncodeError
|
|
7
8
|
|
|
8
9
|
from vicinity import Vicinity
|
|
9
10
|
from vicinity.datatypes import Backend
|
|
@@ -162,6 +163,21 @@ def test_vicinity_save_and_load_vector_store(tmp_path: Path, vicinity_instance_w
|
|
|
162
163
|
assert v.vector_store is not None
|
|
163
164
|
|
|
164
165
|
|
|
166
|
+
def test_vicinity_save_and_load_non_serializable_items(
|
|
167
|
+
tmp_path: Path, non_serializable_items: list[str], vectors: np.ndarray
|
|
168
|
+
) -> None:
|
|
169
|
+
"""
|
|
170
|
+
Test Vicinity.save and Vicinity.load with non-serializable items.
|
|
171
|
+
|
|
172
|
+
:param tmp_path: Temporary directory provided by pytest.
|
|
173
|
+
:param non_serializable_items: A list of non-serializable items.
|
|
174
|
+
"""
|
|
175
|
+
vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=non_serializable_items)
|
|
176
|
+
save_path = tmp_path / "vicinity_data"
|
|
177
|
+
with pytest.raises(JSONEncodeError):
|
|
178
|
+
vicinity.save(save_path)
|
|
179
|
+
|
|
180
|
+
|
|
165
181
|
def test_index_vector_store(vicinity_with_basic_backend_and_store: Vicinity, vectors: np.ndarray) -> None:
|
|
166
182
|
"""
|
|
167
183
|
Index vectors in the Vicinity instance.
|
|
@@ -183,18 +199,17 @@ def test_index_vector_store(vicinity_with_basic_backend_and_store: Vicinity, vec
|
|
|
183
199
|
vicinity_with_basic_backend_and_store.get_vector_by_index([-1])
|
|
184
200
|
|
|
185
201
|
|
|
186
|
-
def test_vicinity_insert_duplicate(vicinity_instance: Vicinity, query_vector: np.ndarray) -> None:
|
|
202
|
+
def test_vicinity_insert_duplicate(items: list[str], vicinity_instance: Vicinity, query_vector: np.ndarray) -> None:
|
|
187
203
|
"""
|
|
188
204
|
Test that Vicinity.insert raises ValueError when inserting duplicate items.
|
|
189
205
|
|
|
190
206
|
:param vicinity_instance: A Vicinity instance.
|
|
191
207
|
:raises ValueError: If inserting items that already exist.
|
|
192
208
|
"""
|
|
193
|
-
new_items = ["item1"]
|
|
194
209
|
new_vector = query_vector
|
|
195
210
|
|
|
196
211
|
with pytest.raises(ValueError):
|
|
197
|
-
vicinity_instance.insert(
|
|
212
|
+
vicinity_instance.insert(items[0], new_vector[None, :])
|
|
198
213
|
|
|
199
214
|
|
|
200
215
|
def test_vicinity_delete_nonexistent(vicinity_instance: Vicinity) -> None:
|
|
@@ -281,7 +296,8 @@ def test_vicinity_delete_and_query(vicinity_instance: Vicinity, items: list[str]
|
|
|
281
296
|
return
|
|
282
297
|
|
|
283
298
|
# Delete some items from the Vicinity instance
|
|
284
|
-
|
|
299
|
+
non_existing_items_indices = [0, 1, 2]
|
|
300
|
+
items_to_delete = [items[i] for i in non_existing_items_indices]
|
|
285
301
|
vicinity_instance.delete(items_to_delete)
|
|
286
302
|
|
|
287
303
|
# Ensure the items are no longer in the items list
|
|
@@ -289,14 +305,14 @@ def test_vicinity_delete_and_query(vicinity_instance: Vicinity, items: list[str]
|
|
|
289
305
|
assert item not in vicinity_instance.items
|
|
290
306
|
|
|
291
307
|
# Query using a vector of an item that wasn't deleted
|
|
292
|
-
|
|
293
|
-
item3_vector = vectors[
|
|
308
|
+
existing_item_index = 3
|
|
309
|
+
item3_vector = vectors[existing_item_index]
|
|
294
310
|
|
|
295
311
|
results = vicinity_instance.query(item3_vector, k=10)
|
|
296
312
|
returned_items = [item for item, _ in results[0]]
|
|
297
313
|
|
|
298
314
|
# Check that the queried item is in the results
|
|
299
|
-
assert
|
|
315
|
+
assert items[existing_item_index] in returned_items
|
|
300
316
|
|
|
301
317
|
|
|
302
318
|
def test_vicinity_evaluate(vicinity_instance: Vicinity, vectors: np.ndarray) -> None:
|