Commit 6a0afa2
Add FlatFieldVectorsWriter#asKnnVectorValues (#16062)
FlatFieldVectorsWriter<T> exposes its accumulated vectors via List<T> getVectors().
This is both too generic and too prescriptive:
List<T> binds the return type to specific vector representation (T = float[] / byte[] heap arrays, one vector per list element); if a FlatFieldVectorsWriter implementation is backed by a different data structure (off-heap / paged / memory-mapped storage), it has to materialize a heap array even when the downstream consumer would be happy with a non-materialized view.
it does not carry enough information with it (e.g. encoding, dimensions for sub-byte packed types, etc.). In fact, current consumes have to wrap that list into a KnnVectorValues to feed the scoring / graph-building path (see e.g. Lucene99HnswVectorsWriter.FieldWriter).
This PR proposes to move this step directly to FlatFieldVectorsWriter<T>, exposing its vectors also as KnnVectorValues.
Why KnnVectorValues?
KnnVectorValues is the shape current callers (e.g. scorers) actually use. This PR updates Lucene99HnswVectorsWriter to use the new function when it calls FlatVectorsScorer.getRandomVectorScorerSupplier, which already takes KnnVectorValues.
No new Lucene type is needed; an alternative would be to introduce a new Lucene interface (e.g. FlatVectorsView). That would be very similar to KnnVectorValues with minor variations.1 parent ef272d0 commit 6a0afa2
3 files changed
Lines changed: 30 additions & 16 deletions
File tree
- lucene
- core/src/java/org/apache/lucene/codecs
- hnsw
- lucene99
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
37 | 60 | | |
38 | 61 | | |
39 | 62 | | |
| |||
Lines changed: 4 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | 41 | | |
43 | 42 | | |
44 | | - | |
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
| |||
739 | 737 | | |
740 | 738 | | |
741 | 739 | | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
756 | 744 | | |
757 | 745 | | |
758 | 746 | | |
| |||
0 commit comments