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

Fix panic #1904

Merged
merged 2 commits into from
Nov 10, 2023
Merged

Fix panic #1904

merged 2 commits into from
Nov 10, 2023

Conversation

CascadingRadium
Copy link
Member

need this check because i accidentally used the API without giving a k value it panicked because in

index.go in go-faiss you have

func (idx *faissIndex) Search(x []float32, k int64) (
	distances []float32, labels []int64, err error,
	) {
n := len(x) / idx.D()
distances = make([]float32, int64(n)*k)
labels = make([]int64, int64(n)*k)
if c := C.faiss_Index_search(
	idx.idx,
	C.idx_t(n),
	(*C.float)(&x[0]),
	C.idx_t(k),
	(*C.float)(&distances[0]),
	(*C.idx_t)(&labels[0]),

so if either k is 0 or query vector is nil/empty we get a panic because distances[0] is invalid operation

@CascadingRadium CascadingRadium changed the title Fix panicfor0k Fix panic Nov 10, 2023
@abhinavdangeti abhinavdangeti merged commit d06a3a9 into unstable Nov 10, 2023
0 of 9 checks passed
@abhinavdangeti abhinavdangeti deleted the fix-panicfor0k branch November 10, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants