vicinity 0.3.4__tar.gz → 0.4.1__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 (37) hide show
  1. {vicinity-0.3.4 → vicinity-0.4.1}/PKG-INFO +54 -14
  2. {vicinity-0.3.4 → vicinity-0.4.1}/README.md +37 -12
  3. {vicinity-0.3.4 → vicinity-0.4.1}/pyproject.toml +21 -0
  4. {vicinity-0.3.4 → vicinity-0.4.1}/tests/conftest.py +13 -1
  5. {vicinity-0.3.4 → vicinity-0.4.1}/tests/test_vicinity.py +23 -7
  6. vicinity-0.4.1/uv.lock +2201 -0
  7. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/annoy.py +5 -4
  8. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/base.py +1 -1
  9. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/basic.py +9 -6
  10. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/faiss.py +7 -5
  11. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/hnsw.py +5 -4
  12. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/pynndescent.py +6 -6
  13. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/usearch.py +9 -6
  14. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/voyager.py +5 -4
  15. vicinity-0.4.1/vicinity/integrations/dataset_card_template.md +30 -0
  16. vicinity-0.4.1/vicinity/integrations/huggingface.py +130 -0
  17. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/version.py +1 -1
  18. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/vicinity.py +82 -28
  19. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity.egg-info/PKG-INFO +54 -14
  20. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity.egg-info/SOURCES.txt +3 -1
  21. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity.egg-info/requires.txt +18 -0
  22. vicinity-0.3.4/uv.lock +0 -1230
  23. {vicinity-0.3.4 → vicinity-0.4.1}/.github/workflows/ci.yaml +0 -0
  24. {vicinity-0.3.4 → vicinity-0.4.1}/.gitignore +0 -0
  25. {vicinity-0.3.4 → vicinity-0.4.1}/.pre-commit-config.yaml +0 -0
  26. {vicinity-0.3.4 → vicinity-0.4.1}/LICENSE +0 -0
  27. {vicinity-0.3.4 → vicinity-0.4.1}/Makefile +0 -0
  28. {vicinity-0.3.4 → vicinity-0.4.1}/assets/images/vicinity_logo.png +0 -0
  29. {vicinity-0.3.4 → vicinity-0.4.1}/setup.cfg +0 -0
  30. {vicinity-0.3.4 → vicinity-0.4.1}/tests/test_utils.py +0 -0
  31. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/__init__.py +0 -0
  32. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/backends/__init__.py +0 -0
  33. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/datatypes.py +0 -0
  34. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/py.typed +0 -0
  35. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity/utils.py +0 -0
  36. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity.egg-info/dependency_links.txt +0 -0
  37. {vicinity-0.3.4 → vicinity-0.4.1}/vicinity.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: vicinity
3
- Version: 0.3.4
3
+ Version: 0.4.1
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
@@ -54,6 +54,10 @@ Requires-Dist: pytest; extra == "dev"
54
54
  Requires-Dist: pytest-coverage; extra == "dev"
55
55
  Requires-Dist: ruff; extra == "dev"
56
56
  Requires-Dist: setuptools; extra == "dev"
57
+ Provides-Extra: huggingface
58
+ Requires-Dist: datasets; extra == "huggingface"
59
+ Provides-Extra: integrations
60
+ Requires-Dist: datasets; extra == "integrations"
57
61
  Provides-Extra: hnsw
58
62
  Requires-Dist: hnswlib; extra == "hnsw"
59
63
  Provides-Extra: pynndescent
@@ -69,7 +73,18 @@ Provides-Extra: usearch
69
73
  Requires-Dist: usearch; extra == "usearch"
70
74
  Provides-Extra: voyager
71
75
  Requires-Dist: voyager; extra == "voyager"
