Skip to content

Instantly share code, notes, and snippets.

@mrmaheshrajput
Created July 2, 2023 06:07
Show Gist options
  • Save mrmaheshrajput/be57cea489939650036a998146cf20e7 to your computer and use it in GitHub Desktop.
Save mrmaheshrajput/be57cea489939650036a998146cf20e7 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