From 58bd8b7ff1c0445012feb85b5800f5200c526b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Wed, 25 Feb 2026 17:07:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DFAQ=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=90=8E=E5=90=91=E9=87=8F=E6=95=B0=E6=8D=AE=E6=9C=AA=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/service/impl/FaqItemServiceImpl.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/service/impl/FaqItemServiceImpl.java b/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/service/impl/FaqItemServiceImpl.java index 176e7fb..bc424e5 100644 --- a/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/service/impl/FaqItemServiceImpl.java +++ b/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/service/impl/FaqItemServiceImpl.java @@ -11,6 +11,8 @@ import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.spring.service.impl.ServiceImpl; import org.jsoup.Jsoup; import org.jsoup.safety.Safelist; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,8 +21,8 @@ import tech.easyflow.ai.entity.DocumentCollection; import tech.easyflow.ai.entity.FaqItem; import tech.easyflow.ai.entity.Model; import tech.easyflow.ai.mapper.FaqItemMapper; -import tech.easyflow.ai.service.FaqCategoryService; import tech.easyflow.ai.service.DocumentCollectionService; +import tech.easyflow.ai.service.FaqCategoryService; import tech.easyflow.ai.service.FaqItemService; import tech.easyflow.ai.service.ModelService; import tech.easyflow.common.util.StringUtil; @@ -28,10 +30,7 @@ import tech.easyflow.common.web.exceptions.BusinessException; import javax.annotation.Resource; import java.math.BigInteger; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import static tech.easyflow.ai.entity.DocumentCollection.KEY_CAN_UPDATE_EMBEDDING_MODEL; import static tech.easyflow.ai.entity.DocumentCollection.KEY_SEARCH_ENGINE_TYPE; @@ -39,6 +38,7 @@ import static tech.easyflow.ai.entity.DocumentCollection.KEY_SEARCH_ENGINE_TYPE; @Service public class FaqItemServiceImpl extends ServiceImpl implements FaqItemService { + private static final Logger LOG = LoggerFactory.getLogger(FaqItemServiceImpl.class); private static final Safelist ANSWER_SAFE_LIST = Safelist.basic() .addTags("h1", "h2", "h3", "h4", "h5", "h6"); @@ -190,16 +190,44 @@ public class FaqItemServiceImpl extends ServiceImpl impl private void removeFromVector(DocumentCollection collection, FaqItem entity) { PreparedStore preparedStore = prepareStore(collection); - preparedStore.documentStore.delete(Collections.singletonList(entity.getId()), preparedStore.storeOptions); + boolean deleteSuccess = deleteFromVectorStore(preparedStore.documentStore, preparedStore.storeOptions, entity.getId()); + if (!deleteSuccess) { + throw new BusinessException("FAQ向量删除失败"); + } if (collection.isSearchEngineEnabled()) { DocumentSearcher searcher = searcherFactory.getSearcher((String) collection.getOptionsByKey(KEY_SEARCH_ENGINE_TYPE)); if (searcher != null) { - searcher.deleteDocument(entity.getId()); + boolean removed = searcher.deleteDocument(entity.getId()); + if (!removed) { + LOG.warn("Delete faq search index failed. faqId={}, searcherType={}", + entity.getId(), collection.getOptionsByKey(KEY_SEARCH_ENGINE_TYPE)); + } } } } + private boolean deleteFromVectorStore(DocumentStore documentStore, StoreOptions storeOptions, BigInteger id) { + List candidates = new ArrayList<>(3); + candidates.add(id); + candidates.add(String.valueOf(id)); + try { + candidates.add(id.longValueExact()); + } catch (ArithmeticException ignored) { + // 非 long 范围不追加 long 类型候选 + } + + for (Object candidate : candidates) { + StoreResult deleteResult = documentStore.delete(Collections.singletonList(candidate), storeOptions); + if (deleteResult != null && deleteResult.isSuccess()) { + return true; + } + LOG.warn("Delete faq vector by id candidate failed. faqId={}, candidateType={}, candidate={}", + id, candidate == null ? "null" : candidate.getClass().getSimpleName(), candidate); + } + return false; + } + private PreparedStore prepareStore(DocumentCollection collection) { DocumentStore documentStore; try {