kaivalnp commented on PR #16839:
URL: https://github.com/apache/lucene/pull/16839#issuecomment-6926882390

   I agree with the motivation of this PR and appreciate the attempt to avoid 
API changes, but the `MergedCentroidCollector` approach looks unnecessarily 
complicated to me.
   
   The scalar quantized writer 
[re-uses](https://github.com/apache/lucene/blob/9965d34e3c77f80ee1752fe7579dd5bca8278747/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104ScalarQuantizedVectorsWriter.java#L81)
 a flat writer to manage its raw vectors, and I see that existing 
`FlatVectorsWriter` functions are not sufficient for the ask here.
   
   I guess the API is tricky because each writer -> writer interaction requires 
exposing different data. For example 
[`MergeScorerData`](https://github.com/apache/lucene/blob/9965d34e3c77f80ee1752fe7579dd5bca8278747/lucene/core/src/java/org/apache/lucene/codecs/hnsw/FlatVectorsWriter.java#L97-L103)
 is 
[used](https://github.com/apache/lucene/blob/9965d34e3c77f80ee1752fe7579dd5bca8278747/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsWriter.java#L434-L435)
 in the `Lucene99HnswVectorsWriter` -> `Lucene104ScalarQuantizedVectorsWriter` 
path to expose an asymmetric scorer for graph construction.
   
   The API needs more thought, but some examples of what we could do:
   1. Add a new `mergeOneFlatVectorField*` function to `FlatVectorsWriter` that 
accepts a consumer of raw floats.
        - The scalar-quantized writer would pass a consumer that computes the 
centroid.
        - **Caveat**: This would only be used from the 
`Lucene104ScalarQuantizedVectorsWriter` -> `Lucene99FlatVectorsWriter` path, 
and adding new functions to the base `FlatVectorsWriter` class for specific 
writer -> writer interactions might blow up the API. FWIW [this 
function](https://github.com/apache/lucene/blob/9965d34e3c77f80ee1752fe7579dd5bca8278747/lucene/core/src/java/org/apache/lucene/codecs/hnsw/FlatVectorsWriter.java#L90)
 is a precedent for one such interaction.
   2. Make `MergeScorerData` generic to represent arbitrary data useful for 
merge.
        - Then it could be overridden from `Lucene99FlatVectorsWriter` to 
expose the centroid of merged live vectors.
        - **Caveat**: Each writer can only support one interaction, and each 
caller would need runtime checks to ensure it gets necessary data.
   3. Harden internal flat writer types.
        - If [this 
instance](https://github.com/apache/lucene/blob/9965d34e3c77f80ee1752fe7579dd5bca8278747/lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104ScalarQuantizedVectorsWriter.java#L81)
 was known to be a `Lucene99FlatVectorsWriter`, we could write a special merge 
function in that class alone, without hoisting it up to `FlatVectorsWriter`.
   
   These are just suggestions, I don't have a strong leaning towards any right 
now, and open to other suggestions.


-- 
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