OpenSPG / KAG

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.
https://spg.openkg.cn/en-US
Apache License 2.0
732 stars 54 forks source link

csv数据加载,仿照示例riskmining读取关系自定义chain报错 #61

Open Wangzhongxi opened 1 week ago

Wangzhongxi commented 1 week ago

class Control_Action_Chain(BuilderChainABC): def init(self, spg_type_name: str): super().init() self.spg_type_name = spg_type_name

def build(self, **kwargs):
    source = CSVReader(output_type="Dict")
    subject_name, relation, object_name = self.spg_type_name.split("_")
    mapping = (
        RelationMapping(subject_name, relation, object_name)
        .add_src_id_mapping("condition")
        .add_dst_id_mapping("effect")
    )
    sink = KGWriter()
    return source >> mapping >> sink

csv数据如下: condition,effect 高于xx水位线,关闭xx设备。

报错信息: INFO:numexpr.utils:Note: NumExpr detected 24 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 16. INFO:numexpr.utils:NumExpr defaulting to 16 threads. Traceback (most recent call last): File "E:\LLM\code\KAG2\KAG\kag\examples\Logictugraph\builder\indexer.py", line 142, in ControlLogicChain(spg_type_name="control_actions").invoke(file_path=os.path.join(file_path, "data/output_control_actions.csv")) File "C:\ProgramData\Anaconda3\envs\wllm\lib\site-packages\knext\builder\builder_chain_abc.py", line 25, in invoke chain = self.build(file_path=file_path, max_workers=max_workers, **kwargs) File "E:\LLM\code\KAG2\KAG\kag\examples\Logictugraph\builder\indexer.py", line 109, in build raise ValueError(f"Invalid spg_type_name format: {self.spg_type_name}. Expected format: 'subject_relation_object'") ValueError: Invalid spg_type_name format: control_actions. Expected format: 'subject_relation_object' 但是我看示例riskmining示例中的RiskMiningRelationChain加载的数据也只包含src和dst两列数据,那为什么这里可以加载,我自定义的数据无法加载 并且怎么才算是合理的SPG type name呢,是需要在哪里重新定义还是? image