I'm just starting using redis and I'm trying to do a vector search. Right now I have setup the redis server with the redisearch module on ubuntu using wsl (My machine's OS is windows 10). This is the python code I have
import redis
import numpy as np
redis_client = redis.Redis(host="localhost", port=6379)
#index_name = 'vector_index'
vectors = [
("vector1", np.array([1, 2, 3])),
("vector2", np.array([4, 5, 6])),
("vector3", np.array([7, 8, 9]))
]
for name, vector in vectors:
vector_str = ",".join(map(str, vector))
redis_client.execute_command('HSET', name, 'vector', vector_str)
redis_client.execute_command('FT.CREATE', 'vector_index', 'SCHEMA', 'vector', 'VECTOR', 'HNSW', '16', 'TYPE', 'FLOAT64', 'DIM', '3')
query_vector = np.array([2, 3, 4])
query = query_vector.tobytes
results = redis_client.execute_command('FT.SEARCH', query, 'SORTBY', 'score', 'LIMIT', 0, 3)
print("Search results:")
for result in results[1::2]:
document_id = result[1]
score = result[-1]
print(f"Document ID: {document_id}, Score: {score}")
I was able to add the vectors in the database with the HSET command, but every time it gets to the point where it needs to create the index I always get the message "redis.exceptions.ResponseError: Could not parse field spec". I already tried typing the FT.CREATE command directly into the redis cli multiple times in multiple different sintaxes, but none of them worked and I just got the same message. What can I do to create the index so I can search the vectors I have in there with a query vector? Btw this is just a starter project, I'm trying to make it work so then I can move onto image embeddings and VSS.
The best example for redis-py and vectors can be found here: https://redis.readthedocs.io/en/stable/examples/search_vector_similarity_examples.html
Reposting from that page:
Follow that recipe and you should be good!