76
+ Provides-Extra: backends
77
+ Requires-Dist: hnswlib; extra == "backends"
78
+ Requires-Dist: pynndescent>=0.5.10; extra == "backends"
79
+ Requires-Dist: numba>=0.59.0; extra == "backends"
80
+ Requires-Dist: llvmlite>=0.42.0; extra == "backends"
81
+ Requires-Dist: numpy>=1.24.0; extra == "backends"
82
+ Requires-Dist: annoy; extra == "backends"
83
+ Requires-Dist: faiss-cpu; extra == "backends"
84
+ Requires-Dist: usearch; extra == "backends"
85
+ Requires-Dist: voyager; extra == "backends"
72
86
  Provides-Extra: all
87
+ Requires-Dist: datasets; extra == "all"
73
88
  Requires-Dist: hnswlib; extra == "all"
74
89
  Requires-Dist: pynndescent>=0.5.10; extra == "all"
75
90
  Requires-Dist: numba>=0.59.0; extra == "all"
@@ -97,14 +112,20 @@ Requires-Dist: voyager; extra == "all"
97
112
  <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
113
  <a href="https://pypi.org/project/vicinity/"><img src="https://img.shields.io/pypi/pyversions/vicinity" alt="Supported Python versions"></a>
99
114
  <a href="https://pepy.tech/project/vicinity">
100
- <img src="https://static.pepy.tech/badge/vicinity" alt="Downloads">
115
+ <img src="https://static.pepy.tech/badge/vicinity" alt="Downloads">
101
116
  </a>
102
117
  <a href="https://app.codecov.io/gh/MinishLab/vicinity">
103
- <img src="https://codecov.io/gh/MinishLab/vicinity/graph/badge.svg?token=0MQ2945OZL" alt="Codecov">
118
+ <img src="https://codecov.io/gh/MinishLab/vicinity/graph/badge.svg?token=0MQ2945OZL" alt="Codecov">
119
+ </a>
120
+ <a href="https://discord.gg/4BDPR5nmtK">
121
+ <img src="https://img.shields.io/badge/Join-Discord-5865F2?logo=discord&logoColor=white" alt="Join Discord">
122
+ </a>
123
+ <a href="https://github.com/MinishLab/vicinity/blob/main/LICENSE">
124
+ <img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
104
125
  </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
126
  </h2>
107
127
 
