Skip to content

Instantly share code, notes, and snippets.

@bet02024
Forked from mrmaheshrajput/Faiss ANN.py
Created September 15, 2023 17:38
Show Gist options
  • Save bet02024/f726bcc6d0232ab246376ac88a385b4c to your computer and use it in GitHub Desktop.
Save bet02024/f726bcc6d0232ab246376ac88a385b4c to your computer and use it in GitHub Desktop.
try:
import faiss
except:
!pip install faiss-cpu -q
import faiss
# Build the index
d = embeddings.shape[1] # Dimension
index = faiss.IndexFlatL2(d)
# Add vectors to the index
index.add(embeddings)
print(index.ntotal)
# Sanity Check
# "model" is our Sentence Transformer model
xq = model.encode(["I am not able to find my issue, where is it gone?"])
k = 1
D, I = index.search(xq, k)
print(corpus[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment