You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add builder pattern and refactor Elasticsearch store package
The changes introduce a fluent builder pattern for ElasticsearchVectorStore
configuration, making it easier to create and customize instances with
optional parameters. All Elasticsearch-related classes are moved to a
dedicated elasticsearch package for better organization.
Key changes:
* Add ElasticsearchVectorStore.builder() with comprehensive options
* Move classes to org.springframework.ai.vectorstore.elasticsearch package
* Deprecate old constructors in favor of builder pattern
* Add support for configurable batching strategies
* Enhance documentation with usage examples and best practices
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/elasticsearch.adoc
+36-44Lines changed: 36 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,14 +76,11 @@ Alternatively you can opt-out the initialization and create the index manually u
76
76
77
77
NOTE: this is a breaking change! In earlier versions of Spring AI, this schema initialization happened by default.
78
78
79
-
80
-
81
79
Please have a look at the list of <<elasticsearchvector-properties,configuration parameters>> for the vector store to learn about the default values and configuration options.
82
80
These properties can be also set by configuring the `ElasticsearchVectorStoreOptions` bean.
83
81
84
82
Additionally, you will need a configured `EmbeddingModel` bean. Refer to the xref:api/embeddings.adoc#available-implementations[EmbeddingModel] section for more information.
85
83
86
-
87
84
Now you can auto-wire the `ElasticsearchVectorStore` as a vector store in your application.
88
85
89
86
[source,java]
@@ -97,7 +94,7 @@ List <Document> documents = List.of(
97
94
new Document("The World is Big and Salvation Lurks Around the Corner"),
98
95
new Document("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));
batching-strategy: TOKEN_COUNT # Optional: Controls how documents are batched for embedding
136
125
----
137
126
138
-
or can be a mix of those.
139
-
For example, if you want to store your password as an environment variable but keep the rest in the plain `application.yml` file.
140
-
141
-
NOTE: If you choose to create a shell script for ease in future work, be sure to run it prior to starting your application by "sourcing" the file, i.e. `source <your_script_name>.sh`.
142
-
143
-
Spring Boot's auto-configuration feature for the Elasticsearch RestClient will create a bean instance that will be used by the `ElasticsearchVectorStore`.
144
-
145
127
The Spring Boot properties starting with `spring.elasticsearch.*` are used to configure the Elasticsearch client:
146
128
147
-
[stripes=even]
129
+
[cols="2,5,1",stripes=even]
148
130
|===
149
131
|Property | Description | Default Value
150
132
@@ -160,23 +142,24 @@ The Spring Boot properties starting with `spring.elasticsearch.*` are used to co
160
142
| `spring.elasticsearch.socket-timeout` | Socket timeout used when communicating with Elasticsearch. | `30s`
161
143
|===
162
144
163
-
Properties starting with the `spring.ai.vectorstore.elasticsearch.*` prefix are used to configure `ElasticsearchVectorStore`.
145
+
Properties starting with `spring.ai.vectorstore.elasticsearch.*` are used to configure the `ElasticsearchVectorStore`:
164
146
165
-
[stripes=even]
147
+
[cols="2,5,1",stripes=even]
166
148
|===
167
149
|Property | Description | Default Value
168
150
169
-
|`spring.ai.vectorstore.elasticsearch.initialize-schema`| Whether to initialize the required schema | `false`
170
-
|`spring.ai.vectorstore.elasticsearch.index-name` | The name of the index to store the vectors. | spring-ai-document-index
171
-
|`spring.ai.vectorstore.elasticsearch.dimensions` | The number of dimensions in the vector. | 1536
172
-
|`spring.ai.vectorstore.elasticsearch.similarity` | The similarity function to use. | `cosine`
151
+
|`spring.ai.vectorstore.elasticsearch.initialize-schema`| Whether to initialize the required schema | `false`
152
+
|`spring.ai.vectorstore.elasticsearch.index-name` | The name of the index to store the vectors | `spring-ai-document-index`
153
+
|`spring.ai.vectorstore.elasticsearch.dimensions` | The number of dimensions in the vector | `1536`
154
+
|`spring.ai.vectorstore.elasticsearch.similarity` | The similarity function to use | `cosine`
155
+
|`spring.ai.vectorstore.elasticsearch.batching-strategy` | Strategy for batching documents when calculating embeddings. Options are `TOKEN_COUNT` or `FIXED_SIZE` | `TOKEN_COUNT`
173
156
|===
174
157
175
158
The following similarity functions are available:
176
159
177
-
* cosine
178
-
* l2_norm
179
-
* dot_product
160
+
* `cosine` - Default, suitable for most use cases. Measures cosine similarity between vectors.
* `dot_product` - Best performance for normalized vectors (e.g., OpenAI embeddings).
180
163
181
164
More details about each in the https://www.elastic.co/guide/en/elasticsearch/reference/master/dense-vector.html#dense-vector-params[Elasticsearch Documentation] on dense vectors.
Read the link:https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-usage-initialization.html[Elasticsearch Documentation] for more in-depth information about the configuration of a custom RestClient.
Copy file name to clipboardExpand all lines: spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreAutoConfiguration.java
Copy file name to clipboardExpand all lines: spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreProperties.java
Copy file name to clipboardExpand all lines: spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/elasticsearch/ElasticsearchVectorStoreAutoConfigurationIT.java
Copy file name to clipboardExpand all lines: vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchAiSearchFilterExpressionConverter.java
0 commit comments