|
52 | 52 | import org.elasticsearch.index.fielddata.IndexFieldData; |
53 | 53 | import org.elasticsearch.index.mapper.ArraySourceValueFetcher; |
54 | 54 | import org.elasticsearch.index.mapper.BlockDocValuesReader; |
| 55 | +import org.elasticsearch.index.mapper.BlockDocValuesReader.DocValuesBlockLoader; |
55 | 56 | import org.elasticsearch.index.mapper.BlockLoader; |
56 | 57 | import org.elasticsearch.index.mapper.BlockSourceReader; |
57 | 58 | import org.elasticsearch.index.mapper.DocumentParserContext; |
@@ -431,6 +432,21 @@ public double computeSquaredMagnitude(VectorData vectorData) { |
431 | 432 | return VectorUtil.dotProduct(vectorData.asByteVector(), vectorData.asByteVector()); |
432 | 433 | } |
433 | 434 |
|
| 435 | + @Override |
| 436 | + public DocValuesBlockLoader indexedBlockLoader(String fieldName) { |
| 437 | + return null; |
| 438 | + } |
| 439 | + |
| 440 | + @Override |
| 441 | + public DocValuesBlockLoader docValuesBlockLoader(String fieldName, int dimensions, IndexVersion indexVersionCreated) { |
| 442 | + return null; |
| 443 | + } |
| 444 | + |
| 445 | + @Override |
| 446 | + public BlockLoader sourceBlockLoader(String fieldName, MappedFieldType.BlockLoaderContext blContext) { |
| 447 | + return null; |
| 448 | + } |
| 449 | + |
434 | 450 | private VectorData parseVectorArray( |
435 | 451 | DocumentParserContext context, |
436 | 452 | int dims, |
@@ -672,6 +688,34 @@ public double computeSquaredMagnitude(VectorData vectorData) { |
672 | 688 | return VectorUtil.dotProduct(vectorData.asFloatVector(), vectorData.asFloatVector()); |
673 | 689 | } |
674 | 690 |
|
| 691 | + @Override |
| 692 | + public DocValuesBlockLoader indexedBlockLoader(String fieldName) { |
| 693 | + return new BlockDocValuesReader.DenseVectorBlockLoader(fieldName); |
| 694 | + } |
| 695 | + |
| 696 | + @Override |
| 697 | + public DocValuesBlockLoader docValuesBlockLoader(String fieldName, int dimensions, IndexVersion indexVersionCreated) { |
| 698 | + return new BlockDocValuesReader.DenseVectorFromBinaryBlockLoader(fieldName, dimensions, indexVersionCreated); |
| 699 | + } |
| 700 | + |
| 701 | + @Override |
| 702 | + public BlockLoader sourceBlockLoader(String fieldName, MappedFieldType.BlockLoaderContext blContext) { |
| 703 | + BlockSourceReader.LeafIteratorLookup lookup = BlockSourceReader.lookupMatchingAll(); |
| 704 | + return new BlockSourceReader.FloatsBlockLoader(sourceValueFetcher(blContext.sourcePaths(fieldName)), lookup); |
| 705 | + } |
| 706 | + |
| 707 | + private SourceValueFetcher sourceValueFetcher(Set<String> sourcePaths) { |
| 708 | + return new SourceValueFetcher(sourcePaths, null) { |
| 709 | + @Override |
| 710 | + protected Object parseSourceValue(Object value) { |
| 711 | + if (value.equals("")) { |
| 712 | + return null; |
| 713 | + } |
| 714 | + return NumberFieldMapper.NumberType.FLOAT.parse(value, false); |
| 715 | + } |
| 716 | + }; |
| 717 | + } |
| 718 | + |
675 | 719 | @Override |
676 | 720 | public void parseKnnVectorAndIndex(DocumentParserContext context, DenseVectorFieldMapper fieldMapper) throws IOException { |
677 | 721 | int index = 0; |
@@ -851,6 +895,21 @@ public double computeSquaredMagnitude(VectorData vectorData) { |
851 | 895 | return count; |
852 | 896 | } |
853 | 897 |
|
| 898 | + @Override |
| 899 | + public DocValuesBlockLoader indexedBlockLoader(String fieldName) { |
| 900 | + return null; |
| 901 | + } |
| 902 | + |
| 903 | + @Override |
| 904 | + public DocValuesBlockLoader docValuesBlockLoader(String fieldName, int dimensions, IndexVersion indexVersionCreated) { |
| 905 | + return null; |
| 906 | + } |
| 907 | + |
| 908 | + @Override |
| 909 | + public BlockLoader sourceBlockLoader(String fieldName, MappedFieldType.BlockLoaderContext blContext) { |
| 910 | + return null; |
| 911 | + } |
| 912 | + |
854 | 913 | private VectorData parseVectorArray( |
855 | 914 | DocumentParserContext context, |
856 | 915 | int dims, |
@@ -1145,6 +1204,12 @@ static Function<StringBuilder, StringBuilder> errorByteElementsAppender(byte[] v |
1145 | 1204 | public static ElementType fromString(String name) { |
1146 | 1205 | return valueOf(name.trim().toUpperCase(Locale.ROOT)); |
1147 | 1206 | } |
| 1207 | + |
| 1208 | + public abstract DocValuesBlockLoader indexedBlockLoader(String fieldName); |
| 1209 | + |
| 1210 | + public abstract DocValuesBlockLoader docValuesBlockLoader(String fieldName, int dimensions, IndexVersion indexVersionCreated); |
| 1211 | + |
| 1212 | + public abstract BlockLoader sourceBlockLoader(String fieldName, MappedFieldType.BlockLoaderContext blContext); |
1148 | 1213 | } |
1149 | 1214 |
|
1150 | 1215 | public static final Map<String, ElementType> namesToElementType = Map.of( |
@@ -2324,33 +2389,15 @@ ElementType getElementType() { |
2324 | 2389 |
|
2325 | 2390 | @Override |
2326 | 2391 | public BlockLoader blockLoader(MappedFieldType.BlockLoaderContext blContext) { |
2327 | | - if (elementType != ElementType.FLOAT) { |
2328 | | - // Just float dense vector support for now |
2329 | | - return null; |
2330 | | - } |
2331 | | - |
2332 | 2392 | if (indexed) { |
2333 | | - return new BlockDocValuesReader.DenseVectorBlockLoader(name()); |
| 2393 | + return getElementType().indexedBlockLoader(name()); |
2334 | 2394 | } |
2335 | 2395 |
|
2336 | 2396 | if (hasDocValues() && (blContext.fieldExtractPreference() != FieldExtractPreference.STORED || isSyntheticSource)) { |
2337 | | - return new BlockDocValuesReader.DenseVectorFromBinaryBlockLoader(name(), dims, indexVersionCreated); |
| 2397 | + return getElementType().docValuesBlockLoader(name(), dims, indexVersionCreated); |
2338 | 2398 | } |
2339 | 2399 |
|
2340 | | - BlockSourceReader.LeafIteratorLookup lookup = BlockSourceReader.lookupMatchingAll(); |
2341 | | - return new BlockSourceReader.FloatsBlockLoader(sourceValueFetcher(blContext.sourcePaths(name())), lookup); |
2342 | | - } |
2343 | | - |
2344 | | - private SourceValueFetcher sourceValueFetcher(Set<String> sourcePaths) { |
2345 | | - return new SourceValueFetcher(sourcePaths, null) { |
2346 | | - @Override |
2347 | | - protected Object parseSourceValue(Object value) { |
2348 | | - if (value.equals("")) { |
2349 | | - return null; |
2350 | | - } |
2351 | | - return NumberFieldMapper.NumberType.FLOAT.parse(value, false); |
2352 | | - } |
2353 | | - }; |
| 2400 | + return getElementType().sourceBlockLoader(name(), blContext); |
2354 | 2401 | } |
2355 | 2402 | } |
2356 | 2403 |
|
|
0 commit comments