@@ -510,39 +510,43 @@ public String toString() {
510
510
511
511
public static class DenseVectorBlockLoader extends DocValuesBlockLoader {
512
512
private final String fieldName ;
513
+ private final int dimensions ;
513
514
514
- public DenseVectorBlockLoader (String fieldName ) {
515
+ public DenseVectorBlockLoader (String fieldName , int dimensions ) {
515
516
this .fieldName = fieldName ;
517
+ this .dimensions = dimensions ;
516
518
}
517
519
518
520
@ Override
519
521
public Builder builder (BlockFactory factory , int expectedCount ) {
520
- return factory .floats (expectedCount );
522
+ return factory .denseVectors (expectedCount , dimensions );
521
523
}
522
524
523
525
@ Override
524
526
public AllReader reader (LeafReaderContext context ) throws IOException {
525
527
FloatVectorValues floatVectorValues = context .reader ().getFloatVectorValues (fieldName );
526
528
if (floatVectorValues != null ) {
527
- return new FloatVectorValuesBlockReader (floatVectorValues );
529
+ return new DenseVectorValuesBlockReader (floatVectorValues , dimensions );
528
530
}
529
531
return new ConstantNullsReader ();
530
532
}
531
533
}
532
534
533
- private static class FloatVectorValuesBlockReader extends BlockDocValuesReader {
535
+ private static class DenseVectorValuesBlockReader extends BlockDocValuesReader {
534
536
private final FloatVectorValues floatVectorValues ;
535
537
private final KnnVectorValues .DocIndexIterator iterator ;
538
+ private final int dimensions ;
536
539
537
- FloatVectorValuesBlockReader (FloatVectorValues floatVectorValues ) {
540
+ DenseVectorValuesBlockReader (FloatVectorValues floatVectorValues , int dimensions ) {
538
541
this .floatVectorValues = floatVectorValues ;
539
542
iterator = floatVectorValues .iterator ();
543
+ this .dimensions = dimensions ;
540
544
}
541
545
542
546
@ Override
543
547
public BlockLoader .Block read (BlockFactory factory , Docs docs ) throws IOException {
544
548
// Doubles from doc values ensures that the values are in order
545
- try (BlockLoader .FloatBuilder builder = factory .floats (docs .count ())) {
549
+ try (BlockLoader .FloatBuilder builder = factory .denseVectors (docs .count (), dimensions )) {
546
550
for (int i = 0 ; i < docs .count (); i ++) {
547
551
int doc = docs .get (i );
548
552
if (doc < iterator .docID ()) {
@@ -563,6 +567,8 @@ private void read(int doc, BlockLoader.FloatBuilder builder) throws IOException
563
567
if (iterator .advance (doc ) == doc ) {
564
568
builder .beginPositionEntry ();
565
569
float [] floats = floatVectorValues .vectorValue (iterator .index ());
570
+ assert floats .length == dimensions
571
+ : "unexpected dimensions for vector value; expected " + dimensions + " but got " + floats .length ;
566
572
for (float aFloat : floats ) {
567
573
builder .appendFloat (aFloat );
568
574
}
@@ -844,7 +850,7 @@ public DenseVectorFromBinaryBlockLoader(String fieldName, int dims, IndexVersion
844
850
845
851
@ Override
846
852
public Builder builder (BlockFactory factory , int expectedCount ) {
847
- return factory .floats (expectedCount );
853
+ return factory .denseVectors (expectedCount , dims );
848
854
}
849
855
850
856
@ Override
@@ -860,6 +866,7 @@ public AllReader reader(LeafReaderContext context) throws IOException {
860
866
private static class DenseVectorFromBinary extends BlockDocValuesReader {
861
867
private final BinaryDocValues docValues ;
862
868
private final IndexVersion indexVersion ;
869
+ private final int dimensions ;
863
870
private final float [] scratch ;
864
871
865
872
private int docID = -1 ;
@@ -868,11 +875,12 @@ private static class DenseVectorFromBinary extends BlockDocValuesReader {
868
875
this .docValues = docValues ;
869
876
this .scratch = new float [dims ];
870
877
this .indexVersion = indexVersion ;
878
+ this .dimensions = dims ;
871
879
}
872
880
873
881
@ Override
874
882
public BlockLoader .Block read (BlockFactory factory , Docs docs ) throws IOException {
875
- try (BlockLoader .FloatBuilder builder = factory .floats (docs .count ())) {
883
+ try (BlockLoader .FloatBuilder builder = factory .denseVectors (docs .count (), dimensions )) {
876
884
for (int i = 0 ; i < docs .count (); i ++) {
877
885
int doc = docs .get (i );
878
886
if (doc < docID ) {
0 commit comments