128
+
108
129
  [Quickstart](#quickstart) •
109
130
  [Main Features](#main-features) •
110
131
  [Supported Backends](#supported-backends) •
@@ -112,13 +133,11 @@ Requires-Dist: voyager; extra == "all"
112
133
 
113
134
  </div>
114
135
 
115
-
116
136
  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
137
 
118
138
  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
139
 
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.
140
+ 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
141
 
123
142
  ## Quickstart
124
143
 
@@ -126,18 +145,18 @@ Install the package with:
126
145
  ```bash
127
146
  pip install vicinity
128
147
  ```
129
- Optionally, [install any of the supported backends](#installation), or simply install all of them with:
148
+ Optionally, [install specific backends and integrations](#installation), or simply install all of them with:
130
149
  ```bash
131
150
  pip install vicinity[all]
132
151
  ```
133
152
 
134
-
135
153
  The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
154
+
136
155
  ```python
137
156
  import numpy as np
138
157
  from vicinity import Vicinity, Backend, Metric
139
158
 
140
- # Create some dummy data
159
+ # Create some dummy data as strings or other serializable objects
141
160
  items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
142
161
  vectors = np.random.rand(len(items), 128)
143
162
 
@@ -164,12 +183,21 @@ results = vicinity.query(query_vectors, k=3)
164
183
  ```
165
184
 
166
185
  Saving and loading a vector store:
186
+
167
187
  ```python
168
188
  vicinity.save('my_vector_store')
169
189
  vicinity = Vicinity.load('my_vector_store')
170
190
  ```
171
191
 
192
+ 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"`):
193
+
194
+ ```python
195
+ vicinity.push_to_hub(repo_id='minishlab/my-vicinity-repo')
196
+ vicinity = Vicinity.load_from_hub(repo_id='minishlab/my-vicinity-repo')
197
+ ```
198
+
172
199
  Evaluating a backend:
200
+
173
201
  ```python
174
202
  # Use the first 1000 vectors as query vectors
175
203
  query_vectors = vectors[:1000]
@@ -182,14 +210,17 @@ qps, recall = vicinity.evaluate(
182
210
  ```
183
211
 
184
212
  ## Main Features
213
+
185
214
  Vicinity provides the following features:
186
215
  - Lightweight: Minimal dependencies and fast performance.
187
216
  - Flexible Backend Support: Use different backends for vector storage and search.
188
217
  - Serialization: Save and load vector stores for persistence.
218
+ - HuggingFace Hub Integration: Push and load vector stores directly to and from the HuggingFace Hub.
189
219
  - Evaluation: Easily evaluate the performance of different backends.
190
220
  - Easy to Use: Simple and intuitive API.
191
221
 
192
222
  ## Supported Backends
223
+
193
224
  The following backends are supported:
194
225
  - `BASIC`: A simple (exact matching) flat index for vector storage and search.
195
226
  - [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
@@ -208,8 +239,6 @@ The following backends are supported:
208
239
  - `ivfpqr`: Inverted file search with product quantizer and refinement.
209
240
  - [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
241
 
211
-
212
-
213
242
  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
243
 
215
244
  ### Backend Parameters
@@ -241,14 +270,25 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
241
270
  | | `m` | The number of connections between nodes in the tree’s internal data structure. | `16` |
242
271
 
243
272
  ## Installation
273
+
244
274
  The following installation options are available:
275
+
245
276
  ```bash
246
277
  # Install the base package
247
278
  pip install vicinity
248
279
 
249
- # Install all backends
280
+ # Install all integrations and backends
250
281
  pip install vicinity[all]
251
282
 
283
+ # Install all integrations
284
+ pip install vicinity[integrations]
285
+
286
+ # Install specific integrations
287
+ pip install vicinity[huggingface]
288
+
289
+ # Install all backends
290
+ pip install vicinity[backends]
291
+
252
292
  # Install specific backends
253
293
  pip install vicinity[annoy]
254
294
  pip install vicinity[faiss]
@@ -15,14 +15,20 @@
15
15
  <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
16
  <a href="https://pypi.org/project/vicinity/"><img src="https://img.shields.io/pypi/pyversions/vicinity" alt="Supported Python versions"></a>
17
17
  <a href="https://pepy.tech/project/vicinity">
18
- <img src="https://static.pepy.tech/badge/vicinity" alt="Downloads">
18
+ <img src="https://static.pepy.tech/badge/vicinity" alt="Downloads">
19
19
  </a>
20
20
  <a href="https://app.codecov.io/gh/MinishLab/vicinity">
21
- <img src="https://codecov.io/gh/MinishLab/vicinity/graph/badge.svg?token=0MQ2945OZL" alt="Codecov">
21
+ <img src="https://codecov.io/gh/MinishLab/vicinity/graph/badge.svg?token=0MQ2945OZL" alt="Codecov">
22
+ </a>
23
+ <a href="https://discord.gg/4BDPR5nmtK">
24
+ <img src="https://img.shields.io/badge/Join-Discord-5865F2?logo=discord&logoColor=white" alt="Join Discord">
25
+ </a>
26
+ <a href="https://github.com/MinishLab/vicinity/blob/main/LICENSE">
27
+ <img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
22
28
  </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
29
  </h2>
25
30
 
31
+
26
32
  [Quickstart](#quickstart) •
27
33
  [Main Features](#main-features) •
28
34
  [Supported Backends](#supported-backends) •
@@ -30,13 +36,11 @@
30
36
 
31
37
  </div>
32
38
 
33
-
34
39
  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
40
 
36
41
  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
42
 
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.
43
+ 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
44
 
41
45
  ## Quickstart
42
46
 
@@ -44,18 +48,18 @@ Install the package with:
44
48
  ```bash
45
49
  pip install vicinity
46
50
  ```
47
- Optionally, [install any of the supported backends](#installation), or simply install all of them with:
51
+ Optionally, [install specific backends and integrations](#installation), or simply install all of them with:
48
52
  ```bash
49
53
  pip install vicinity[all]
50
54
  ```
51
55
 
52
-
53
56
  The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
57
+
54
58
  ```python
55
59
  import numpy as np
56
60
  from vicinity import Vicinity, Backend, Metric
57
61
 
58
- # Create some dummy data
62
+ # Create some dummy data as strings or other serializable objects
59
63
  items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
60
64
  vectors = np.random.rand(len(items), 128)
61
65
 
@@ -82,12 +86,21 @@ results = vicinity.query(query_vectors, k=3)
82
86
  ```
83
87
 
84
88
  Saving and loading a vector store:
89
+
85
90
  ```python
86
91
  vicinity.save('my_vector_store')
87
92
  vicinity = Vicinity.load('my_vector_store')
88
93
  ```
89
94
 
95
+ 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"`):
96
+
97
+ ```python
98
+ vicinity.push_to_hub(repo_id='minishlab/my-vicinity-repo')
99
+ vicinity = Vicinity.load_from_hub(repo_id='minishlab/my-vicinity-repo')
100
+ ```
101
+
90
102
  Evaluating a backend:
103
+
91
104
  ```python
92
105
  # Use the first 1000 vectors as query vectors
93
106
  query_vectors = vectors[:1000]
@@ -100,14 +113,17 @@ qps, recall = vicinity.evaluate(
100
113
  ```
101
114
 
102
115
  ## Main Features
116
+
103
117
  Vicinity provides the following features:
104
118
  - Lightweight: Minimal dependencies and fast performance.
105
119
  - Flexible Backend Support: Use different backends for vector storage and search.
106
120
  - Serialization: Save and load vector stores for persistence.
121
+ - HuggingFace Hub Integration: Push and load vector stores directly to and from the HuggingFace Hub.
107
122
  - Evaluation: Easily evaluate the performance of different backends.
108
123
  - Easy to Use: Simple and intuitive API.
109
124
 
110
125
  ## Supported Backends
126
+
111
127
  The following backends are supported:
112
128
  - `BASIC`: A simple (exact matching) flat index for vector storage and search.
113
129
  - [HNSW](https://github.com/nmslib/hnswlib): Hierarchical Navigable Small World Graph (HNSW) for ANN search using hnswlib.
@@ -126,8 +142,6 @@ The following backends are supported:
126
142
  - `ivfpqr`: Inverted file search with product quantizer and refinement.
127
143
  - [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
144
 
129
-
130
-
131
145
  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
146
 
133
147
  ### Backend Parameters
@@ -159,14 +173,25 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
159
173
  | | `m` | The number of connections between nodes in the tree’s internal data structure. | `16` |
160
174
 
161
175
  ## Installation
176
+
162
177
  The following installation options are available:
178
+
163
179
  ```bash
164
180
  # Install the base package
165
181
  pip install vicinity
166
182
 
167
- # Install all backends
183
+ # Install all integrations and backends
168
184
  pip install vicinity[all]
169
185
 
186
+ # Install all integrations
187
+ pip install vicinity[integrations]
188
+
189
+ # Install specific integrations
190
+ pip install vicinity[huggingface]
191
+
192
+ # Install all backends
193
+ pip install vicinity[backends]
194
+
170
195
  # Install specific backends
171
196
  pip install vicinity[annoy]
172
197
  pip install vicinity[faiss]
@@ -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",
@@ -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(new_items, new_vector[None, :])
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
- items_to_delete = ["item2", "item4", "item6"]
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
- item3_index = items.index("item3")
293
- item3_vector = vectors[item3_index]
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 "item3" in returned_items
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: