Polishing.

This commit is contained in:
Peter-Josef Meisch 2024-05-28 20:57:27 +02:00
parent 687b014e70
commit fade919be6
No known key found for this signature in database
GPG Key ID: DE108246970C7708
2 changed files with 14 additions and 13 deletions

View File

@ -909,8 +909,7 @@ public abstract class MappingBuilderIntegrationTests extends MappingContextBaseT
@Nullable @Nullable
@Id private String id; @Id private String id;
@Field(type = FieldType.Dense_Vector, dims = 42, knnSimilarity = KnnSimilarity.COSINE) @Field(type = FieldType.Dense_Vector, dims = 42, knnSimilarity = KnnSimilarity.COSINE) private double[] denseVector;
private double[] denseVector;
} }
@Mapping(aliases = { @Mapping(aliases = {

View File

@ -27,7 +27,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.*; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.KnnAlgorithmType;
import org.springframework.data.elasticsearch.annotations.KnnIndexOptions;
import org.springframework.data.elasticsearch.annotations.KnnSimilarity;
import org.springframework.data.elasticsearch.client.elc.NativeQuery; import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder; import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
@ -71,7 +76,7 @@ public abstract class KnnSearchIntegrationTests {
entity.setMessage("top" + (i + 1)); entity.setMessage("top" + (i + 1));
// The generated vector is always in the first quadrant, from the x-axis direction to the y-axis direction // The generated vector is always in the first quadrant, from the x-axis direction to the y-axis direction
float[] vector = new float[] {1.0f - i * increment, increment}; float[] vector = new float[] { 1.0f - i * increment, increment };
entity.setVector(vector); entity.setVector(vector);
entities.add(entity); entities.add(entity);
} }
@ -127,27 +132,24 @@ public abstract class KnnSearchIntegrationTests {
assertThat(vectorEntities.get(0).getMessage()).isEqualTo("top10"); assertThat(vectorEntities.get(0).getMessage()).isEqualTo("top10");
} }
public interface VectorEntityRepository extends ElasticsearchRepository<VectorEntity, String> { public interface VectorEntityRepository extends ElasticsearchRepository<VectorEntity, String> {}
}
@Document(indexName = "#{@indexNameProvider.indexName()}") @Document(indexName = "#{@indexNameProvider.indexName()}")
static class VectorEntity { static class VectorEntity {
@Nullable @Nullable
@Id @Id private String id;
private String id;
@Nullable @Nullable
@Field(type = Keyword) @Field(type = Keyword) private String message;
private String message;
// TODO: `elementType = FieldElementType.FLOAT,` is to be added here later // TODO: `elementType = FieldElementType.FLOAT,` is to be added here later
// TODO: element_type can not be set here, because it's left out in elasticsearch-specification // TODO: element_type can not be set here, because it's left out in elasticsearch-specification
// TODO: the issue is fixed in https://github.com/elastic/elasticsearch-java/pull/800, but still not released in 8.13.x // TODO: the issue is fixed in https://github.com/elastic/elasticsearch-java/pull/800, but still not released in
// 8.13.x
// TODO: will be fixed later by either upgrading to 8.14.0 or a newer 8.13.x // TODO: will be fixed later by either upgrading to 8.14.0 or a newer 8.13.x
@Field(type = FieldType.Dense_Vector, dims = 2, @Field(type = FieldType.Dense_Vector, dims = 2,
knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100), knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100),
knnSimilarity = KnnSimilarity.COSINE) knnSimilarity = KnnSimilarity.COSINE) private float[] vector;
private float[] vector;
@Nullable @Nullable
public String getId() { public String getId() {