SuperAPI AI 工具集

neo4j-gds-skill

数据与分析

查看项目

更新于 11-27 17:04

技能介绍

用途

本技能用于在已安装 GDS 插件的 Neo4j 数据库上运行图数据科学算法,支持两种方式:Python 客户端 graphdatascience 2.x,或 Cypher 的 CALL gds.* 过程。适用环境包括 Aura Pro、自管理 Neo4j、本地 Neo4j 或离线 DBMS(需安装 GDS 插件)。

不适用场景:Aura Graph Analytics Sessions / AGA / GdsSessions / AuraGraphDataScience 应使用 neo4j-aura-graph-analytics-skill;Cypher 查询编写使用 neo4j-cypher-skill;驱动/连接设置使用 neo4j-driver-python-skill;GraphRAG 检索使用 neo4j-graphrag-skill;创建/查询向量索引使用 neo4j-vector-index-skill。

主要能力

  • 图目录操作:原生投影(gds.graph.project.native / CALL gds.graph.project)、Cypher 投影(gds.graph.project.cypher)、无向投影设置、查看与删除图(node_count、relationship_count、node_properties、relationship_properties、size_in_bytes、gds.graph.drop、gds.graph.get、gds.graph.list)。
  • 内存估算:gds.graph.project.estimate 与算法 estimate,用于大型投影和算法前预估。
  • 执行模式:stream(返回每节点/对行)、stats(单聚合行)、mutate(仅修改内存图)、write(持久化到数据库)。推荐模式:stream 验证 → mutate 链式 → write 持久化。
  • 核心算法:PageRank、Louvain、Leiden、WCC、Betweenness Centrality、Node Similarity、FastRP、KNN,以及 FastRP → KNN 推荐管道。
  • 结果增强:stream 模式使用 gds.util.asNode(nodeId) 将内部 nodeId 转回数据库节点以访问属性。
  • 算法选择参考:影响力用 PageRank/ArticleRank;瓶颈节点用 Betweenness;直接连接用 Degree;社区用 Louvain/Leiden;连通性用 WCC;嵌入相似度用 KNN;邻居相似度用 Node Similarity;最短路径用 Dijkstra/A*;k 替代路径用 Yen's;快速嵌入用 FastRP;特征丰富节点用 GraphSAGE。

使用方式

安装:pip install "graphdatascience>=2.3"(GDS 2026.10 需要 2.3;2026.09 需要 2.1);可选 pip install "graphdatascience[rust-ext]" 加速序列化。

客户端初始化示例: from graphdatascience import GraphDataScience gds = GraphDataScience("neo4j+s://xxx.databases.neo4j.io", auth=("neo4j", "pw")) # AuraDS gds = GraphDataScience("bolt://localhost:7687", auth=("neo4j", "password")) print(gds.server_version())

Cypher 版本检查:RETURN gds.version() AS gds_version。

兼容性:客户端 2.3 对应 GDS >= 2.13, < 2.28, < 2026.11,Python >= 3.11, < 3.16,pyarrow >= 22, < 27;2.1/2.2 对应 GDS >= 2.13, < 2.28, < 2026.10,Python >= 3.10, < 3.15,pyarrow 21–25;2.0 对应 GDS >= 2.13, < 2.28, < 2026.9,Python >= 3.10, < 3.15,pyarrow 21–25。所有 2.x 需要 Neo4j Python driver >= 5.26 且 < 7.0,pandas 2–3。Python 3.10 + GDS 2026.10 无受支持客户端;GDS 服务器 < 2.13 会触发 DeprecationWarning,应固定 graphdatascience<2(客户端 1.22)。

2.0 客户端规则:端点无 v2 前缀;参数使用 snake_case(page_rank、fast_rp、mutate_property、write_property);结果属性为类型化(result.write_millis);服务器版本用 gds.server_version();过程别名如 gds.betweenness ≡ gds.betweenness_centrality;管道 API 为 gds.pipeline.node_classification / link_prediction / node_regression,train(G, model_name=..., ...) 中 model_name 必填;gds.run_cypher(query, auto_commit=True) [2.1] 用于 CALL { … } IN TRANSACTIONS;gds.db_driver() [2.1] 获取底层 neo4j.Driver;mode="READ"/"WRITE" 字符串 [2.1];插件接口无异步/作业句柄 API。

1.x 回退映射:2.0 的 gds.page_rank 对应 1.x 的 gds.v2.page_rank;gds.graph.project.native 对应 gds.v2.graph.project;gds.graph.project.cypher 对应 gds.graph.cypher.project(query, database=...);Graph/Model 对应 GraphV2/ModelV2;gds.graph.drop 返回 list[GraphInfo] 对应单个 GraphInfo;Graph.drop(fail_if_missing=) 对应 failIfMissing=;run_cypher 总是重试对应 retryable=...。

适用场景

  • 在 Aura Pro 或自管理/本地/离线 Neo4j(已装 GDS 插件)上做图分析。
  • 投影命名内存图并运行中心性、社区、相似度、路径、嵌入算法。
  • 通过 mutate 模式链式调用算法,构建 FastRP → KNN 管道。
  • 将节点嵌入写入 Neo4j 向量索引以支持结构相似性搜索(写入后需用 neo4j-vector-index-skill 创建索引)。
  • 大型图操作前进行内存估算。

限制

  • 仅适用于嵌入式 GDS 插件;AuraDB serverless 分析会话、AGA 会话、非 Neo4j 数据源应使用 neo4j-aura-graph-analytics-skill。
  • GDS 插件不可用时,客户端构造抛出 GdsNotFound,Cypher 报 Unknown function 'gds.version'。
  • GDS 插件版本跟随服务器:2026.09.0 需要 Neo4j 2026.09,升级前需查兼容表。
  • GDS 插件 2026.07.0 移除了 CALL gds.userLog(),提示和警告从驱动结果摘要通知或 Neo4j 调试日志读取;任务进度用 CALL gds.listProgress()。
  • Leiden、Triangle Count、Local Clustering Coefficient、K-Core 需要 UNDIRECTED 投影,在 NATURAL 上会失败;HITS 需要 directed(NATURAL/REVERSE)。
  • mutate_property 不能已存在于内存图;KNN 等关系算法还需 mutate_relationship_type。write 后需重新投影才能在后续 GDS 调用中使用写入属性。
  • Cypher 投影中 sourceNodeProperties 与 targetNodeProperties 需同时设置,否则报配置键缺失;图名通过 graph_name="..." 关键字传入;查询必须以恰好一个 RETURN gds.graph.project(...) 结尾。
  • gds.graph.project.cypher(query) 不接受 database=,需在构造 GraphDataScience 时设置 database= 或先调用 gds.set_database(...)。
  • 常见错误包括堆内存不足(需估算并调整 server.memory.heap.max_size)、图已存在(overwrite=True 或先删除)、mutate_property 已存在、节点不在投影中、gds.graph.drop 返回 list 需索引等。

暂未提供

本资料未提供具体收费、价格、平台支持范围、效果指标或完整使用步骤,相关内容暂未提供。