1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""pyvicinity: multi-algorithm approximate nearest-neighbor search (Rust-backed).
Python bindings for the ``vicinity`` Rust crate (crates.io). The PyPI
distribution is named ``pyvicinity`` because the bare ``vicinity`` name
is held on PyPI by an unrelated project.
Quick start::
import numpy as np
from pyvicinity import HNSWIndex, DistanceMetric
rng = np.random.default_rng(0)
vectors = rng.standard_normal((10_000, 128), dtype=np.float32)
index = HNSWIndex(
dim=128,
metric=DistanceMetric.Cosine,
auto_normalize=True, # normalizes both inserts and queries
seed=42, # reproducible build order
)
index.add_items(vectors)
index.build()
ids, dists = index.search(vectors[0], k=10)
batch_ids, batch_dists = index.batch_search(vectors[:32], k=10)
"""
=