Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

IDSelectorNot causing "segmentation fault" when calling search() #3090

Closed
2 of 4 tasks
plurch opened this issue Oct 11, 2023 · 3 comments
Closed
2 of 4 tasks

IDSelectorNot causing "segmentation fault" when calling search() #3090

plurch opened this issue Oct 11, 2023 · 3 comments
Labels

Comments

@plurch
Copy link

plurch commented Oct 11, 2023

Summary

I am getting a "segmentation fault" error which is crashing the python interpreter when using IDSelectorNot to exclude some IDs from the search() results. See below for a script to reproduce the issue.

Please let me know if I am doing something incorrectly - thanks!

Platform

OS: macOS 13.5 (Ventura) / Apple Silicon

Faiss version: 1.7.4

Installed from: conda / python 3.11

Faiss compilation options: n/a

Running on:

  • CPU
  • GPU

Interface:

  • C++
  • Python

Reproduction instructions

import faiss
import numpy as np

print(f'faiss version: {faiss.__version__}')

vecs = np.random.rand(10000, 50).astype(np.float32)
vecs_normalized = np.copy(vecs)
faiss.normalize_L2(vecs_normalized)

index_faiss = faiss.IndexHNSWFlat(vecs_normalized.shape[1], 32, faiss.METRIC_INNER_PRODUCT)
index_faiss.add(vecs_normalized)

query_vec = vecs_normalized[0].reshape(1, -1)
top_k = 20

# this works fine
cos_sims, idx_results = index_faiss.search(query_vec, top_k)
print(f'base idx_results: {idx_results}')

# this also works fine
params_include = faiss.SearchParametersHNSW(sel = faiss.IDSelectorBatch([3195, 1935]))
cos_sims, idx_results = index_faiss.search(query_vec, top_k, params=params_include)
print(f'params_include idx_results: {idx_results}')

# Error: "segmentation fault" when calling search()
params_exclude = faiss.SearchParametersHNSW(sel = faiss.IDSelectorNot(faiss.IDSelectorBatch([3195, 1935])))
cos_sims, idx_results = index_faiss.search(query_vec, top_k, params=params_exclude)
print(f'params_exclude idx_results: {idx_results}')
@mdouze
Copy link
Contributor

mdouze commented Oct 11, 2023

I can repro, it's an object ownership bug. Will fix. In the meantime to work around it, do

sel1 = faiss.IDSelectorBatch([3195, 1935])
sel2 = faiss.IDSelectorNot(sel1)
params_exclude = faiss.SearchParametersHNSW(sel = sel2)
cos_sims, idx_results = index_faiss.search(query_vec, top_k, params=params_exclude)
print(f'params_exclude idx_results: {idx_results}')

@mdouze mdouze added the bug label Oct 11, 2023
@plurch
Copy link
Author

plurch commented Oct 12, 2023

Thanks for the quick response and workaround solution! I tested the workaround and it works as expected without an error. 👍

@mdouze
Copy link
Contributor

mdouze commented Nov 15, 2023

Was fixed in current version

@mdouze mdouze closed this as completed Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants