Skip to content

Instantly share code, notes, and snippets.

@allenanie
Forked from mdouze/index_to_array.py
Created February 13, 2020 17:21
Show Gist options
  • Save allenanie/cbaf512d8ad4d0bad8b1697ac4d79b53 to your computer and use it in GitHub Desktop.
Save allenanie/cbaf512d8ad4d0bad8b1697ac4d79b53 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment