Skip to content

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

Feat: add use KG to retrieval component. (#5988)

Kevin Hud660f6b9a5db
diff --git a/agent/component/retrieval.py b/agent/component/retrieval.py
index b96bc8bf53..c960725e66 100644
--- a/agent/component/retrieval.py
+++ b/agent/component/retrieval.py
@@ -42,6 +42,7 @@ class RetrievalParam(ComponentParamBase):
self.rerank_id = ""
self.empty_response = ""
self.tavily_api_key = ""
+ self.use_kg = False
def check(self):
self.check_decimal_float(self.similarity_threshold, "[Retrieval] Similarity threshold")
@@ -77,6 +78,15 @@ class Retrieval(ComponentBase, ABC):
self._param.similarity_threshold, 1 - self._param.keywords_similarity_weight,
aggs=False, rerank_mdl=rerank_mdl,
rank_feature=label_question(query, kbs))
+ if self._param.use_kg:
+ ck = settings.kg_retrievaler.retrieval(query,
+ [kbs[0].tenant_id],
+ self._param.kb_ids,
+ embd_mdl,
+ LLMBundle(kbs[0].tenant_id, LLMType.CHAT))
+ if ck["content_with_weight"]:
+ kbinfos["chunks"].insert(0, ck)
+
if self._param.tavily_api_key:
tav = Tavily(self._param.tavily_api_key)
tav_res = tav.retrieve_chunks(query)