Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ The following service connection factories are provided in the `spring-ai-spring
| Containers named `localstack/localstack`

| `ChromaConnectionDetails`
| Containers named `docker.elastic.co/elasticsearch/elasticsearch`

| `ElasticsearchConnectionDetails`
| Containers named `chromadb/chroma`, `ghcr.io/chroma-core/chroma`

| `MongoConnectionDetails`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ The following service connection factories are provided in the `spring-ai-spring
| `ChromaConnectionDetails`
| Containers of type `ChromaDBContainer`

| `ElasticsearchConnectionDetails`
| Containers of type `ElasticsearchContainer`

| `MilvusServiceClientConnectionDetails`
| Containers of type `MilvusContainer`

Expand Down
13 changes: 13 additions & 0 deletions spring-ai-spring-boot-docker-compose/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-vector-store-elasticsearch</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-vector-store-weaviate</artifactId>
Expand Down Expand Up @@ -138,6 +143,14 @@
<optional>true</optional>
</dependency>

<!-- Elasticsearch Vector Store -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-elasticsearch-store</artifactId>
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>

<!-- Weaviate Vector Store -->
<dependency>
<groupId>org.springframework.ai</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.docker.compose.service.connection.elasticsearch;

import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;

import java.util.List;

/**
* A {@link DockerComposeConnectionDetailsFactory} implementation that creates
* {@link ElasticsearchConnectionDetails} for an Elasticsearch instance running in a
* Docker container.
*
* @author Laura Trotta
* @see DockerComposeConnectionDetailsFactory
* @see ElasticsearchConnectionDetails
* @see DockerComposeConnectionSource
* @since 1.0.2
*/
class ElasticsearchDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<ElasticsearchConnectionDetails> {

private static final int ELASTICSEARCH_PORT = 9200;

protected ElasticsearchDockerComposeConnectionDetailsFactory() {
super("docker.elastic.co/elasticsearch/elasticsearch");
}

@Override
protected ElasticsearchConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new ElasticsearchDockerComposeConnectionDetails(source.getRunningService());
}

/**
* {@link ElasticsearchConnectionDetails} backed by an {@code Elasticsearch}
* {@link RunningService}.
*/
static class ElasticsearchDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements ElasticsearchConnectionDetails {

private final ElasticsearchEnvironment environment;

private final String host;

ElasticsearchDockerComposeConnectionDetails(RunningService service) {
super(service);
this.environment = new ElasticsearchEnvironment(service.env());
this.host = service.host();
}

@Override
public List<Node> getNodes() {
return List.of(new Node(host, ELASTICSEARCH_PORT, Node.Protocol.HTTPS, getUsername(), getPassword()));
}

@Override
public String getUsername() {
return "elastic";
}

@Override
public String getPassword() {
return environment.getPassword();
}

@Override
public String getPathPrefix() {
return "";
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.docker.compose.service.connection.elasticsearch;

import java.util.Map;

class ElasticsearchEnvironment {

private final String password;

ElasticsearchEnvironment(Map<String, String> env) {
this.password = env.get("ELASTIC_PASSWORD");
}

String getPassword() {
return this.password;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
org.springframework.ai.docker.compose.service.connection.chroma.ChromaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.elasticsearch.ElasticsearchDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.mongo.MongoDbAtlasLocalDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.ollama.OllamaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.opensearch.AwsOpenSearchDockerComposeConnectionDetailsFactory,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.docker.compose.service.connection.elasticsearch;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIT;
import org.springframework.util.StreamUtils;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

import static org.assertj.core.api.Assertions.assertThat;

class ElasticsearchDockerComposeConnectionDetailsFactoryIT extends AbstractDockerComposeIT {

protected ElasticsearchDockerComposeConnectionDetailsFactoryIT() {
super("elasticsearch-compose.yaml", DockerImageName.parse(getLatestElasticsearch()));
}

private static String getLatestElasticsearch() {
String imageName = "docker.elastic.co/elasticsearch/elasticsearch:";
try {
URL url = new URL("https://artifacts.elastic.co/releases/stack.json");
URLConnection connection = url.openConnection();
try (InputStream is = connection.getInputStream()) {
String result = StreamUtils.copyToString(is, Charset.defaultCharset());
JSONObject json = new JSONObject(result);
JSONArray releases = json.getJSONArray("releases");
JSONObject latest = (JSONObject) releases.get(releases.length() - 1);
return imageName + latest.getString("version");
}
}
catch (IOException e) {
throw new RuntimeException(
"Failed to retrieve latest Elasticsearch version from https://artifacts.elastic.co/releases/stack.json",
e);
}
}

@Test
void runCreatesConnectionDetails() {
ElasticsearchConnectionDetails connectionDetails = run(ElasticsearchConnectionDetails.class);
assertThat(connectionDetails.getNodes()).isNotEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.docker.compose.service.connection.elasticsearch;

import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

class ElasticsearchEnvironmentTests {

@Test
void getPasswordWhenNoPassword() {
ElasticsearchEnvironment environment = new ElasticsearchEnvironment(Collections.emptyMap());
assertThat(environment.getPassword()).isNull();
}

@Test
void getPasswordWhenHasPassword() {
ElasticsearchEnvironment environment = new ElasticsearchEnvironment(Map.of("ELASTIC_PASSWORD", "Ym9vcCE="));
assertThat(environment.getPassword()).isEqualTo("Ym9vcCE=");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
elasticsearch:
image: '{imageName}'
ports:
- '9200'
environment:
- ELASTIC_PASSWORD=Ym9vcCE=
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms128m -Xmx512m
21 changes: 21 additions & 0 deletions spring-ai-spring-boot-testcontainers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-vector-store-elasticsearch</artifactId>
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-autoconfigure-vector-store-mongodb-atlas</artifactId>
Expand Down Expand Up @@ -151,6 +157,14 @@
<optional>true</optional>
</dependency>

<!-- Elasticsearch Vector Store-->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-elasticsearch-store</artifactId>
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>

<!-- Weaviate Vector Store -->
<dependency>
<groupId>org.springframework.ai</groupId>
Expand Down Expand Up @@ -308,6 +322,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.21.3</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
Expand Down
Loading