CH-Abhinav opened a new pull request, #17044:
URL: https://github.com/apache/lucene/pull/17044

   ### Description
   Addresses point (2) of #15287: Add byte vector support to the Faiss vector 
codec (`FaissKnnVectorsFormat`).
   
   Previously, `FaissKnnVectorsFormat` only supported `VectorEncoding.FLOAT32`, 
throwing `UnsupportedOperationException("Byte vectors not supported")` when 
indexing, merging, reading, or searching `VectorEncoding.BYTE` fields 
(`KnnByteVectorField`).
   
   ### Changes
   1. **FaissLibrary & Native Wrapper Integration**:
      - Extended `FaissLibrary` with `createIndex(..., ByteVectorValues, ...)` 
and `search(byte[], ...)`.
      - Converted signed bytes in `[-128, 127]` to floats losslessly when 
copying into native memory segments, since Faiss's C API functions 
(`faiss_Index_add_with_ids`, `faiss_Index_search`) accept `float*`.
      - Guarded empty segment handling (`if (size > 0)`) in `buildIndex` to 
properly support segments with 0 live vectors.
      - Passed `VectorEncoding` to `readIndex(...)` so `Index` can adapt 
distance-to-score scaling per encoding without any file format changes.
      - Handled Lucene's scaled dot product metric for byte vectors (`0.5f + 
distance / (dim * (1 << 15))`) matching `VectorUtil.dotProductScore(byte[], 
byte[])`.
   
   2. **Writer and Reader**:
      - Implemented `writeByteField(...)` and `BufferedByteVectorValues` in 
`FaissKnnVectorsWriter`.
      - Wired up `mergeOneField` and `flush` for `VectorEncoding.BYTE`.
      - Delegated `getByteVectorValues(field)` in `FaissKnnVectorsReader` to 
`rawVectorsReader.getByteVectorValues(field)`.
      - Enabled `FaissKnnVectorsReader.search(field, byte[], ...)`.
   
   3. **Testing**:
      - Added `BYTE` to `SUPPORTED_ENCODINGS` in `TestFaissKnnVectorsFormat`.
      - Un-ignored the 6 base test cases from `BaseKnnVectorsFormatTestCase` 
(`testByteVectorScorerIteration`, `testMismatchedFields`, 
`testSortedIndexBytes`, `testRandomBytes`, `testEmptyByteVectorData`, 
`testMergingWithDifferentByteKnnFields`).
      - Added `testByteVectorSearch()` to verify exact nearest neighbor 
retrieval and score consistency against Lucene's 
`VectorSimilarityFunction.compare` across `EUCLIDEAN`, `DOT_PRODUCT`, and 
`COSINE`.
      - Updated `lucene/CHANGES.txt`.
      


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to