You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import numpy as np
import faiss
# Define the dimension of the vectors
d = 64
# Define the size of the database
nb = 100000
# Define the number of queries
nq = 10000
# Set the random seed for reproducibility
np.random.seed(1234)
# Generate random vectors for the database
xb = np.random.random((nb, d)).astype('float32')
# Add a unique identifier to each vector in the database
xb[:, 0] += np.arange(nb) / 1000.
# Generate random vectors for the queries
xq = np.random.random((nq, d)).astype('float32')
# Add a unique identifier to each vector in the queries
xq[:, 0] += np.arange(nq) / 1000.
# Create an HNSW index
index = faiss.IndexHNSWFlat(d, 32)
# Add the vectors to the index
index.add(xb)
# Perform a search
D, I = index.search(xq, 4)
# Print the results
print(I[:5]) # Neighbors of the first 5 queries
print(I[-5:]) # Neighbors of the last 5 queries
Summary
There are tutorials present for Flat, and IVF but not for HNSW. I believe having a tutorial on HNSW would be helpful.
The text was updated successfully, but these errors were encountered: