You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "ldematte (via GitHub)" <gi...@apache.org> on 2026/05/12 16:45:41 UTC

[PR] Add an (optional) field-writer creation strategy to `Lucene99FlatVectorsWriter` [lucene]

ldematte opened a new pull request, #16053:
URL: https://github.com/apache/lucene/pull/16053

   `Lucene99FlatVectorsWriter` hard-codes the per-field storage for vector values to an on-heap `ArrayList<T>` (`ArrayList<float[]>` or `ArrayList<byte[]>`), managed by a private nested class `Lucene99FlatVectorsWriter.FieldWriter<T>`.
   
   Different users of `Lucene99FlatVectorsFormat` may want to change how vectors are stored in memory; this PR proposes a simple change to decouple the external interface and the write pipeline implemented by `Lucene99FlatVectorsWriter` from the vectors' memory storage.
   
   In particular, this PR adds a public constructor overload to `Lucene99FlatVectorsWriter` that accepts a `FlatFieldVectorsWriter` factory: when the factory is supplied, `addField(FieldInfo)` uses it to obtain the per-field storage; when the existing two-arg ctor is used, the current behavior is preserved exactly via a default hardcoded `fieldWriterFactory`.
   
   `Lucene99FlatVectorsWriter` write pipeline is unchanged in shape, but is refactored internally to read its FieldWriter's state through accessor methods rather than direct field reads. This makes it possible to introduce a `Delegating` variant of `FieldWriter` that forwards to the injected strategy, without the need to open up the class visibility. `FieldWriter<T>` remains a private nested class. No public API surface of `FlatFieldVectorsWriter<T>` (or any other class) is changed.
   
   A new `TestKnnVectorsFormatCustomWriter` is introduced; this test exercises the new constructor against
   the full `BaseKnnVectorsFormatTestCase` suite, using a paged storage strategy as a concrete example of a non-default `FlatFieldVectorsWriter`.
   
   The purpose of the test is 2-fold: 1) ensure that the use of a different, custom strategy does not break any existing invariants, and 2) showcase how a different `FlatFieldVectorsWriter` can work. The test `FlatFieldVectorsWriter`  stores vectors in a `List<ByteBuffer>` of fixed-size pages, and exposes them back through FlatFieldVectorsWriter#getVectors()` via an `AbstractList` adapter that materializes a heap array per access. The on-disk format produced is identical to the default configuration -- only the in-memory accumulation differs.


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add an (optional) field-writer creation strategy to `Lucene99FlatVectorsWriter` [lucene]

Posted by "ldematte (via GitHub)" <gi...@apache.org>.
ldematte commented on code in PR #16053:
URL: https://github.com/apache/lucene/pull/16053#discussion_r3233416193


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99FlatVectorsWriter.java:
##########
@@ -58,14 +59,40 @@ public final class Lucene99FlatVectorsWriter extends FlatVectorsWriter {
 
   private final SegmentWriteState segmentWriteState;
   private final IndexOutput meta, vectorData;
+  private final IOFunction<FieldInfo, FlatFieldVectorsWriter<?>> fieldWriterFactory;
 
-  private final List<FieldWriter<?>> fields = new ArrayList<>();
+  private record FieldData(FlatFieldVectorsWriter<?> fieldWriter, FieldInfo fieldInfo) {}
+
+  private final List<FieldData> fields = new ArrayList<>();

Review Comment:
   We could store FlatFieldVectorsWriters and FieldInfos separately in 2 arrays, but I think using a small record here is cleaner



-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add an (optional) field-writer creation strategy to `Lucene99FlatVectorsWriter` [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty merged PR #16053:
URL: https://github.com/apache/lucene/pull/16053


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add an (optional) field-writer creation strategy to `Lucene99FlatVectorsWriter` [lucene]

Posted by "ldematte (via GitHub)" <gi...@apache.org>.
ldematte commented on PR #16053:
URL: https://github.com/apache/lucene/pull/16053#issuecomment-4510456127

   @benwtrent if you don't have any objection, we would like to merge this change


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org