[improvement][chat] Optimize the logic for obtaining the generic thread pool (#1979)

This commit is contained in:
lexluo09
2024-12-26 23:37:55 +08:00
committed by GitHub
parent 94267f6028
commit a23d1071a3
6 changed files with 33 additions and 26 deletions

View File

@@ -1,6 +1,5 @@
package com.tencent.supersonic.headless.chat.mapper;
import com.tencent.supersonic.common.config.ThreadPoolConfig;
import com.tencent.supersonic.headless.api.pojo.enums.MapModeEnum;
import com.tencent.supersonic.headless.api.pojo.response.S2Term;
import com.tencent.supersonic.headless.chat.ChatQueryContext;
@@ -9,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -17,13 +17,15 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
@Service
@Slf4j
public abstract class BaseMatchStrategy<T extends MapResult> implements MatchStrategy<T> {
@Autowired
protected ThreadPoolConfig threadPoolConfig;
@Qualifier("mapExecutor")
private ThreadPoolExecutor executor;
@Override
public Map<MatchText, List<T>> match(ChatQueryContext chatQueryContext, List<S2Term> terms,
@@ -72,7 +74,7 @@ public abstract class BaseMatchStrategy<T extends MapResult> implements MatchStr
protected void executeTasks(List<Callable<Void>> tasks) {
try {
threadPoolConfig.getMapExecutor().invokeAll(tasks);
executor.invokeAll(tasks);
for (Callable<Void> future : tasks) {
future.call();
}

View File

@@ -1,7 +1,6 @@
package com.tencent.supersonic.headless.chat.mapper;
import com.google.common.collect.Lists;
import com.tencent.supersonic.common.config.ThreadPoolConfig;
import com.tencent.supersonic.headless.chat.ChatQueryContext;
import com.tencent.supersonic.headless.chat.knowledge.EmbeddingResult;
import com.tencent.supersonic.headless.chat.knowledge.MetaEmbeddingService;
@@ -38,8 +37,6 @@ public class EmbeddingMatchStrategy extends BatchMatchStrategy<EmbeddingResult>
@Autowired
private MetaEmbeddingService metaEmbeddingService;
@Autowired
protected ThreadPoolConfig threadPoolConfig;
@Override
public List<EmbeddingResult> detectByBatch(ChatQueryContext chatQueryContext,