mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-01 22:10:40 +08:00
Feat: add use KG to retrieval component. (#5988)
### What problem does this PR solve? #5973 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
80389ae61e
commit
d660f6b9a5
@ -42,6 +42,7 @@ class RetrievalParam(ComponentParamBase):
|
|||||||
self.rerank_id = ""
|
self.rerank_id = ""
|
||||||
self.empty_response = ""
|
self.empty_response = ""
|
||||||
self.tavily_api_key = ""
|
self.tavily_api_key = ""
|
||||||
|
self.use_kg = False
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
self.check_decimal_float(self.similarity_threshold, "[Retrieval] Similarity threshold")
|
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,
|
self._param.similarity_threshold, 1 - self._param.keywords_similarity_weight,
|
||||||
aggs=False, rerank_mdl=rerank_mdl,
|
aggs=False, rerank_mdl=rerank_mdl,
|
||||||
rank_feature=label_question(query, kbs))
|
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:
|
if self._param.tavily_api_key:
|
||||||
tav = Tavily(self._param.tavily_api_key)
|
tav = Tavily(self._param.tavily_api_key)
|
||||||
tav_res = tav.retrieve_chunks(query)
|
tav_res = tav.retrieve_chunks(query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user