Parcourir la source

Fix: no doc hits after meta data filter. (#9435)

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.20.2
Kevin Hu il y a 2 mois
Parent
révision
4b1b68c5fc
Aucun compte lié à l'adresse e-mail de l'auteur
3 fichiers modifiés avec 9 ajouts et 6 suppressions
  1. 7
    4
      api/db/services/dialog_service.py
  2. 2
    1
      rag/prompts/citation_prompt.md
  3. 0
    1
      rag/utils/s3_conn.py

+ 7
- 4
api/db/services/dialog_service.py Voir le fichier

@@ -365,8 +365,12 @@ def chat(dialog, messages, stream=True, **kwargs):
if dialog.meta_data_filter.get("method") == "auto":
filters = gen_meta_filter(chat_mdl, metas, questions[-1])
attachments.extend(meta_filter(metas, filters))
if not attachments:
attachments = None
elif dialog.meta_data_filter.get("method") == "manual":
attachments.extend(meta_filter(metas, dialog.meta_data_filter["manual"]))
if not attachments:
attachments = None

if prompt_config.get("keyword", False):
questions[-1] += keyword_extraction(chat_mdl, questions[-1])
@@ -375,17 +379,16 @@ def chat(dialog, messages, stream=True, **kwargs):

thought = ""
kbinfos = {"total": 0, "chunks": [], "doc_aggs": []}
knowledges = []

if "knowledge" not in [p["key"] for p in prompt_config["parameters"]]:
knowledges = []
else:
if attachments is not None and "knowledge" in [p["key"] for p in prompt_config["parameters"]]:
tenant_ids = list(set([kb.tenant_id for kb in kbs]))
knowledges = []
if prompt_config.get("reasoning", False):
reasoner = DeepResearcher(
chat_mdl,
prompt_config,
partial(retriever.retrieval, embd_mdl=embd_mdl, tenant_ids=tenant_ids, kb_ids=dialog.kb_ids, page=1, page_size=dialog.top_n, similarity_threshold=0.2, vector_similarity_weight=0.3),
partial(retriever.retrieval, embd_mdl=embd_mdl, tenant_ids=tenant_ids, kb_ids=dialog.kb_ids, page=1, page_size=dialog.top_n, similarity_threshold=0.2, vector_similarity_weight=0.3, doc_ids=attachments),
)

for think in reasoner.thinking(kbinfos, " ".join(questions)):

+ 2
- 1
rag/prompts/citation_prompt.md Voir le fichier

@@ -105,4 +105,5 @@ REMEMBER:
- Cite FACTS, not opinions or transitions
- Each citation supports the ENTIRE sentence
- When in doubt, ask: "Would a fact-checker need to verify this?"
- Place citations at sentence end, before punctuation
- Place citations at sentence end, before punctuation
- Format likes this is FORBIDDEN: [ID:0, ID:5, ID:...]. It MUST be seperated like, [ID:0][ID:5]...

+ 0
- 1
rag/utils/s3_conn.py Voir le fichier

@@ -191,7 +191,6 @@ class RAGFlowS3:
time.sleep(1)
return

@use_prefix_path
@use_default_bucket
def rm_bucket(self, bucket, *args, **kwargs):
for conn in self.conn:

Chargement…
Annuler
Enregistrer