Skip to content

Conversation

metonymic-smokey
Copy link
Member

@metonymic-smokey metonymic-smokey commented May 9, 2025

  1. Generalise the Add(), Ntotal(), D(), and AddWithIDs() functions to accommodate binary vector indexes.
  2. Generalise the Train(), SetNProbe() functions to accommodate BIVF indexes.
  3. Add the IVFDistCompute() function to perform a distance computation between a query vector and the vector corresponding to the specified ID.
  4. Add functionality to read and write binary indexes into buffers.
  5. Add functionality to search binary vector indexes, similar to the one offered for IVF indexes.

@metonymic-smokey metonymic-smokey force-pushed the bq branch 2 times, most recently from 0299389 to 4132f92 Compare May 12, 2025 08:56
@metonymic-smokey metonymic-smokey marked this pull request as ready for review May 12, 2025 15:45
@metonymic-smokey metonymic-smokey changed the title MB-62985 - Add support for binary quantised vectors. MB-62985 - Add functionality to support binary quantised vectors. May 12, 2025

go 1.21
go 1.22

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was changed in a recent patch so update.

index.go Outdated
return int(C.faiss_IndexBinary_d(idx.idxBinary))
}

func (idx *faissIndex) IsTrained() bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If index is binary then calling this method would panic right as you should be calling

return C.faiss_IndexBinary_is_trained(idx.idx) != 0

https://github.com/blevesearch/faiss/blob/b3d4e00a69425b95e0b283da7801efc9f66b580d/c_api/IndexBinary_c.h#L35

index.go Outdated
return
}

func (idx *faissIndex) SearchBinaryWithIDs(x []uint8, k int64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • please add all binary index related methods(and the struct) to a new file, after splitting the interface thanks
  • The method naming is off, youre just searching the binary vector with a given K - No IDs for an include selector is given, Rename to Just SearchBinary

index.go Outdated
}
defer searchParams.Delete()

if c := C.faiss_IndexBinary_search_with_params(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code block can be reused. Add searchBinaryWithParams method similar to searchWithParams

tempBuf := (*C.uchar)(nil)
bufSize := C.size_t(0)

if c := C.faiss_write_index_binary_buf(
Copy link
Member

@CascadingRadium CascadingRadium Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot of code duplication here; following my earlier comment of split interfaces, you can just reuse the existing method

func WriteIndexIntoBuffer(idx BaseIndex) ([]byte, error) {
// the values to be returned by the faiss APIs
	tempBuf := (*C.uchar)(nil)
	bufSize := C.size_t(0)

	switch i := idx.(type) {
	case BinaryIndex: // Child Interface check - Will be binary index struct if has the TrainBinary method
		status = C.faiss_write_index_binary_buf(
			(*C.FaissIndexBinary)(i.(*binaryIndex).idx),
			&bufSize,
			&tempBuf,
		)
	case FloatIndex:  // Child Interface check - Will be float index struct if has the IVF methods (example
		status = C.faiss_write_index_buf(
			(*C.FaissIndex)(i.(*floatIndex).idx),
			&bufSize,
			&tempBuf,
		)
	default:
		return nil, fmt.Errorf("unsupported index type: %T", idx)
	}
// Rest of the method unchanged

index_io.go Outdated
return &IndexImpl{&idx}, nil
}

func ReadBinaryIndexFromBuffer(buf []byte, ioflags int) (*IndexImpl, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not need a new method, just pass a flag, maybe expose a enum to zapx that can

type IndexType int

const (
    FloatIndexType IndexType = iota // 0
    BinaryIndexType                  // 1
)

func ReadIndexFromBuffer(buf []byte, ioflags int, idxType IndexType) () {
``

@metonymic-smokey metonymic-smokey force-pushed the bq branch 2 times, most recently from a961c59 to 5dd343f Compare June 6, 2025 11:57
@metonymic-smokey metonymic-smokey force-pushed the bq branch 2 times, most recently from b779132 to 2c060eb Compare June 9, 2025 14:20
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