Skip to content

Commit

Permalink
Add Docker Compose Service Connection for Weaviate
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed May 17, 2024
1 parent 06e3a1f commit 6983a39
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.weaviate;

import org.springframework.ai.autoconfigure.vectorstore.weaviate.WeaviateConnectionDetails;
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;

/**
* @author Eddú Meléndez
*/
class WeaviateDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<WeaviateConnectionDetails> {

private static final String[] WEAVIATE_CONTAINER_NAMES = { "semitechnologies/weaviate",
"cr.weaviate.io/semitechnologies/weaviate" };

private static final int WEAVIATE_PORT = 8080;

protected WeaviateDockerComposeConnectionDetailsFactory() {
super(WEAVIATE_CONTAINER_NAMES);
}

@Override
protected WeaviateConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
return new WeaviateDockerComposeConnectionDetails(source.getRunningService());
}

/**
* {@link WeaviateConnectionDetails} backed by a {@code Weaviate}
* {@link RunningService}.
*/
static class WeaviateDockerComposeConnectionDetails extends DockerComposeConnectionDetails
implements WeaviateConnectionDetails {

private final String host;

WeaviateDockerComposeConnectionDetails(RunningService service) {
super(service);
this.host = service.host() + ":" + service.ports().get(WEAVIATE_PORT);
}

@Override
public String getHost() {
return this.host;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFacto
org.springframework.ai.docker.compose.service.connection.chroma.ChromaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.ollama.OllamaDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.qdrant.QdrantDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.redis.RedisDockerComposeConnectionDetailsFactory
org.springframework.ai.docker.compose.service.connection.redis.RedisDockerComposeConnectionDetailsFactory,\
org.springframework.ai.docker.compose.service.connection.weaviate.WeaviateDockerComposeConnectionDetailsFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.springframework.ai.docker.compose.service.connection.weaviate;

import org.junit.jupiter.api.Test;
import org.springframework.ai.autoconfigure.vectorstore.weaviate.WeaviateConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.testcontainers.utility.DockerImageName;

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

class WeaviateDockerComposeConnectionDetailsFactoryTests extends AbstractDockerComposeIntegrationTests {

WeaviateDockerComposeConnectionDetailsFactoryTests() {
super("weaviate-compose.yaml", DockerImageName.parse("semitechnologies/weaviate"));
}

@Test
void runCreatesConnectionDetails() {
WeaviateConnectionDetails connectionDetails = run(WeaviateConnectionDetails.class);
assertThat(connectionDetails.getHost()).isNotNull();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
weaviate:
image: '{imageName}'
ports:
- '8080'

0 comments on commit 6983a39

Please sign in to comment.