Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tutorial for IndexHNSW #3379

Open
JayjeetAtGithub opened this issue Apr 21, 2024 · 3 comments
Open

Add a tutorial for IndexHNSW #3379

JayjeetAtGithub opened this issue Apr 21, 2024 · 3 comments

Comments

@JayjeetAtGithub
Copy link
Contributor

Summary

There are tutorials present for Flat, and IVF but not for HNSW. I believe having a tutorial on HNSW would be helpful.

@mdouze
Copy link
Contributor

mdouze commented Apr 23, 2024

right, adding this as enhancement.

@hammad7
Copy link

hammad7 commented Apr 30, 2024

@JayjeetAtGithub

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

@mlomeli1
Copy link
Contributor

Re-opening since the python tutorial is pending.

@mlomeli1 mlomeli1 reopened this Apr 30, 2024
abhinavdangeti pushed a commit to blevesearch/faiss that referenced this issue Jul 12, 2024
…rch#3381)

Summary:
Fixes facebookresearch#3379

Pull Request resolved: facebookresearch#3381

Reviewed By: junjieqi

Differential Revision: D56570120

Pulled By: kuarora

fbshipit-source-id: 758ea4ab866609d6dd5621e6e6ffda583ba52503
aalekhpatel07 pushed a commit to aalekhpatel07/faiss that referenced this issue Oct 17, 2024
…rch#3381)

Summary:
Fixes facebookresearch#3379

Pull Request resolved: facebookresearch#3381

Reviewed By: junjieqi

Differential Revision: D56570120

Pulled By: kuarora

fbshipit-source-id: 758ea4ab866609d6dd5621e6e6ffda583ba52503
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants