vicinity 0.4.3__tar.gz → 0.4.5__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 (40) hide show
  1. {vicinity-0.4.3 → vicinity-0.4.5}/.github/workflows/ci.yaml +1 -3
  2. vicinity-0.4.5/.github/workflows/release.yaml +40 -0
  3. vicinity-0.4.5/CITATION.cff +27 -0
  4. {vicinity-0.4.3 → vicinity-0.4.5}/PKG-INFO +20 -5
  5. {vicinity-0.4.3 → vicinity-0.4.5}/README.md +17 -1
  6. {vicinity-0.4.3 → vicinity-0.4.5}/pyproject.toml +5 -3
  7. {vicinity-0.4.3 → vicinity-0.4.5}/tests/test_vicinity.py +31 -0
  8. {vicinity-0.4.3 → vicinity-0.4.5}/uv.lock +119 -314
  9. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/__init__.py +2 -3
  10. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/annoy.py +9 -10
  11. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/base.py +2 -2
  12. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/basic.py +14 -14
  13. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/faiss.py +8 -8
  14. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/hnsw.py +10 -10
  15. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/pynndescent.py +10 -10
  16. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/usearch.py +22 -11
  17. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/backends/voyager.py +12 -12
  18. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/datatypes.py +10 -7
  19. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/integrations/huggingface.py +3 -1
  20. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/utils.py +2 -3
  21. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/version.py +1 -1
  22. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/vicinity.py +21 -19
  23. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity.egg-info/PKG-INFO +20 -5
  24. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity.egg-info/SOURCES.txt +4 -0
  25. vicinity-0.4.5/vicinity.egg-info/scm_file_list.json +35 -0
  26. vicinity-0.4.5/vicinity.egg-info/scm_version.json +8 -0
  27. {vicinity-0.4.3 → vicinity-0.4.5}/.gitignore +0 -0
  28. {vicinity-0.4.3 → vicinity-0.4.5}/.pre-commit-config.yaml +0 -0
  29. {vicinity-0.4.3 → vicinity-0.4.5}/LICENSE +0 -0
  30. {vicinity-0.4.3 → vicinity-0.4.5}/Makefile +0 -0
  31. {vicinity-0.4.3 → vicinity-0.4.5}/assets/images/vicinity_logo.png +0 -0
  32. {vicinity-0.4.3 → vicinity-0.4.5}/setup.cfg +0 -0
  33. {vicinity-0.4.3 → vicinity-0.4.5}/tests/conftest.py +0 -0
  34. {vicinity-0.4.3 → vicinity-0.4.5}/tests/test_utils.py +0 -0
  35. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/__init__.py +0 -0
  36. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/integrations/dataset_card_template.md +0 -0
  37. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity/py.typed +0 -0
  38. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity.egg-info/dependency_links.txt +0 -0
  39. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity.egg-info/requires.txt +0 -0
  40. {vicinity-0.4.3 → vicinity-0.4.5}/vicinity.egg-info/top_level.txt +0 -0
@@ -12,10 +12,8 @@ jobs:
12
12
  strategy:
13
13
  matrix:
14
14
  os: ["ubuntu-latest", "windows-latest"]
15
- python-version: ["3.9", "3.10", "3.11", "3.12"]
15
+ python-version: ["3.10", "3.11", "3.12"]
16
16
  exclude:
17
- - os: windows-latest
18
- python-version: "3.9"
19
17
  - os: windows-latest
20
18
  python-version: "3.11"
21
19
  - os: windows-latest
@@ -0,0 +1,40 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ build:
8
+ name: Build distribution
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
12
+
13
+ - name: Install uv
14
+ uses: astral-sh/setup-uv@d0d8abe699bfb85fec6de9f7adb5ae17292296ff
15
+
16
+ - name: Build package
17
+ run: uv build
18
+
19
+ - name: Upload dist
20
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+
25
+ publish:
26
+ name: Publish to PyPI
27
+ needs: build
28
+ runs-on: ubuntu-latest
29
+ environment: release
30
+ permissions:
31
+ id-token: write
32
+ steps:
33
+ - name: Download dist
34
+ uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
35
+ with:
36
+ name: dist
37
+ path: dist/
38
+
39
+ - name: Publish to PyPI
40
+ uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
@@ -0,0 +1,27 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use Vicinity in your research, please cite it as below."
3
+ title: "Vicinity: Lightweight Nearest Neighbors with Flexible Backends"
4
+ authors:
5
+ - family-names: "Tulkens"
6
+ given-names: "Stephan"
7
+ - family-names: "van Dongen"
8
+ given-names: "Thomas"
9
+ doi: 10.5281/zenodo.17265874
10
+ license: MIT
11
+ url: "https://github.com/MinishLab/vicinity"
12
+ repository-code: "https://github.com/MinishLab/vicinity"
13
+ date-released: "2024-11-09"
14
+
15
+ preferred-citation:
16
+ type: software
17
+ title: "Vicinity: Lightweight Nearest Neighbors with Flexible Backends"
18
+ authors:
19
+ - family-names: "Tulkens"
20
+ given-names: "Stephan"
21
+ - family-names: "van Dongen"
22
+ given-names: "Thomas"
23
+ year: 2024
24
+ publisher: Zenodo
25
+ doi: 10.5281/zenodo.17265874
26
+ url: "https://github.com/MinishLab/vicinity"
27
+ license: MIT
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vicinity
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: Lightweight Nearest Neighbors with Flexible Backends
5
- Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
5
+ Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomasvdongen@proton.me>
6
6
  License: MIT License
7
7
 
8
8
  Copyright (c) 2024 The Minish Lab
@@ -35,11 +35,10 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
35
35
  Classifier: Topic :: Software Development :: Libraries
36
36
  Classifier: License :: OSI Approved :: MIT License
37
37
  Classifier: Programming Language :: Python :: 3 :: Only
38
- Classifier: Programming Language :: Python :: 3.9
39
38
  Classifier: Programming Language :: Python :: 3.10
40
39
  Classifier: Programming Language :: Python :: 3.11
41
40
  Classifier: Programming Language :: Python :: 3.12
42
- Requires-Python: >=3.9
41
+ Requires-Python: >=3.10
43
42
  Description-Content-Type: text/markdown
44
43
  Requires-Dist: numpy
45
44
  Requires-Dist: orjson
@@ -254,7 +253,7 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
254
253
  | | `m` | Number of connections per layer. | `16` |
255
254
  | **PYNNDESCENT** | `metric` | Similarity metric to use (`cosine`, `euclidean`, `manhattan`). | `"cosine"` |
256
255
  | | `n_neighbors` | Number of neighbors to use for search. | `15` |
257
- | **USEARCH** | `metric` | Similarity metric to use (`cos`, `ip`, `l2sq`, `hamming`, `tanimoto`). | `"cos"` |
256
+ | **USEARCH** | `metric` | Similarity metric to use (`cos`, `ip`, `l2sq`, `hamming`, `tanimoto`). `hamming` and `tanimoto` take uint8 vectors bit-packed with `np.packbits`. | `"cos"` |
258
257
  | | `connectivity` | Number of connections per node in the graph. | `16` |
259
258
  | | `expansion_add` | Number of candidates considered during graph construction. | `128` |
260
259
  | | `expansion_search` | Number of candidates considered during search. | `64` |
@@ -294,3 +293,19 @@ pip install vicinity[voyager]
294
293
  ## License
295
294
 
296
295
  MIT
296
+
297
+ ## Citing
298
+
299
+ If you use Vicinity in your research, please cite the following:
300
+
301
+ ```bibtex
302
+ @software{minishlab2024vicinity,
303
+ author = {Stephan Tulkens and {van Dongen}, Thomas},
304
+ title = {Vicinity: Lightweight Nearest Neighbors with Flexible Backends},
305
+ year = {2024},
306
+ publisher = {Zenodo},
307
+ doi = {10.5281/zenodo.17265874},
308
+ url = {https://github.com/MinishLab/vicinity},
309
+ license = {MIT}
310
+ }
311
+ ```
@@ -158,7 +158,7 @@ NOTE: the ANN backends do not support dynamic deletion. To delete items, you nee
158
158
  | | `m` | Number of connections per layer. | `16` |
159
159
  | **PYNNDESCENT** | `metric` | Similarity metric to use (`cosine`, `euclidean`, `manhattan`). | `"cosine"` |
160
160
  | | `n_neighbors` | Number of neighbors to use for search. | `15` |
161
- | **USEARCH** | `metric` | Similarity metric to use (`cos`, `ip`, `l2sq`, `hamming`, `tanimoto`). | `"cos"` |
161
+ | **USEARCH** | `metric` | Similarity metric to use (`cos`, `ip`, `l2sq`, `hamming`, `tanimoto`). `hamming` and `tanimoto` take uint8 vectors bit-packed with `np.packbits`. | `"cos"` |
162
162
  | | `connectivity` | Number of connections per node in the graph. | `16` |
163
163
  | | `expansion_add` | Number of candidates considered during graph construction. | `128` |
164
164
  | | `expansion_search` | Number of candidates considered during search. | `64` |
