How to do a batch search in Redis?

97 Views Asked by At

I use Redis as a vector database. I want to make multiple search queries, but I can't find how to do it in documentation. Now it looks like:

client = redis.Redis(host="localhost", port=6379, decode_responses=True)
# insert data

# search
query = (
    Query("*=>[KNN 2 @vector $vec as score]")
     .sort_by("score")
     .return_fields("id", "score")
     .paging(0, 2)
     .dialect(2)
)

query_params = {
    "vec": np.random.rand(VECTOR_DIMENSIONS).astype(np.float32).tobytes()
}
r.ft(INDEX_NAME).search(query, query_params).docs

This example I take from redis-py documentation: documentation.

But it is only for one query per search. I need something like that:

query_params = {
    "vec": [np.random.rand(VECTOR_DIMENSIONS).astype(np.float32).tobytes(),
np.random.rand(VECTOR_DIMENSIONS).astype(np.float32).tobytes()]
}
r.ft(INDEX_NAME).search(query, query_params).docs

Is it possible?

0

There are 0 best solutions below