Skip to content

numb3r3/hnsw_cpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hnsw_cpy

A scalable HNSW binary vector index in Cython.

Install

pip install src/.

Test

To run all unit tests:

pip install src/.[test]
python -m unittest tests/*.py

Lint

pylint src/**/*.py

Usage

Two core functions: index(), query().

from hnsw_cpy import HnswIndex
import numpy as np


bytes_num = 8

index = HnswIndex(bytes_num=bytes_num)

# random generate 10000 vectors
data_size = 10000
for i in range(data_size):
    data = np.random.randint(1, 255, data_dim, dtype=np.uint8).tobytes()
    index.index(i, data)

# build a random query
query = np.random.randint(1, 255, data_dim, dtype=np.uint8).tobytes()

# find the top 10 result
result = index.query(query, 10)

About

A scalable HNSW binary vector index in Cython.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published