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 index configuration and add support for ES response error handling.
- rename dims to dimension propety.
- add property javadocs
- improve the elasticsearch javadoc.
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
36
39
37
-
== Configuration
40
+
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.
41
+
42
+
Here is an example of the needed bean:
43
+
44
+
[source,java]
45
+
----
46
+
@Bean
47
+
public EmbeddingClient embeddingCLient() {
48
+
// Can be any other EmbeddingClient implementation
49
+
return new OpenAiEmbeddingClient(new OpenAiApi(System.getenv("SPRING_AI_OPENAI_API_KEY")));
50
+
}
51
+
----
52
+
53
+
In cases where the Spring Boot auto-configured Elasticsearch `RestClient` bean is not what you want or need, you can still define your own bean.
54
+
Please read the link:https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-usage-initialization.html[Elasticsearch Documentation]
55
+
for more in-depth information about the configuration of a custom RestClient.
To connect to Elasticsearch and use the `ElasticsearchVectorStore`, you need to provide access details for your instance.
40
92
A simple configuration can either be provided via Spring Boot's `application.yml`,
@@ -71,16 +123,44 @@ NOTE: If you choose to create a shell script for ease in future work, be sure to
71
123
72
124
Spring Boot's auto-configuration feature for the Elasticsearch RestClient will create a bean instance that will be used by the `ElasticsearchVectorStore`.
73
125
74
-
== Auto-configuration
126
+
The Spring Boot properties starting with `spring.elasticsearch.*` are used to configure the Elasticsearch client:
75
127
76
-
Spring AI provides Spring Boot auto-configuration for the Elasticsearch Vector Store.
77
-
To enable it, add the following dependency to your project's Maven `pom.xml` file:
128
+
|===
129
+
|Property | Description | Default Value
130
+
131
+
| spring.elasticsearch.connection-timeout | Connection timeout used when communicating with Elasticsearch. | 1s
132
+
| spring.elasticsearch.password | Password for authentication with Elasticsearch. | -
133
+
| spring.elasticsearch.username | Username for authentication with Elasticsearch.| -
134
+
| spring.elasticsearch.path-prefix | Prefix added to the path of every request sent to Elasticsearch. | -
135
+
| spring.elasticsearch.restclient.sniffer.delay-after-failure | Delay of a sniff execution scheduled after a failure.| 1m
| spring.elasticsearch.socket-keep-alive | Whether to enable socket keep alive between client and Elasticsearch. | false
139
+
| spring.elasticsearch.socket-timeout | Socket timeout used when communicating with Elasticsearch. | 30s
140
+
| spring.elasticsearch.uris | Comma-separated list of the Elasticsearch instances to use. | http://localhost:9200
141
+
|===
142
+
143
+
144
+
The properties with `spring.ai.vectorstore.elasticsearch.*` prefix help to configure Elasticsearch vector store.
145
+
146
+
|===
147
+
|Property | Description | Default Value
148
+
149
+
|`spring.ai.vectorstore.elasticsearch.index-name` | The name of the index to store the vectors. | spring-ai-document-index
150
+
|`spring.ai.vectorstore.elasticsearch.dimensions` | The number of dimensions in the vector. | 1536
151
+
|`spring.ai.vectorstore.elasticsearch.dense-vector-indexing` | Whether to use dense vector indexing. | true
152
+
|`spring.ai.vectorstore.elasticsearch.similarity` | The similarity function to use. | `cosine`
153
+
|===
154
+
155
+
=== Manual Configuration
156
+
157
+
Instead of using the Spring Boot auto-configuration, you can manually configure the Elasticsearch vector store. \For this you need to add the `spring-ai-elasticsearch-store` to your project:
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
97
-
98
-
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.
99
-
100
-
Here is an example of the needed bean:
101
-
102
-
[source,java]
103
-
----
104
-
@Bean
105
-
public EmbeddingClient embeddingCLient() {
106
-
// Can be any other EmbeddingClient implementation
107
-
return new OpenAiEmbeddingClient(new OpenAiApi(System.getenv("SPRING_AI_OPENAI_API_KEY")));
108
-
}
109
-
----
110
-
111
-
In cases where the Spring Boot auto-configured Elasticsearch `RestClient` bean is not what you want or need, you can still define your own bean.
112
-
Please read the link:https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low-usage-initialization.html[Elasticsearch Documentation]
113
-
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
0 commit comments