mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(improvement)(chat) It supports successful startup using Docker, local, and other methods. If the Chroma store creation fails, it will be replaced with in-memory (#1301)
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package dev.langchain4j.chroma.spring;
|
||||
|
||||
import dev.langchain4j.inmemory.spring.InMemoryEmbeddingStoreFactory;
|
||||
import dev.langchain4j.store.embedding.EmbeddingStore;
|
||||
import dev.langchain4j.store.embedding.EmbeddingStoreFactory;
|
||||
import dev.langchain4j.store.embedding.chroma.ChromaEmbeddingStore;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class ChromaEmbeddingStoreFactory implements EmbeddingStoreFactory {
|
||||
|
||||
private Properties properties;
|
||||
@@ -14,11 +18,30 @@ public class ChromaEmbeddingStoreFactory implements EmbeddingStoreFactory {
|
||||
|
||||
@Override
|
||||
public EmbeddingStore create(String collectionName) {
|
||||
EmbeddingStoreProperties embeddingStore = properties.getEmbeddingStore();
|
||||
return ChromaEmbeddingStore.builder()
|
||||
.baseUrl(embeddingStore.getBaseUrl())
|
||||
.collectionName(collectionName)
|
||||
.timeout(embeddingStore.getTimeout())
|
||||
.build();
|
||||
EmbeddingStoreProperties storeProperties = properties.getEmbeddingStore();
|
||||
EmbeddingStore embeddingStore = null;
|
||||
try {
|
||||
embeddingStore = ChromaEmbeddingStore.builder()
|
||||
.baseUrl(storeProperties.getBaseUrl())
|
||||
.collectionName(collectionName)
|
||||
.timeout(storeProperties.getTimeout())
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to create ChromaEmbeddingStore,collectionName:{}"
|
||||
+ ", fallback to the default InMemoryEmbeddingStore method。",
|
||||
collectionName, e.getMessage());
|
||||
}
|
||||
if (Objects.isNull(embeddingStore)) {
|
||||
embeddingStore = createInMemoryEmbeddingStore(collectionName);
|
||||
}
|
||||
return embeddingStore;
|
||||
}
|
||||
|
||||
private EmbeddingStore createInMemoryEmbeddingStore(String collectionName) {
|
||||
dev.langchain4j.inmemory.spring.Properties properties = new dev.langchain4j.inmemory.spring.Properties();
|
||||
dev.langchain4j.inmemory.spring.EmbeddingStoreProperties embeddingStoreProperties =
|
||||
new dev.langchain4j.inmemory.spring.EmbeddingStoreProperties();
|
||||
properties.setEmbeddingStore(embeddingStoreProperties);
|
||||
return new InMemoryEmbeddingStoreFactory(properties).create(collectionName);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
class EmbeddingStoreProperties {
|
||||
public class EmbeddingStoreProperties {
|
||||
|
||||
private String persistPath;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ WORKDIR /usr/src/app
|
||||
# Argument to pass in the supersonic version at build time
|
||||
ARG SUPERSONIC_VERSION
|
||||
|
||||
# Install the Vim editor.
|
||||
# Install the vim editor.
|
||||
RUN apt-get update && \
|
||||
apt-get install -y vim && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
@@ -1,4 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
# Please execute the "supersonic-build.sh" command first
|
||||
# to generate the corresponding zip package in the "assembly/build/" directory.
|
||||
docker build --no-cache --build-arg SUPERSONIC_VERSION=$1 -t supersonic:$1 -f docker/Dockerfile .
|
||||
|
||||
# Function to execute the build script
|
||||
execute_build_script() {
|
||||
echo "Executing build script: assembly/bin/supersonic-build.sh"
|
||||
assembly/bin/supersonic-build.sh
|
||||
}
|
||||
|
||||
# Function to build the Docker image
|
||||
build_docker_image() {
|
||||
local version=$1
|
||||
echo "Building Docker image: supersonic:$version"
|
||||
docker build --no-cache --build-arg SUPERSONIC_VERSION=$version -t supersonic:$version -f docker/Dockerfile .
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Docker build failed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
echo "Docker image supersonic:$version built successfully."
|
||||
}
|
||||
|
||||
# Main script execution
|
||||
VERSION=$1
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Usage: $0 <version>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
execute_build_script
|
||||
build_docker_image $VERSION
|
||||
@@ -1,15 +1,13 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: supersonic_mysql
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root_password
|
||||
MYSQL_DB_HOST: ${DB_HOST}
|
||||
MYSQL_DATABASE: ${DB_NAME}
|
||||
MYSQL_USER: ${DB_USERNAME}
|
||||
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||
MYSQL_DATABASE: supersonic_db
|
||||
MYSQL_USER: supersonic_user
|
||||
MYSQL_PASSWORD: supersonic_password
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
@@ -30,9 +28,9 @@ services:
|
||||
command: >
|
||||
sh -c "
|
||||
sleep 30 &&
|
||||
if ! mysql -h supersonic_mysql -uroot -proot_password -e 'use supersonic_db; show tables;' | grep -q 's2_database'; then
|
||||
mysql -h supersonic_mysql -uroot -proot_password supersonic_db < /usr/src/app/supersonic-standalone-0.9.2-SNAPSHOT/conf/db/schema-mysql.sql &&
|
||||
mysql -h supersonic_mysql -uroot -proot_password supersonic_db < /usr/src/app/supersonic-standalone-0.9.2-SNAPSHOT/conf/db/data-mysql.sql
|
||||
if ! mysql -h supersonic_mysql -usupersonic_user -psupersonic_password -e 'use supersonic_db; show tables;' | grep -q 's2_database'; then
|
||||
mysql -h supersonic_mysql -usupersonic_user -psupersonic_password supersonic_db < /usr/src/app/supersonic-standalone-0.9.2-SNAPSHOT/conf/db/schema-mysql.sql &&
|
||||
mysql -h supersonic_mysql -usupersonic_user -psupersonic_password supersonic_db < /usr/src/app/supersonic-standalone-0.9.2-SNAPSHOT/conf/db/data-mysql.sql
|
||||
else
|
||||
echo 'Database already initialized.'
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
server:
|
||||
port: 9080
|
||||
compression:
|
||||
enabled: true
|
||||
min-response-size: 1024
|
||||
mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/*
|
||||
|
||||
spring:
|
||||
h2:
|
||||
console:
|
||||
path: /h2-console/semantic
|
||||
enabled: true
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
schema: classpath:db/schema-h2.sql
|
||||
data: classpath:db/data-h2.sql
|
||||
url: jdbc:h2:mem:semantic;DATABASE_TO_UPPER=false
|
||||
username: root
|
||||
password: semantic
|
||||
|
||||
mybatis:
|
||||
mapper-locations=classpath:mappers/custom/*.xml,classpath*:/mappers/*.xml
|
||||
|
||||
logging:
|
||||
level:
|
||||
dev.langchain4j: DEBUG
|
||||
dev.ai4j.openai4j: DEBUG
|
||||
# swagger配置
|
||||
swagger:
|
||||
title: 'SuperSonic平台接口文档'
|
||||
base:
|
||||
package: com.tencent.supersonic
|
||||
description: 'SuperSonic平台接口文档'
|
||||
url: ''
|
||||
contact:
|
||||
name:
|
||||
email:
|
||||
url: ''
|
||||
version: 3.0
|
||||
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: prd
|
||||
active: local
|
||||
application:
|
||||
name: chat
|
||||
config:
|
||||
|
||||
30754
webapp/pnpm-lock.yaml
generated
30754
webapp/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user