mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-28 11:48:10 +08:00
Fix search vector_similarity_weight (#15108)
### What problem does this PR solve? Fix search vector_similarity_weight ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -938,6 +938,8 @@ async def search(dataset_id: str, tenant_id: str, req: dict):
|
||||
question = req.get("question", "")
|
||||
doc_ids = req.get("doc_ids", [])
|
||||
use_kg = req.get("use_kg", False)
|
||||
similarity_threshold = float(req.get("similarity_threshold", 0.0))
|
||||
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
|
||||
top = max(1, min(int(req.get("top_k", 1024)), 2048))
|
||||
langs = req.get("cross_languages", [])
|
||||
|
||||
@@ -955,14 +957,31 @@ async def search(dataset_id: str, tenant_id: str, req: dict):
|
||||
local_doc_ids = list(doc_ids) if doc_ids else []
|
||||
|
||||
meta_data_filter = {}
|
||||
search_id = req.get("search_id", "")
|
||||
search_config = {}
|
||||
chat_mdl = None
|
||||
if req.get("search_id", ""):
|
||||
search_detail = SearchService.get_detail(req.get("search_id", ""))
|
||||
if search_id:
|
||||
search_detail = SearchService.get_detail(search_id)
|
||||
if not search_detail:
|
||||
logging.warning("search config not found: search_id=%s", req.get("search_id", ""))
|
||||
logging.warning("search config not found: search_id=%s", search_id)
|
||||
return False, "Invalid search_id"
|
||||
search_config = search_detail.get("search_config", {})
|
||||
meta_data_filter = search_config.get("meta_data_filter", {})
|
||||
similarity_threshold = float(search_config.get("similarity_threshold", similarity_threshold))
|
||||
vector_similarity_weight = float(search_config.get("vector_similarity_weight", vector_similarity_weight))
|
||||
top = max(1, min(int(search_config.get("top_k", top)), 2048))
|
||||
use_kg = search_config.get("use_kg", use_kg)
|
||||
langs = search_config.get("cross_languages", langs)
|
||||
logging.debug(
|
||||
"Dataset search loaded Search config: search_id=%s dataset_id=%s "
|
||||
"vector_similarity_weight=%s full_text_weight=%s similarity_threshold=%s top_k=%s",
|
||||
search_id,
|
||||
dataset_id,
|
||||
vector_similarity_weight,
|
||||
1 - vector_similarity_weight,
|
||||
similarity_threshold,
|
||||
top,
|
||||
)
|
||||
if meta_data_filter.get("method") in ["auto", "semi_auto"]:
|
||||
chat_id = search_config.get("chat_id", "")
|
||||
if chat_id:
|
||||
@@ -1016,11 +1035,13 @@ async def search(dataset_id: str, tenant_id: str, req: dict):
|
||||
requester_tenant_id=tenant_id,
|
||||
)
|
||||
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
||||
elif req.get("rerank_id"):
|
||||
rerank_model_config = get_model_config_by_type_and_name(kb.tenant_id, LLMType.RERANK.value, req["rerank_id"])
|
||||
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
||||
else:
|
||||
rerank_id = search_config.get("rerank_id") or req.get("rerank_id")
|
||||
if rerank_id:
|
||||
rerank_model_config = get_model_config_by_type_and_name(kb.tenant_id, LLMType.RERANK.value, rerank_id)
|
||||
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
||||
|
||||
if req.get("keyword", False):
|
||||
if search_config.get("keyword", req.get("keyword", False)):
|
||||
default_chat_model_config = get_tenant_default_model_by_type(kb.tenant_id, LLMType.CHAT)
|
||||
chat_mdl = LLMBundle(kb.tenant_id, default_chat_model_config)
|
||||
_question += await keyword_extraction(chat_mdl, _question)
|
||||
@@ -1033,12 +1054,13 @@ async def search(dataset_id: str, tenant_id: str, req: dict):
|
||||
[dataset_id],
|
||||
page,
|
||||
size,
|
||||
float(req.get("similarity_threshold", 0.0)),
|
||||
float(req.get("vector_similarity_weight", 0.3)),
|
||||
similarity_threshold,
|
||||
vector_similarity_weight,
|
||||
doc_ids=local_doc_ids,
|
||||
top=top,
|
||||
rerank_mdl=rerank_mdl,
|
||||
rank_feature=labels,
|
||||
trace_id=search_id,
|
||||
)
|
||||
|
||||
if use_kg:
|
||||
@@ -1291,6 +1313,8 @@ async def search_datasets(tenant_id: str, req: dict):
|
||||
question = req.get("question", "")
|
||||
doc_ids = req.get("doc_ids", [])
|
||||
use_kg = req.get("use_kg", False)
|
||||
similarity_threshold = float(req.get("similarity_threshold", 0.0))
|
||||
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
|
||||
top = max(1, min(int(req.get("top_k", 1024)), 2048))
|
||||
langs = req.get("cross_languages", [])
|
||||
|
||||
@@ -1321,14 +1345,31 @@ async def search_datasets(tenant_id: str, req: dict):
|
||||
local_doc_ids = list(doc_ids) if doc_ids else []
|
||||
|
||||
meta_data_filter = {}
|
||||
search_id = req.get("search_id", "")
|
||||
search_config = {}
|
||||
chat_mdl = None
|
||||
if req.get("search_id", ""):
|
||||
search_detail = SearchService.get_detail(req.get("search_id", ""))
|
||||
if search_id:
|
||||
search_detail = SearchService.get_detail(search_id)
|
||||
if not search_detail:
|
||||
logging.warning("search config not found: search_id=%s", req.get("search_id", ""))
|
||||
logging.warning("search config not found: search_id=%s", search_id)
|
||||
return False, "Invalid search_id"
|
||||
search_config = search_detail.get("search_config", {})
|
||||
meta_data_filter = search_config.get("meta_data_filter", {})
|
||||
similarity_threshold = float(search_config.get("similarity_threshold", similarity_threshold))
|
||||
vector_similarity_weight = float(search_config.get("vector_similarity_weight", vector_similarity_weight))
|
||||
top = max(1, min(int(search_config.get("top_k", top)), 2048))
|
||||
use_kg = search_config.get("use_kg", use_kg)
|
||||
langs = search_config.get("cross_languages", langs)
|
||||
logging.debug(
|
||||
"Dataset search loaded Search config: search_id=%s dataset_ids=%s "
|
||||
"vector_similarity_weight=%s full_text_weight=%s similarity_threshold=%s top_k=%s",
|
||||
search_id,
|
||||
kb_ids,
|
||||
vector_similarity_weight,
|
||||
1 - vector_similarity_weight,
|
||||
similarity_threshold,
|
||||
top,
|
||||
)
|
||||
if meta_data_filter.get("method") in ["auto", "semi_auto"]:
|
||||
chat_id = search_config.get("chat_id", "")
|
||||
if chat_id:
|
||||
@@ -1384,11 +1425,13 @@ async def search_datasets(tenant_id: str, req: dict):
|
||||
requester_tenant_id=tenant_id,
|
||||
)
|
||||
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
||||
elif req.get("rerank_id"):
|
||||
rerank_model_config = get_model_config_by_type_and_name(kb.tenant_id, LLMType.RERANK.value, req["rerank_id"])
|
||||
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
||||
else:
|
||||
rerank_id = search_config.get("rerank_id") or req.get("rerank_id")
|
||||
if rerank_id:
|
||||
rerank_model_config = get_model_config_by_type_and_name(kb.tenant_id, LLMType.RERANK.value, rerank_id)
|
||||
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
||||
|
||||
if req.get("keyword", False):
|
||||
if search_config.get("keyword", req.get("keyword", False)):
|
||||
default_chat_model_config = get_tenant_default_model_by_type(kb.tenant_id, LLMType.CHAT)
|
||||
chat_mdl = LLMBundle(kb.tenant_id, default_chat_model_config)
|
||||
_question += await keyword_extraction(chat_mdl, _question)
|
||||
@@ -1401,12 +1444,13 @@ async def search_datasets(tenant_id: str, req: dict):
|
||||
kb_ids,
|
||||
page,
|
||||
size,
|
||||
float(req.get("similarity_threshold", 0.0)),
|
||||
float(req.get("vector_similarity_weight", 0.3)),
|
||||
similarity_threshold,
|
||||
vector_similarity_weight,
|
||||
doc_ids=local_doc_ids,
|
||||
top=top,
|
||||
rerank_mdl=rerank_mdl,
|
||||
rank_feature=labels,
|
||||
trace_id=search_id,
|
||||
)
|
||||
|
||||
if use_kg:
|
||||
|
||||
Reference in New Issue
Block a user