mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
Fix: no result if metadata returns none. (#11412)
### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -137,7 +137,7 @@ class Retrieval(ToolBase, ABC):
|
|||||||
if not doc_ids:
|
if not doc_ids:
|
||||||
doc_ids = None
|
doc_ids = None
|
||||||
elif self._param.meta_data_filter.get("method") == "manual":
|
elif self._param.meta_data_filter.get("method") == "manual":
|
||||||
filters=self._param.meta_data_filter["manual"]
|
filters = self._param.meta_data_filter["manual"]
|
||||||
for flt in filters:
|
for flt in filters:
|
||||||
pat = re.compile(self.variable_ref_patt)
|
pat = re.compile(self.variable_ref_patt)
|
||||||
s = flt["value"]
|
s = flt["value"]
|
||||||
@ -166,8 +166,8 @@ class Retrieval(ToolBase, ABC):
|
|||||||
out_parts.append(s[last:])
|
out_parts.append(s[last:])
|
||||||
flt["value"] = "".join(out_parts)
|
flt["value"] = "".join(out_parts)
|
||||||
doc_ids.extend(meta_filter(metas, filters, self._param.meta_data_filter.get("logic", "and")))
|
doc_ids.extend(meta_filter(metas, filters, self._param.meta_data_filter.get("logic", "and")))
|
||||||
if not doc_ids:
|
if filters and not doc_ids:
|
||||||
doc_ids = None
|
doc_ids = ["-999"]
|
||||||
|
|
||||||
if self._param.cross_languages:
|
if self._param.cross_languages:
|
||||||
query = cross_languages(kbs[0].tenant_id, None, query, self._param.cross_languages)
|
query = cross_languages(kbs[0].tenant_id, None, query, self._param.cross_languages)
|
||||||
|
|||||||
@ -311,8 +311,8 @@ async def retrieval_test():
|
|||||||
doc_ids = None
|
doc_ids = None
|
||||||
elif meta_data_filter.get("method") == "manual":
|
elif meta_data_filter.get("method") == "manual":
|
||||||
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
||||||
if not doc_ids:
|
if meta_data_filter["manual"] and not doc_ids:
|
||||||
doc_ids = None
|
doc_ids = ["-999"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tenants = UserTenantService.query(user_id=current_user.id)
|
tenants = UserTenantService.query(user_id=current_user.id)
|
||||||
|
|||||||
@ -1445,6 +1445,8 @@ async def retrieval_test(tenant_id):
|
|||||||
metadata_condition = req.get("metadata_condition", {}) or {}
|
metadata_condition = req.get("metadata_condition", {}) or {}
|
||||||
metas = DocumentService.get_meta_by_kbs(kb_ids)
|
metas = DocumentService.get_meta_by_kbs(kb_ids)
|
||||||
doc_ids = meta_filter(metas, convert_conditions(metadata_condition), metadata_condition.get("logic", "and"))
|
doc_ids = meta_filter(metas, convert_conditions(metadata_condition), metadata_condition.get("logic", "and"))
|
||||||
|
if metadata_condition and not doc_ids:
|
||||||
|
doc_ids = ["-999"]
|
||||||
similarity_threshold = float(req.get("similarity_threshold", 0.2))
|
similarity_threshold = float(req.get("similarity_threshold", 0.2))
|
||||||
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
|
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
|
||||||
top = int(req.get("top_k", 1024))
|
top = int(req.get("top_k", 1024))
|
||||||
|
|||||||
@ -446,8 +446,8 @@ async def agent_completions(tenant_id, agent_id):
|
|||||||
|
|
||||||
if req.get("stream", True):
|
if req.get("stream", True):
|
||||||
|
|
||||||
def generate():
|
async def generate():
|
||||||
for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req):
|
async for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req):
|
||||||
if isinstance(answer, str):
|
if isinstance(answer, str):
|
||||||
try:
|
try:
|
||||||
ans = json.loads(answer[5:]) # remove "data:"
|
ans = json.loads(answer[5:]) # remove "data:"
|
||||||
@ -471,7 +471,7 @@ async def agent_completions(tenant_id, agent_id):
|
|||||||
full_content = ""
|
full_content = ""
|
||||||
reference = {}
|
reference = {}
|
||||||
final_ans = ""
|
final_ans = ""
|
||||||
for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req):
|
async for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req):
|
||||||
try:
|
try:
|
||||||
ans = json.loads(answer[5:])
|
ans = json.loads(answer[5:])
|
||||||
|
|
||||||
@ -873,7 +873,7 @@ async def agent_bot_completions(agent_id):
|
|||||||
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
for answer in agent_completion(objs[0].tenant_id, agent_id, **req):
|
async for answer in agent_completion(objs[0].tenant_id, agent_id, **req):
|
||||||
return get_result(data=answer)
|
return get_result(data=answer)
|
||||||
|
|
||||||
|
|
||||||
@ -981,8 +981,8 @@ async def retrieval_test_embedded():
|
|||||||
doc_ids = None
|
doc_ids = None
|
||||||
elif meta_data_filter.get("method") == "manual":
|
elif meta_data_filter.get("method") == "manual":
|
||||||
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
||||||
if not doc_ids:
|
if meta_data_filter["manual"] and not doc_ids:
|
||||||
doc_ids = None
|
doc_ids = ["-999"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tenants = UserTenantService.query(user_id=tenant_id)
|
tenants = UserTenantService.query(user_id=tenant_id)
|
||||||
|
|||||||
@ -415,9 +415,10 @@ def chat(dialog, messages, stream=True, **kwargs):
|
|||||||
if not attachments:
|
if not attachments:
|
||||||
attachments = None
|
attachments = None
|
||||||
elif dialog.meta_data_filter.get("method") == "manual":
|
elif dialog.meta_data_filter.get("method") == "manual":
|
||||||
attachments.extend(meta_filter(metas, dialog.meta_data_filter["manual"], dialog.meta_data_filter.get("logic", "and")))
|
conds = dialog.meta_data_filter["manual"]
|
||||||
if not attachments:
|
attachments.extend(meta_filter(metas, conds, dialog.meta_data_filter.get("logic", "and")))
|
||||||
attachments = None
|
if conds and not attachments:
|
||||||
|
attachments = ["-999"]
|
||||||
|
|
||||||
if prompt_config.get("keyword", False):
|
if prompt_config.get("keyword", False):
|
||||||
questions[-1] += keyword_extraction(chat_mdl, questions[-1])
|
questions[-1] += keyword_extraction(chat_mdl, questions[-1])
|
||||||
@ -787,8 +788,8 @@ def ask(question, kb_ids, tenant_id, chat_llm_name=None, search_config={}):
|
|||||||
doc_ids = None
|
doc_ids = None
|
||||||
elif meta_data_filter.get("method") == "manual":
|
elif meta_data_filter.get("method") == "manual":
|
||||||
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
||||||
if not doc_ids:
|
if meta_data_filter["manual"] and not doc_ids:
|
||||||
doc_ids = None
|
doc_ids = ["-999"]
|
||||||
|
|
||||||
kbinfos = retriever.retrieval(
|
kbinfos = retriever.retrieval(
|
||||||
question=question,
|
question=question,
|
||||||
@ -862,8 +863,8 @@ def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
|
|||||||
doc_ids = None
|
doc_ids = None
|
||||||
elif meta_data_filter.get("method") == "manual":
|
elif meta_data_filter.get("method") == "manual":
|
||||||
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
doc_ids.extend(meta_filter(metas, meta_data_filter["manual"], meta_data_filter.get("logic", "and")))
|
||||||
if not doc_ids:
|
if meta_data_filter["manual"] and not doc_ids:
|
||||||
doc_ids = None
|
doc_ids = ["-999"]
|
||||||
|
|
||||||
ranks = settings.retriever.retrieval(
|
ranks = settings.retriever.retrieval(
|
||||||
question=question,
|
question=question,
|
||||||
|
|||||||
Reference in New Issue
Block a user