Storing the embeddings
Vectors are numerical representations of unstructured data and the transformation is performed using AI and ML models. Redis Stack can perform VSS on vectors that are locally stored. In this section, you will learn how to store vectors, a capability that turns Redis Stack into a de facto vector database.
Hashes
Vectors can be stored in Hash data structures or JSON documents as attributes contained in such document formats. Storing vectors in Hashes is a one-command operation that involves leveraging the NumPy library for scientific computing and its conversion utility, astype, which casts the vector to the desired format – in this case, a binary blob. Back to the former embedding generation example, we can now convert the vector and print a portion as follows:
import numpy as np blob = embedding.astype(np.float32).tobytes() print(blob[0 : 50])
This script outputs the following:
b'\x99\xcf\xce;\x87\x08\xaa\xbbe\x98\x1a\xbdZ\xde\xb8\xbdx...