|
27 | 27 | import org.springframework.beans.factory.annotation.Autowired;
|
28 | 28 | import org.springframework.data.annotation.Id;
|
29 | 29 | import org.springframework.data.domain.Pageable;
|
30 |
| -import org.springframework.data.elasticsearch.annotations.*; |
| 30 | +import org.springframework.data.elasticsearch.annotations.Document; |
| 31 | +import org.springframework.data.elasticsearch.annotations.Field; |
| 32 | +import org.springframework.data.elasticsearch.annotations.FieldType; |
| 33 | +import org.springframework.data.elasticsearch.annotations.KnnAlgorithmType; |
| 34 | +import org.springframework.data.elasticsearch.annotations.KnnIndexOptions; |
| 35 | +import org.springframework.data.elasticsearch.annotations.KnnSimilarity; |
31 | 36 | import org.springframework.data.elasticsearch.client.elc.NativeQuery;
|
32 | 37 | import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder;
|
33 | 38 | import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
@@ -71,7 +76,7 @@ private List<VectorEntity> createVectorEntities(int n) {
|
71 | 76 | entity.setMessage("top" + (i + 1));
|
72 | 77 |
|
73 | 78 | // The generated vector is always in the first quadrant, from the x-axis direction to the y-axis direction
|
74 |
| - float[] vector = new float[] {1.0f - i * increment, increment}; |
| 79 | + float[] vector = new float[] { 1.0f - i * increment, increment }; |
75 | 80 | entity.setVector(vector);
|
76 | 81 | entities.add(entity);
|
77 | 82 | }
|
@@ -127,27 +132,24 @@ public void shouldReturnYAxisVector() {
|
127 | 132 | assertThat(vectorEntities.get(0).getMessage()).isEqualTo("top10");
|
128 | 133 | }
|
129 | 134 |
|
130 |
| - public interface VectorEntityRepository extends ElasticsearchRepository<VectorEntity, String> { |
131 |
| - } |
| 135 | + public interface VectorEntityRepository extends ElasticsearchRepository<VectorEntity, String> {} |
132 | 136 |
|
133 | 137 | @Document(indexName = "#{@indexNameProvider.indexName()}")
|
134 | 138 | static class VectorEntity {
|
135 | 139 | @Nullable
|
136 |
| - @Id |
137 |
| - private String id; |
| 140 | + @Id private String id; |
138 | 141 |
|
139 | 142 | @Nullable
|
140 |
| - @Field(type = Keyword) |
141 |
| - private String message; |
| 143 | + @Field(type = Keyword) private String message; |
142 | 144 |
|
143 | 145 | // TODO: `elementType = FieldElementType.FLOAT,` is to be added here later
|
144 | 146 | // TODO: element_type can not be set here, because it's left out in elasticsearch-specification
|
145 |
| - // TODO: the issue is fixed in https://github.com/elastic/elasticsearch-java/pull/800, but still not released in 8.13.x |
| 147 | + // TODO: the issue is fixed in https://github.com/elastic/elasticsearch-java/pull/800, but still not released in |
| 148 | + // 8.13.x |
146 | 149 | // TODO: will be fixed later by either upgrading to 8.14.0 or a newer 8.13.x
|
147 | 150 | @Field(type = FieldType.Dense_Vector, dims = 2,
|
148 | 151 | knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100),
|
149 |
| - knnSimilarity = KnnSimilarity.COSINE) |
150 |
| - private float[] vector; |
| 152 | + knnSimilarity = KnnSimilarity.COSINE) private float[] vector; |
151 | 153 |
|
152 | 154 | @Nullable
|
153 | 155 | public String getId() {
|
|
0 commit comments