Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Feat: let image citation being shown. (#7624)

Kevin Hu01330fa428b7
diff --git a/agent/component/retrieval.py b/agent/component/retrieval.py
index 0a34b5d665..859d65478b 100644
--- a/agent/component/retrieval.py
+++ b/agent/component/retrieval.py
@@ -15,6 +15,7 @@
#
import json
import logging
+import re
from abc import ABC
import pandas as pd
@@ -59,6 +60,7 @@ class Retrieval(ComponentBase, ABC):
def _run(self, history, **kwargs):
query = self.get_input()
query = str(query["content"][0]) if "content" in query else ""
+ query = re.split(r"(USER:|ASSISTANT:)", query)[-1]
kb_ids: list[str] = self._param.kb_ids or []
diff --git a/api/apps/conversation_app.py b/api/apps/conversation_app.py
index 5eaeb19259..c05710a4fd 100644
--- a/api/apps/conversation_app.py
+++ b/api/apps/conversation_app.py
@@ -210,6 +210,7 @@ def completion():
"dataset_id": get_value(ck, "kb_id", "dataset_id"),
"image_id": get_value(ck, "image_id", "img_id"),
"positions": get_value(ck, "positions", "position_int"),
+ "doc_type": get_value(ck, "doc_type_kwd", "doc_type_kwd"),
}
for ck in ref.get("chunks", [])
]
diff --git a/rag/prompts.py b/rag/prompts.py
index 7d061b810c..4a61de557d 100644
--- a/rag/prompts.py
+++ b/rag/prompts.py
@@ -117,7 +117,9 @@ def kb_prompt(kbinfos, max_tokens):
doc2chunks = defaultdict(lambda: {"chunks": [], "meta": []})
for i, ck in enumerate(kbinfos["chunks"][:chunks_num]):
- doc2chunks[ck["docnm_kwd"]]["chunks"].append((f"URL: {ck['url']}\n" if "url" in ck else "") + f"ID: {i}\n" + ck["content_with_weight"])
+ cnt = f"---\nID: {i}\n" + (f"URL: {ck['url']}\n" if "url" in ck else "")
+ cnt += ck["content_with_weight"]
+ doc2chunks[ck["docnm_kwd"]]["chunks"].append(cnt)
doc2chunks[ck["docnm_kwd"]]["meta"] = docs.get(ck["doc_id"], {})
knowledges = []