From cc8029a732514375907003d6686688488efdc4e6 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Wed, 26 Mar 2025 15:37:48 +0800 Subject: [PATCH] Fix: uploading in chat box issue. (#6547) ### What problem does this PR solve? #6228 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/llm/__init__.py | 4 +++- rag/llm/cv_model.py | 7 +++++++ rag/nlp/search.py | 21 ++++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/rag/llm/__init__.py b/rag/llm/__init__.py index c7790a986..708ed4372 100644 --- a/rag/llm/__init__.py +++ b/rag/llm/__init__.py @@ -106,7 +106,8 @@ from .cv_model import ( TogetherAICV, YiCV, HunyuanCV, - AnthropicCV + AnthropicCV, + SILICONFLOWCV ) from .rerank_model import ( @@ -200,6 +201,7 @@ CvModel = { "01.AI": YiCV, "Tencent Hunyuan": HunyuanCV, "Anthropic": AnthropicCV, + "SILICONFLOW": SILICONFLOWCV, } ChatModel = { diff --git a/rag/llm/cv_model.py b/rag/llm/cv_model.py index 50b7d1a39..ce317ea6f 100644 --- a/rag/llm/cv_model.py +++ b/rag/llm/cv_model.py @@ -833,6 +833,13 @@ class YiCV(GptV4): super().__init__(key, model_name, lang, base_url) +class SILICONFLOWCV(GptV4): + def __init__(self, key, model_name, lang="Chinese", base_url="https://api.siliconflow.cn/v1",): + if not base_url: + base_url = "https://api.siliconflow.cn/v1" + super().__init__(key, model_name, lang, base_url) + + class HunyuanCV(Base): def __init__(self, key, model_name, lang="Chinese", base_url=None): from tencentcloud.common import credential diff --git a/rag/nlp/search.py b/rag/nlp/search.py index d0d041452..b18bfd52a 100644 --- a/rag/nlp/search.py +++ b/rag/nlp/search.py @@ -119,13 +119,17 @@ class Dealer: # If result is empty, try again with lower min_match if total == 0: - matchText, _ = self.qryr.question(qst, min_match=0.1) - filters.pop("doc_ids", None) - matchDense.extra_options["similarity"] = 0.17 - res = self.dataStore.search(src, highlightFields, filters, [matchText, matchDense, fusionExpr], - orderBy, offset, limit, idx_names, kb_ids, rank_feature=rank_feature) - total = self.dataStore.getTotal(res) - logging.debug("Dealer.search 2 TOTAL: {}".format(total)) + if filters.get("doc_id"): + res = self.dataStore.search(src, [], filters, [], orderBy, offset, limit, idx_names, kb_ids) + total = self.dataStore.getTotal(res) + else: + matchText, _ = self.qryr.question(qst, min_match=0.1) + filters.pop("doc_id", None) + matchDense.extra_options["similarity"] = 0.17 + res = self.dataStore.search(src, highlightFields, filters, [matchText, matchDense, fusionExpr], + orderBy, offset, limit, idx_names, kb_ids, rank_feature=rank_feature) + total = self.dataStore.getTotal(res) + logging.debug("Dealer.search 2 TOTAL: {}".format(total)) for k in keywords: kwds.add(k) @@ -375,6 +379,9 @@ class Dealer: dim = len(sres.query_vector) vector_column = f"q_{dim}_vec" zero_vector = [0.0] * dim + if doc_ids: + similarity_threshold = 0 + page_size = 30 for i in idx: if sim[i] < similarity_threshold: break