Error when reading data in a stream
Nav94 opened this issue · comments
Summary
I am reading a saved faiss model in a streaming fashion during containerized execution in python. I obtain a byte stream of the model and convert it into a faiss::IOReader using:
f = io.BytesIO()
temp = faiss.PyCallbackIOReader(f.read)
temp = faiss.BufferedIOReader(temp)
test_nn = faiss.read_index(temp)
However, I get a runtime error when I am reading a saved faiss model in a stream: Error in faiss::Index* faiss::read_index(faiss::IOReader*, int) at /__w/faiss-wheels/faiss-wheels/faiss/faiss/impl/index_read.cpp:414: Error: 'ret == (1)' failed: read error in : 0 != 1 (Resource temporarily unavailable).
This error does not occur if I just read the file using the filename such as:
test_nn = faiss.read_index("nnscorer_search_index.faiss"),
and am able to run inference with the model this way.
I am not sure if I am missing a step when I am converting the byte object or is there a problem with the streamed data?
Platform
OS: macOS 12.5.1
Faiss version: 1.7.1
Installed from: pip
Faiss compilation options: pip install faiss
Running on:
- CPU
- GPU
Interface:
- C++
- Python
Reproduction instructions
The original model, "nnscorer_search_index.faiss" was saved using the same faiss version, 1.7.1.
It is likely due to the reader implementation. You should make sure the read function waits until all the data is ready, possibly looping over reads from the underlying channel.