fix(rag): 隔离模型实例并修正缓存刷新

This commit is contained in:
evo
2026-07-21 09:35:07 +08:00
parent 6f6d0893ec
commit c4fc1e6fcf
12 changed files with 34 additions and 5 deletions

View File

@@ -77,13 +77,22 @@ public class EmbeddingModelFactory {
/** /**
* 刷新模型缓存 * 刷新模型缓存
* 根据给定的嵌入模型ID从缓存中移除对应的模型 * 根据给定的嵌入模型ID解析模型名称后,从缓存中移除对应的模型
* *
* @param embeddingModelId 嵌入模型的唯一标识ID * @param embeddingModelId 嵌入模型的唯一标识ID
*/ */
public void refreshModel(Long embeddingModelId) { public void refreshModel(Long embeddingModelId) {
// 从模型缓存中移除指定ID的模型 ChatModelVo modelConfig = chatModelService.queryById(embeddingModelId);
modelCache.remove(embeddingModelId); if (modelConfig != null) {
modelCache.remove(modelConfig.getModelName());
}
}
/**
* 按模型名称刷新缓存
*/
public void refreshModelByName(String embeddingModelName) {
modelCache.remove(embeddingModelName);
} }
/** /**

View File

@@ -55,12 +55,22 @@ public class RerankModelFactory {
/** /**
* 刷新模型缓存 * 刷新模型缓存
* 根据给定的模型ID从缓存中移除对应的模型 * 根据给定的模型ID解析模型名称后,从缓存中移除对应的模型
* *
* @param modelId 模型的唯一标识ID * @param modelId 模型的唯一标识ID
*/ */
public void refreshModel(Long modelId) { public void refreshModel(Long modelId) {
modelCache.remove(modelId); ChatModelVo modelConfig = chatModelService.queryById(modelId);
if (modelConfig != null) {
modelCache.remove(modelConfig.getModelName());
}
}
/**
* 按模型名称刷新缓存
*/
public void refreshModelByName(String modelName) {
modelCache.remove(modelName);
} }
/** /**

View File

@@ -19,6 +19,7 @@ import java.util.Set;
* @Description: 阿里百炼基础嵌入模型兼容openai * @Description: 阿里百炼基础嵌入模型兼容openai
*/ */
@Component("alibailian") @Component("alibailian")
@org.springframework.context.annotation.Scope("prototype")
public class AliBaiLianBaseEmbedProvider extends OpenAiEmbeddingProvider { public class AliBaiLianBaseEmbedProvider extends OpenAiEmbeddingProvider {
private ChatModelVo chatModelVo; private ChatModelVo chatModelVo;

View File

@@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
* 实现了MultiModalEmbedModelService接口提供文本、图像和视频的嵌入向量生成服务 * 实现了MultiModalEmbedModelService接口提供文本、图像和视频的嵌入向量生成服务
*/ */
@Component("bailianMultiModel") @Component("bailianMultiModel")
@org.springframework.context.annotation.Scope("prototype")
@Slf4j @Slf4j
public class AliBaiLianMultiEmbeddingProvider implements MultiModalEmbedModelService { public class AliBaiLianMultiEmbeddingProvider implements MultiModalEmbedModelService {
private final OkHttpClient okHttpClient; private final OkHttpClient okHttpClient;

View File

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
* @date 2026/3/21 * @date 2026/3/21
*/ */
@Component("minimax") @Component("minimax")
@org.springframework.context.annotation.Scope("prototype")
public class MinimaxEmbeddingProvider extends OpenAiEmbeddingProvider { public class MinimaxEmbeddingProvider extends OpenAiEmbeddingProvider {
} }

View File

@@ -19,6 +19,7 @@ import java.util.Set;
* @Description: Ollama嵌入模型 * @Description: Ollama嵌入模型
*/ */
@Component("ollama") @Component("ollama")
@org.springframework.context.annotation.Scope("prototype")
public class OllamaEmbeddingProvider implements BaseEmbedModelService { public class OllamaEmbeddingProvider implements BaseEmbedModelService {
private ChatModelVo chatModelVo; private ChatModelVo chatModelVo;

View File

@@ -19,6 +19,7 @@ import java.util.Set;
* @Description: OpenAi嵌入模型 * @Description: OpenAi嵌入模型
*/ */
@Component("openai") @Component("openai")
@org.springframework.context.annotation.Scope("prototype")
public class OpenAiEmbeddingProvider implements BaseEmbedModelService { public class OpenAiEmbeddingProvider implements BaseEmbedModelService {
protected ChatModelVo chatModelVo; protected ChatModelVo chatModelVo;

View File

@@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
* @Description: 硅基流动(兼容 OpenAi * @Description: 硅基流动(兼容 OpenAi
*/ */
@Component("siliconflow") @Component("siliconflow")
@org.springframework.context.annotation.Scope("prototype")
public class SiliconFlowEmbeddingProvider extends OpenAiEmbeddingProvider { public class SiliconFlowEmbeddingProvider extends OpenAiEmbeddingProvider {
} }

View File

@@ -21,6 +21,7 @@ import java.util.Set;
* @Description: 智谱AI嵌入模型 * @Description: 智谱AI嵌入模型
*/ */
@Component("zhipu") @Component("zhipu")
@org.springframework.context.annotation.Scope("prototype")
public class ZhipuAiEmbeddingProvider implements BaseEmbedModelService { public class ZhipuAiEmbeddingProvider implements BaseEmbedModelService {
protected ChatModelVo chatModelVo; protected ChatModelVo chatModelVo;

View File

@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
*/ */
@Slf4j @Slf4j
@Component("qianwenRerank") @Component("qianwenRerank")
@org.springframework.context.annotation.Scope("prototype")
public class AliBaiLianRerankModelService implements RerankModelService { public class AliBaiLianRerankModelService implements RerankModelService {
private final OkHttpClient okHttpClient; private final OkHttpClient okHttpClient;

View File

@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
*/ */
@Slf4j @Slf4j
@Component("siliconflowRerank") @Component("siliconflowRerank")
@org.springframework.context.annotation.Scope("prototype")
public class SiliconFlowRerankModelService implements RerankModelService { public class SiliconFlowRerankModelService implements RerankModelService {
private static final String DEFAULT_BASE_URL = "https://api.siliconflow.cn/v1/rerank"; private static final String DEFAULT_BASE_URL = "https://api.siliconflow.cn/v1/rerank";

View File

@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
*/ */
@Slf4j @Slf4j
@Component("zhipuRerank") @Component("zhipuRerank")
@org.springframework.context.annotation.Scope("prototype")
public class ZhiPuRerankModelService implements RerankModelService { public class ZhiPuRerankModelService implements RerankModelService {
private final OkHttpClient okHttpClient; private final OkHttpClient okHttpClient;