[RAG] 全部LLM硬编码从deepseek-r1改为deepseek-v3;修复知识库问答source格式不匹配导致检索结果被丢弃

This commit is contained in:
2026-04-07 10:32:14 +08:00
parent 4e00a1b15e
commit a5110da4e8
12 changed files with 18 additions and 17 deletions

View File

@@ -34,7 +34,7 @@ async def search_engine_iter(query: str , uid: str):
response = await search_engine_chat(uid = uid, response = await search_engine_chat(uid = uid,
query=query, query=query,
search_engine_name="zhipu_search", search_engine_name="zhipu_search",
model_name=LLM_MODELS[1], model_name=LLM_MODELS[0],
temperature=TEMPERATURE, # Agent搜索互联网的时候温度设为0.1 temperature=TEMPERATURE, # Agent搜索互联网的时候温度设为0.1
history=[], history=[],
top_k=VECTOR_SEARCH_TOP_K, top_k=VECTOR_SEARCH_TOP_K,

View File

@@ -62,7 +62,7 @@ async def chat(query: str = Body(..., description="用户输入", examples=["恼
if prompt_name == "Search Summary": if prompt_name == "Search Summary":
model = get_ChatOpenAI( model = get_ChatOpenAI(
model_name=LLM_MODELS[1], model_name=LLM_MODELS[0],
temperature=temperature, temperature=temperature,
max_tokens=max_tokens, max_tokens=max_tokens,
callbacks=callbacks, callbacks=callbacks,

View File

@@ -46,7 +46,7 @@ async def chat_comparison_test(
executor.submit( executor.submit(
get_llm_model_response, get_llm_model_response,
strategy_name="query rewrite", strategy_name="query rewrite",
llm_model_name=LLM_MODELS[1], llm_model_name=LLM_MODELS[0],
template_prompt_name="extract_key_points", template_prompt_name="extract_key_points",
prompt_param_dict={"time": datetime.now().strftime("%Y%m%d"), "context": context, "content": content}, prompt_param_dict={"time": datetime.now().strftime("%Y%m%d"), "context": context, "content": content},
temperature=0.01, temperature=0.01,

View File

@@ -44,7 +44,7 @@ async def gen_abstract(
try: try:
article_abstract = get_llm_model_response( article_abstract = get_llm_model_response(
strategy_name="gen_abstract", strategy_name="gen_abstract",
llm_model_name=LLM_MODELS[1], llm_model_name=LLM_MODELS[0],
template_prompt_name="gen_abstract", template_prompt_name="gen_abstract",
prompt_param_dict={ prompt_param_dict={
"context": context_summary, # 使用摘要或原文 "context": context_summary, # 使用摘要或原文

View File

@@ -44,7 +44,7 @@ async def gen_conclusion(
try: try:
article_conclusion = get_llm_model_response( article_conclusion = get_llm_model_response(
strategy_name="gen_conclusion", strategy_name="gen_conclusion",
llm_model_name=LLM_MODELS[1], llm_model_name=LLM_MODELS[0],
template_prompt_name="gen_conclusion", template_prompt_name="gen_conclusion",
prompt_param_dict={ prompt_param_dict={
"context": context_summary, # 使用摘要或原文 "context": context_summary, # 使用摘要或原文

View File

@@ -43,7 +43,7 @@ async def gen_keywords(
try: try:
article_keywords = get_llm_model_response( article_keywords = get_llm_model_response(
strategy_name="gen_keywords", strategy_name="gen_keywords",
llm_model_name=LLM_MODELS[1], llm_model_name=LLM_MODELS[0],
template_prompt_name="gen_keywords", template_prompt_name="gen_keywords",
prompt_param_dict={ prompt_param_dict={
"context": context_summary, # 使用摘要或原文 "context": context_summary, # 使用摘要或原文

View File

@@ -44,7 +44,7 @@ async def gen_paragraph(
try: try:
article_paragraph = get_llm_model_response( article_paragraph = get_llm_model_response(
strategy_name="gen_paragraph", strategy_name="gen_paragraph",
llm_model_name=LLM_MODELS[1], llm_model_name=LLM_MODELS[0],
template_prompt_name="gen_paragraph", template_prompt_name="gen_paragraph",
prompt_param_dict={ prompt_param_dict={
"context": context_summary, # 使用摘要或原文 "context": context_summary, # 使用摘要或原文

View File

@@ -19,7 +19,7 @@ async def gen_title(
"content": "我们来玩成语接龙,我先来,生龙活虎"}, "content": "我们来玩成语接龙,我先来,生龙活虎"},
{"role": "assistant", "content": "虎头虎脑"}]] {"role": "assistant", "content": "虎头虎脑"}]]
), ),
model_name: Optional[str] = Body(LLM_MODELS[1], description="LLM 模型名称。"), model_name: Optional[str] = Body(LLM_MODELS[0], description="LLM 模型名称。"),
): ):
""" """
根据一轮对话历史生成简洁标题\n 根据一轮对话历史生成简洁标题\n
@@ -32,7 +32,7 @@ async def gen_title(
if model_name == "R1-70B": if model_name == "R1-70B":
model_name = DEEPSEEK_MODELS[1] model_name = DEEPSEEK_MODELS[1]
elif model_name == "QIANWEN": elif model_name == "QIANWEN":
model_name = LLM_MODELS[1] model_name = LLM_MODELS[0]
else: else:
model_name = model_name model_name = model_name

View File

@@ -138,7 +138,7 @@ async def knowledge_base_chat(query: str = Body(..., description="用户输入",
if isinstance(max_tokens, int) and max_tokens <= 0: if isinstance(max_tokens, int) and max_tokens <= 0:
max_tokens = None max_tokens = None
if prompt_name == "policy_chat": if prompt_name == "policy_chat":
model_name = LLM_MODELS[1] model_name = LLM_MODELS[0]
model = get_ChatOpenAI( model = get_ChatOpenAI(
model_name=model_name, model_name=model_name,
temperature=temperature, temperature=temperature,

View File

@@ -364,7 +364,7 @@ async def search_engine_chat(uid: Optional[str]=Body(None, description="userID")
"content": "虎头虎脑"}]] "content": "虎头虎脑"}]]
), ),
stream: bool = Body(False, description="流式输出"), stream: bool = Body(False, description="流式输出"),
model_name: str = Body(LLM_MODELS[1], description="LLM 模型名称。"), model_name: str = Body(LLM_MODELS[0], description="LLM 模型名称。"),
temperature: float = Body(TEMPERATURE, description="LLM 采样温度", ge=0.0, le=1.0), temperature: float = Body(TEMPERATURE, description="LLM 采样温度", ge=0.0, le=1.0),
max_tokens: Optional[int] = Body(None, description="限制LLM生成Token数量默认None代表模型最大值"), max_tokens: Optional[int] = Body(None, description="限制LLM生成Token数量默认None代表模型最大值"),
prompt_name: str = Body("default", prompt_name: str = Body("default",
@@ -483,7 +483,7 @@ async def search_engine_chat(uid: Optional[str]=Body(None, description="userID")
search_engine_name: str, search_engine_name: str,
top_k: int, top_k: int,
history: Optional[List[History]], history: Optional[List[History]],
model_name: str = LLM_MODELS[1], model_name: str = LLM_MODELS[0],
prompt_name: str = prompt_name, prompt_name: str = prompt_name,
kgo_search_type: str = kgo_search_type kgo_search_type: str = kgo_search_type
) -> AsyncIterable[str]: ) -> AsyncIterable[str]:

View File

@@ -72,7 +72,7 @@ async def self_kb_chat(
async def knowledge_base_chat_iterator( async def knowledge_base_chat_iterator(
query: str, query: str,
model_name: str = LLM_MODELS[0], model_name: str = LLM_MODELS[0],
model_name1: str = LLM_MODELS[1], model_name1: str = LLM_MODELS[0],
prompt_name: str = "self_default", prompt_name: str = "self_default",
) -> AsyncIterable[str]: ) -> AsyncIterable[str]:
nonlocal fileNames, history nonlocal fileNames, history

View File

@@ -116,15 +116,16 @@ def search_self_docs(
if top_k > 50: if top_k > 50:
data = docs data = docs
else: else:
# Milvus 已通过 expr 过滤了 source无需再按 fileNames 二次过滤
# Milvus 的 source 可能是原始文件名,而 fileNames 是 embeddingId格式不一致
data = [ data = [
DocumentWithVSId( DocumentWithVSId(
**{k: v for k, v in x[0].dict().items() if k != 'page_content'}, # 排除原有的 page_content **{k: v for k, v in x[0].dict().items() if k != 'page_content'},
score=x[1], score=x[1],
id=x[0].metadata.get("id"), id=x[0].metadata.get("id"),
page_content=f"【^[{index +1}]^ {x[0].page_content}" # 拼接索引和page_content page_content=f"【^[{index +1}]^ {x[0].page_content}"
) )
for index, x in enumerate(docs) # 使用enumerate来获取索引 for index, x in enumerate(docs)
if x[0].metadata.get("source") in flat_fileNames
] ]
else: else:
logger.warning(f"未找到知识库服务: {knowledge_base_name}") logger.warning(f"未找到知识库服务: {knowledge_base_name}")