@@ -198,3 +198,19 @@ pip install vicinity[voyager]
198
198
  ## License
199
199
 
200
200
  MIT
201
+
202
+ ## Citing
203
+
204
+ If you use Vicinity in your research, please cite the following:
205
+
206
+ ```bibtex
207
+ @software{minishlab2024vicinity,
208
+ author = {Stephan Tulkens and {van Dongen}, Thomas},
209
+ title = {Vicinity: Lightweight Nearest Neighbors with Flexible Backends},
210
+ year = {2024},
211
+ publisher = {Zenodo},
212
+ doi = {10.5281/zenodo.17265874},
213
+ url = {https://github.com/MinishLab/vicinity},
214
+ license = {MIT}
215
+ }
216
+ ```
@@ -3,9 +3,9 @@ name = "vicinity"
3
3
  description = "Lightweight Nearest Neighbors with Flexible Backends"
4
4
  readme = { file = "README.md", content-type = "text/markdown" }
5
5
  dynamic = ["version"]
6
- requires-python = ">=3.9"
6
+ requires-python = ">=3.10"
7
7
  license = { file = "LICENSE" }
8
- authors = [{ name = "Stéphan Tulkens", email = "stephantul@gmail.com"}, {name = "Thomas van Dongen", email = "thomas123@live.nl"}]
8
+ authors = [{ name = "Stéphan Tulkens", email = "stephantul@gmail.com"}, {name = "Thomas van Dongen", email = "thomasvdongen@proton.me"}]
9
9
 
10
10
  classifiers = [
11
11
  "Development Status :: 4 - Beta",
@@ -15,7 +15,6 @@ classifiers = [
15
15
  "Topic :: Software Development :: Libraries",
16
16
  "License :: OSI Approved :: MIT License",
17
17
  "Programming Language :: Python :: 3 :: Only",
18
- "Programming Language :: Python :: 3.9",
19
18
  "Programming Language :: Python :: 3.10",
20
19
  "Programming Language :: Python :: 3.11",
21
20
  "Programming Language :: Python :: 3.12",
@@ -143,3 +142,6 @@ license-files = []
143
142
 
144
143
  [tool.setuptools.dynamic]
145
144
  version = {attr = "vicinity.version.__version__"}
145
+
146
+ [tool.uv]
147
+ exclude-newer = "1 week"
@@ -333,3 +333,34 @@ def test_vicinity_evaluate(vicinity_instance: Vicinity, vectors: np.ndarray) ->
333
333
  vicinity_instance.backend.arguments.metric = "manhattan"
334
334
  with pytest.raises(ValueError):
335
335
  vicinity_instance.evaluate(vectors, query_vectors)
336
+
337
+
338
+ @pytest.mark.parametrize("metric", ["hamming", "tanimoto"])
339
+ def test_vicinity_usearch_binary_metrics(tmp_path: Path, metric: str) -> None:
340
+ """
341
+ Test that the usearch backend supports binary metrics on bit-packed vectors.
342
+
343
+ :param tmp_path: Temporary directory for saving and loading.
344
+ :param metric: The binary metric to use.
345
+ """
346
+ bits = np.random.default_rng(42).integers(0, 2, size=(50, 64)).astype(bool)
347
+ packed = np.packbits(bits, axis=1)
348
+ items = [str(i) for i in range(len(bits))]
349
+ vicinity = Vicinity.from_vectors_and_items(packed, items, backend_type=Backend.USEARCH, metric=metric)
350
+ assert vicinity.dim == packed.shape[1]
351
+
352
+ if metric == "hamming":
353
+ expected = (bits[0] != bits).sum(axis=1)
354
+ else:
355
+ expected = 1 - (bits[0] & bits).sum(axis=1) / (bits[0] | bits).sum(axis=1)
356
+ ((_, distance),) = vicinity.query(packed[:1], k=1)[0]
357
+ ((_, farthest),) = vicinity.query(packed[:1], k=len(items))[0][-1:]
358
+ assert distance == pytest.approx(0)
359
+ assert farthest == pytest.approx(expected.max(), abs=1e-5)
360
+
361
+ vicinity.insert(["new"], packed[:1])
362
+ vicinity.save(tmp_path / "binary")
363
+ assert Vicinity.load(tmp_path / "binary").query(packed[:1], k=3)[0] == vicinity.query(packed[:1], k=3)[0]
364
+
365
+ with pytest.raises(ValueError, match="bit-packed"):
366
+ Vicinity.from_vectors_and_items(bits.astype(np.float32), items, backend_type=Backend.USEARCH, metric=metric)