change apply_meta_data_filter to async
This commit is contained in:
parent
974ca4150a
commit
c54531a6ea
5 changed files with 9 additions and 9 deletions
|
|
@ -165,7 +165,7 @@ class Retrieval(ToolBase, ABC):
|
|||
if self._param.meta_data_filter.get("method") in ["auto", "semi_auto"]:
|
||||
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT)
|
||||
|
||||
doc_ids = apply_meta_data_filter(
|
||||
doc_ids = await apply_meta_data_filter(
|
||||
self._param.meta_data_filter,
|
||||
metas,
|
||||
query,
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ async def retrieval_test():
|
|||
|
||||
if meta_data_filter:
|
||||
metas = DocumentService.get_meta_by_kbs(kb_ids)
|
||||
local_doc_ids = apply_meta_data_filter(meta_data_filter, metas, question, chat_mdl, local_doc_ids)
|
||||
local_doc_ids = await apply_meta_data_filter(meta_data_filter, metas, question, chat_mdl, local_doc_ids)
|
||||
|
||||
tenants = UserTenantService.query(user_id=user_id)
|
||||
for kb_id in kb_ids:
|
||||
|
|
|
|||
|
|
@ -989,7 +989,7 @@ async def retrieval_test_embedded():
|
|||
|
||||
if meta_data_filter:
|
||||
metas = DocumentService.get_meta_by_kbs(kb_ids)
|
||||
local_doc_ids = apply_meta_data_filter(meta_data_filter, metas, _question, chat_mdl, local_doc_ids)
|
||||
local_doc_ids = await apply_meta_data_filter(meta_data_filter, metas, _question, chat_mdl, local_doc_ids)
|
||||
|
||||
tenants = UserTenantService.query(user_id=tenant_id)
|
||||
for kb_id in kb_ids:
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ async def async_chat(dialog, messages, stream=True, **kwargs):
|
|||
|
||||
if dialog.meta_data_filter:
|
||||
metas = DocumentService.get_meta_by_kbs(dialog.kb_ids)
|
||||
attachments = apply_meta_data_filter(
|
||||
attachments = await apply_meta_data_filter(
|
||||
dialog.meta_data_filter,
|
||||
metas,
|
||||
questions[-1],
|
||||
|
|
@ -756,7 +756,7 @@ async def async_ask(question, kb_ids, tenant_id, chat_llm_name=None, search_conf
|
|||
|
||||
if meta_data_filter:
|
||||
metas = DocumentService.get_meta_by_kbs(kb_ids)
|
||||
doc_ids = apply_meta_data_filter(meta_data_filter, metas, question, chat_mdl, doc_ids)
|
||||
doc_ids = await apply_meta_data_filter(meta_data_filter, metas, question, chat_mdl, doc_ids)
|
||||
|
||||
kbinfos = retriever.retrieval(
|
||||
question=question,
|
||||
|
|
@ -823,7 +823,7 @@ async def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
|
|||
|
||||
if meta_data_filter:
|
||||
metas = DocumentService.get_meta_by_kbs(kb_ids)
|
||||
doc_ids = apply_meta_data_filter(meta_data_filter, metas, question, chat_mdl, doc_ids)
|
||||
doc_ids = await apply_meta_data_filter(meta_data_filter, metas, question, chat_mdl, doc_ids)
|
||||
|
||||
ranks = settings.retriever.retrieval(
|
||||
question=question,
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
|
|||
return list(doc_ids)
|
||||
|
||||
|
||||
def apply_meta_data_filter(
|
||||
async def apply_meta_data_filter(
|
||||
meta_data_filter: dict | None,
|
||||
metas: dict,
|
||||
question: str,
|
||||
|
|
@ -118,7 +118,7 @@ def apply_meta_data_filter(
|
|||
method = meta_data_filter.get("method")
|
||||
|
||||
if method == "auto":
|
||||
filters: dict = gen_meta_filter(chat_mdl, metas, question)
|
||||
filters: dict = await gen_meta_filter(chat_mdl, metas, question)
|
||||
doc_ids.extend(meta_filter(metas, filters["conditions"], filters.get("logic", "and")))
|
||||
if not doc_ids:
|
||||
return None
|
||||
|
|
@ -127,7 +127,7 @@ def apply_meta_data_filter(
|
|||
if selected_keys:
|
||||
filtered_metas = {key: metas[key] for key in selected_keys if key in metas}
|
||||
if filtered_metas:
|
||||
filters: dict = gen_meta_filter(chat_mdl, filtered_metas, question)
|
||||
filters: dict = await gen_meta_filter(chat_mdl, filtered_metas, question)
|
||||
doc_ids.extend(meta_filter(metas, filters["conditions"], filters.get("logic", "and")))
|
||||
if not doc_ids:
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue