Skip to content

Instantly share code, notes, and snippets.

@mdouze
Created August 22, 2019 12:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mdouze/e30e8f57a98ed841c082cc68baa14b4a to your computer and use it in GitHub Desktop.
Save mdouze/e30e8f57a98ed841c082cc68baa14b4a to your computer and use it in GitHub Desktop.
###########################################
# serialization of indexes to byte arrays
###########################################
def serialize_index(index):
""" convert an index to a numpy uint8 array """
writer = faiss.VectorIOWriter()
faiss.write_index(index, writer)
return faiss.vector_to_array(writer.data)
def deserialize_index(data):
reader = faiss.VectorIOReader()
faiss.copy_array_to_vector(data, reader.data)
return faiss.read_index(reader)
@QwertyJack
Copy link

Eureka!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment