I receive this error
Traceback (most recent call last):
File "server.py", line 6, in <module>
searcher.init()
File "/usr/local/src/myproj/MyProj.MatchingServer/searcher.py", line 52, in init
self.index = self.build_index(ids, vectors)
File "/usr/local/src/myproj/MyProj.MatchingServer/searcher.py", line 63, in build_index
print(index.search(v, 3))
File "/home/levi/anaconda3/envs/matchingserver/lib/python3.6/site-packages/faiss/__init__.py", line 115, in replacement_search
n, d = x.shape
ValueError: not enough values to unpack (expected 2, got 1)
When I call the following Python test code in my project:
def build_index(self, ids, vectors):
dimension = len(vectors[0]) # <-- Vectors are of dimension 300
index = faiss.IndexFlatL2(dimension)
index.add(vectors)
print("Database created with the following element count: ")
print(index.ntotal)
print("Searching for sentence: ")
print(self.test_sentence)
v = np.array(self.fast_text.get_sentence_vector(self.test_sentence))
print(index.search(v, 3)) # <-- Problem occurs here
# ...
The error appears to occur inside of index.search(v, 3) at this point in Faiss
OS: Ubuntu 16.04
Faiss version: Conda version: faiss-cpu - 1.2.1 - py36_cuda0.0_2
Faiss compilation options: N/A
Running on :
This should be reproducible simply by calling index.search. I'm just starting out with Faiss but am happy to help anyone trying to reproduce this should it not be so straightforward.
I managed to solve this on my own. The problem was that I needed to pass an array of 1-dimensional vectors to search instead of just the single one-dimensional vector. So
v = np.array([self.fast_text.get_sentence_vector(self.test_sentence)])
would have done the trick.
Most helpful comment
I managed to solve this on my own. The problem was that I needed to pass an array of 1-dimensional vectors to
searchinstead of just the single one-dimensional vector. Sowould have done the trick.