Stay Hungry,Stay Foolish!

Ontology Reasoning System

Ontology Reasoning System

https://github.com/fanqingsong/Sapiens_Ontology

Overview

Ontology Reasoning System is a next-generation knowledge graph reasoning engine that goes far beyond traditional RAG (Retrieval-Augmented Generation). It implements Think-on-Graph (ToG) 3.0 with the MACER framework — a meta-cognitive reasoning pipeline that adaptively explores, validates, and synthesizes evidence from structured knowledge graphs.

Why Not Just RAG?

AspectTraditional RAGOntology Reasoning
Reasoning Vector similarity + LLM Meta-cognitive 4-stage pipeline
Query Handling Static, single-pass Adaptive refinement & decomposition
Evidence Validation Basic relevance 5-component scoring + contradiction detection
Multi-hop Questions LLM-dependent hallucination Explicit path tracking & bridge entity detection
Temporal Reasoning Ignored Native temporal alignment & event sequencing
Failure Transparency "I don't know" Detailed confidence classification & gap analysis


✨ Key Features

🔄 MACER Reasoning Pipeline

┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│ Constructor │ -> │  Retriever  │ -> │  Reflector  │ -> │  Responser  │
│             │    │             │    │   (loop)    │    │             │
│ Entity      │    │ 5 Evidence  │    │ Sufficiency │    │ Synthesis   │
│ Extraction  │    │ Strategies  │    │ Assessment  │    │ & Answer    │
└─────────────┘    └─────────────┘    └──────┬──────┘    └─────────────┘
                                             │
                                    EXPLORE / FOCUS / REFINE / BACKTRACK
 

📊 5 Evidence Collection Strategies

  • Vector Search: Semantic similarity on entity/chunk embeddings (what that means)
  • Graph Traversal: Multi-hop structural exploration (how it works)
  • Community Summaries: High-level contextual retrieval (how it works)
  • Text2Cypher: Natural language to Cypher with self-healing
  • Hybrid Mode: Intelligent combination of all strategies

🎯 Advanced Evidence Scoring

  • Entity Overlap (35%): Jaccard similarity matching
  • Relationship Match (25%): Graph structure alignment
  • Temporal Alignment (20%): Date/time context validation
  • Answer Presence (10%): Direct answer detection
  • Negative Evidence (10%): Contradiction & negation detection

🌐 Additional Capabilities

  • Multilingual: Full Chinese/English support with optimized fuzzy matching
  • LLM Failover: Automatic cascade (OpenAI → Anthropic → Azure → Ollama)
  • Incremental Updates: Delta-based graph modifications with change tracking
  • Ontology Schema: Entity type inheritance, predicate cardinality, domain profiles
  • SSE Streaming: Real-time progress for long-running operations

 

https://neo4j.com/docs/graph-data-science/current/algorithms/louvain/

Louvain 算法本身不是一次性的,并且支持增量检测。

🔄 算法的非一次性特点

Louvain 算法是一个层次化的聚类算法。它并非一次性完成,而是通过递归地合并社区来执行的。在每一轮迭代中,它会将属于同一个社区的节点合并成一个“超级节点”,然后在这个被压缩的、更小的图上再次执行社区发现。这个过程会持续进行,直到社区结构不再发生显著变化,达到稳定状态。

➕ 支持增量检测

对于有新节点或关系加入的场景,Louvain 算法支持增量式的社区检测。

这主要通过 seedProperty 配置参数来实现。

  • 工作原理:你可以为图中的一部分节点预先设置一个初始的社区 ID,并将这个 ID 存储在节点的某个属性中(例如 seed)。
  • 执行过程:在运行算法时,通过配置 seedProperty: 'seed',算法会读取这些预设的社区 ID,并尝试在后续的计算中保持这些节点的社区归属不变。
  • 结果:对于新加入的、没有预设 seed 值的节点,算法会为它们计算并分配新的社区 ID。

这种方式使得你可以在已有的社区划分基础上,高效地处理新增的数据,而无需对整个图重新进行计算。

 

https://neo4j.com/docs/graph-data-science-client/current/tutorials/community-detection/

这篇网页是 Neo4j 图数据科学(GDS)客户端的官方教程,主题为“社区发现”。它通过一个 Jupyter Notebook 示例,详细演示了如何使用 Python 的 graphdatascience 库对 Reddit 超链接网络数据集进行社区发现分析。

以下是该教程的核心内容总结:

🎯 教程目标

本教程旨在指导用户完成一个完整的图分析流程,从数据导入、预处理到应用社区发现算法,具体任务包括:

  • 使用 弱连通分量 (Weakly Connected Components, WCC) 算法进行图预处理。
  • 在最大的连通子图上,使用 Louvain 算法进行社区发现。

🛠️ 操作流程详解

  1. 环境设置与数据导入

    • 依赖安装:安装 graphdatasciencepandas 库。
    • 连接数据库:初始化 GDS 客户端并连接到 Neo4j 数据库。
    • 数据加载:从 Stanford SNAP 平台下载 soc-redditHyperlinks-body.tsv 数据集,并使用 Pandas 加载。
    • 数据预处理
      • 筛选出 2014 年 3 月 1 日之前的数据。
      • 仅保留 LINK_SENTIMENT 为 +1(正面关系)的超链接。
      • 去除重复的关系。
      • 从源和目标子版块(Subreddit)中提取所有唯一节点。
    • 数据载入图数据库:将处理好的节点和关系数据通过 Cypher 语句写入 Neo4j,并投影(project)成一个名为 reddit 的 GDS 内存图。
  2. 弱连通分量 (WCC) 分析

    • 目的:识别图中所有相互连接的节点集合(即连通分量),以找出最大的子图进行后续分析。孤立的节点或过小的子图对社区发现意义不大。
    • 执行:运行 gds.wcc.mutate 算法,为每个节点计算并写入 componentId 属性。
    • 结果:通过 Cypher 查询统计每个连通分量的大小,并识别出包含节点最多的那个分量。
    • 子图筛选:使用 gds.graph.filter 方法,基于 componentId 筛选出最大的连通分量,创建一个新的子图 largest_connected_components 用于下一步分析。
  3. 使用 Louvain 算法进行社区发现

    • 目的:在筛选出的最大连通子图上发现内部联系紧密的社区结构。
    • 执行:在 largest_connected_components 子图上运行 gds.louvain.mutate 算法。
    • 结果:算法为每个节点分配一个 louvainCommunityId,并计算出模块度(Modularity)分数为 0.5898,该分数用于衡量社区划分的质量。
    • 结果写入与查看:将 louvainCommunityId 属性写回数据库,并通过 Cypher 查询展示部分节点的社区归属。最后,通过查询统计并列出每个社区的大小及其包含的子版块。

🧹 清理与后续步骤

  • 清理:教程最后提供了清理代码,用于从 GDS 内存和 Neo4j 数据库中删除示例数据和创建的图对象。
  • 后续建议
    • 使用 Neo4j Bloom 可视化工具,根据社区属性对生成的社区进行样式化展示和检查。
    • 尝试调整 Louvain 算法的参数,观察社区划分结果的变化。
    • 尝试使用 GDS 文档中列出的其他社区发现算法。

 

posted @ 2026-08-30 22:26  lightsong  阅读(7)  评论(0)    收藏  举报
千山鸟飞绝,万径人踪灭