Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error while adding custom index using IndexIDMap #1215

Closed
ravitashaw opened this issue May 14, 2020 · 2 comments
Closed

Error while adding custom index using IndexIDMap #1215

ravitashaw opened this issue May 14, 2020 · 2 comments

Comments

@ravitashaw
Copy link

ravitashaw commented May 14, 2020

Hi, I'm facing difficulty in adding custom index (filename) to the IndexMap. The objective of the task is to add feature vectors for indexing and while searching the output should be filename rather than an ordinal index. The test code is:

def test_faiss():
    d = 20
    nb = 1
    file_name = 'test.png'
    xb = np.random.random((nb, d)).astype('float32')
    ids = np.array(file_name).reshape(nb, 1)
    index = faiss.IndexFlatL2(d)
    index = faiss.IndexIDMap(index)
    index.add_with_ids(xb, ids)
    return

and, the error is:

assert ids.shape == (n, ), 'not same nb of vectors as ids'
AssertionError: not same nb of vectors as ids

I'm using only 1 vector for indexing, so my ids also has shape of (1, 1). Is there something missing or misunderstood?

@ravitashaw
Copy link
Author

I figured out from #641

The above code works fine when the ids is replaced as an integer array. The custom index mapping need to be manually managed.

But the error seems misleading, the shape of ids is ok but the datatype.

@SlytherinWyne
Copy link

I'm encountering the same issue, the dimension of xb and ids seem can not be 1, quite weird, annoying error...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants