KAG is a logical form-guided reasoning and retrieval framework based on OpenSPG engine and LLMs. It is used to build logical reasoning and factual Q&A solutions for professional domain knowledge bases. It can effectively overcome the shortcomings of the traditional RAG vector similarity calculation model.
def _can_answer(self, memory: KagMemoryABC, instruction: str):
"""
Determines whether the query can be answered.
:param memory (KagMemory): The context or memory information to use for rewriting.
:param instruction (str): The original instruction to be rewritten.
:return: Whether the query can be answered (boolean)
"""
serialize_memory = self._get_serialize_memory(memory)
if serialize_memory == "":
return False
if memory.get_solved_answer() != "":
return True
return self.llm_module.invoke({'memory': serialize_memory, 'instruction': instruction}, self.judge_prompt,
with_json_parse=False)
直接用hotpotqa數據集測試。
測例:Are Christopher Nolan and Sathish Kalathil both film directors?