Bulk get tensors
eKirad opened this issue · 2 comments
According to the documentation, currently (with the latest release), there is no possibility to bulk get tensor objects, for instance, by a given keyspace. If one wants to fetch, let's say n tensors, what is the current best solution to do so in an efficient manner? (besides the "usual" one of looping over all the tensor objects and fetching every single one inside). Is there a way to achieve a better performance here?
As a reference, I would like to point out the official RedisGears
documentation and the option to use the redisAI
module there. One can see that the functional API of the redisAI
module contains (among many others) the following method: mgetTensorsFromKeyspace(tensors: List[str]) -> List[PyTensor]
. Is there a way to achieve something like this with redisai-py
? If not, what are the alternatives (besides the one mentioned above)?
Thanks in advance!
Hey @eKirad, the best solution for getting n
tensors would probably be using Redis pipelining, which allows sending multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step. This is also what mgetTensorsFromKeyspace
API is doing under the hood raughly... So the implementation should be something like that:
def bulk_get_tensors(tensors_list):
con = redisai.Client()
pipe = con.pipeline(transaction=False)
for tensor in tensors_list
pipe.tensorget(tensor)
result = pipe.execute()
where result
should be a list containing the corresponding replies to every tensorget
command.