Skip to content

Commit 57c45b5

Browse files
committed
Remove cosine similarity code
1 parent 5bcac49 commit 57c45b5

File tree

2 files changed

+4
-46
lines changed

2 files changed

+4
-46
lines changed

server/src/main/java/org/elasticsearch/index/mapper/BlockDocValuesReader.java

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,8 @@ public AllReader reader(LeafReaderContext context) throws IOException {
536536
case FLOAT -> {
537537
FloatVectorValues floatVectorValues = context.reader().getFloatVectorValues(fieldName);
538538
if (floatVectorValues != null) {
539-
if (fieldType.isNormalized()) {
540-
NumericDocValues magnitudeDocValues = context.reader()
541-
.getNumericDocValues(fieldType.name() + COSINE_MAGNITUDE_FIELD_SUFFIX);
542-
return new FloatDenseVectorNormalizedValuesBlockReader(floatVectorValues, dimensions, magnitudeDocValues);
543-
}
539+
return new FloatDenseVectorValuesBlockReader(floatVectorValues, dimensions);
544540
}
545-
return new FloatDenseVectorValuesBlockReader(floatVectorValues, dimensions);
546541
}
547542
case BYTE -> {
548543
ByteVectorValues byteVectorValues = context.reader().getByteVectorValues(fieldName);
@@ -625,41 +620,6 @@ public String toString() {
625620
}
626621
}
627622

628-
private static class FloatDenseVectorNormalizedValuesBlockReader extends DenseVectorValuesBlockReader<FloatVectorValues> {
629-
private final NumericDocValues magnitudeDocValues;
630-
631-
FloatDenseVectorNormalizedValuesBlockReader(
632-
FloatVectorValues floatVectorValues,
633-
int dimensions,
634-
NumericDocValues magnitudeDocValues
635-
) {
636-
super(floatVectorValues, dimensions);
637-
this.magnitudeDocValues = magnitudeDocValues;
638-
}
639-
640-
@Override
641-
protected void appendDoc(BlockLoader.FloatBuilder builder) throws IOException {
642-
float[] floats = vectorValues.vectorValue(iterator.index());
643-
assert floats.length == dimensions
644-
: "unexpected dimensions for vector value; expected " + dimensions + " but got " + floats.length;
645-
646-
float magnitude = 1.0f;
647-
// If all vectors are normalized, no doc values will be present. The vector may be normalized already, so we may not have a
648-
// stored magnitude for all docs
649-
if ((magnitudeDocValues != null) && magnitudeDocValues.advanceExact(iterator.docID())) {
650-
magnitude = Float.intBitsToFloat((int) magnitudeDocValues.longValue());
651-
}
652-
for (float aFloat : floats) {
653-
builder.appendFloat(aFloat * magnitude);
654-
}
655-
}
656-
657-
@Override
658-
public String toString() {
659-
return "BlockDocValuesReader.FloatDenseVectorNormalizedValuesBlockReader";
660-
}
661-
}
662-
663623
private static class ByteDenseVectorValuesBlockReader extends DenseVectorValuesBlockReader<ByteVectorValues> {
664624
ByteDenseVectorValuesBlockReader(ByteVectorValues floatVectorValues, int dimensions) {
665625
super(floatVectorValues, dimensions);

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/DenseVectorFieldTypeIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public static Iterable<Object[]> parameters() throws Exception {
6666
? randomFrom(ALL_DENSE_VECTOR_INDEX_TYPES)
6767
: randomFrom(NON_QUANTIZED_DENSE_VECTOR_INDEX_TYPES);
6868
Supplier<DenseVectorFieldMapper.VectorSimilarity> vectorSimilarityProvider = () -> randomFrom(
69-
DenseVectorFieldMapper.VectorSimilarity.values()
69+
DenseVectorFieldMapper.VectorSimilarity.DOT_PRODUCT,
70+
DenseVectorFieldMapper.VectorSimilarity.L2_NORM,
71+
DenseVectorFieldMapper.VectorSimilarity.MAX_INNER_PRODUCT
7072
);
7173
params.add(new Object[] { elementTypeProvider, indexTypeProvider, vectorSimilarityProvider, true, false });
7274
// No indexing
@@ -137,10 +139,6 @@ public void testRetrieveDenseVectorFieldData() {
137139
| KEEP id, vector
138140
""";
139141

140-
indexedVectors.forEach((i, v) -> {
141-
System.out.println("ID: " + i + ", Vector: " + v);
142-
});
143-
144142
try (var resp = run(query)) {
145143
List<List<Object>> valuesList = EsqlTestUtils.getValuesList(resp);
146144
assertEquals(valuesList.size(), indexedVectors.size());

0 commit comments

Comments
 (0)