Created
August 11, 2022 19:15
-
-
Save Spartee/3ca231066d4e6862b2271fe3ba259f61 to your computer and use it in GitHub Desktop.
Example of creating a flat index in Redis with redis-py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from redis import Redis | |
from redis.commands.search.field import VectorField, TagField | |
# Function to create a flat (brute-force) search index with Redis/RediSearch | |
# Could also be a HNSW index | |
def create_flat_index(redis_conn: Redis, number_of_vectors: int, distance_metric: str='COSINE'): | |
image_field = VectorField("img_vector", | |
"FLAT", {"TYPE": "FLOAT32", | |
"DIM": 512, | |
"DISTANCE_METRIC": distance_metric, | |
"INITIAL_CAP": number_of_vectors, | |
"BLOCK_SIZE": number_of_vectors}) | |
redis_conn.ft().create_index([image_field]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment