You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Neo4j GDS图目录投影中访问特定节点与关系数据?

在Neo4j GDS中访问图投影的节点与关系详细信息

在Neo4j Graph Data Science(GDS)中,每个图都对应一个投影。如何获取特定投影中存储的实际节点与关系的详细信息?是否有方法访问投影内的特定节点和关系数据?

使用CALL gds.graph.list('graph_0')可以获取投影的基本信息(如节点数、关系数),但无法查看节点与关系的详细内容。

1. 创建示例图

使用以下Cypher语句创建包含多重复关系的图:

CREATE
  (alice:Buyer {name: 'Alice'}),
  (instrumentSeller:Seller {name: 'Instrument Seller'}),
  (bob:Buyer {name: 'Bob'}),
  (carol:Buyer {name: 'Carol'}),
  (alice)-[:PAYS { amount: 1.0}]->(instrumentSeller),
  (alice)-[:PAYS { amount: 2.0}]->(instrumentSeller),
  (alice)-[:PAYS { amount: 3.0}]->(instrumentSeller),
  (alice)-[:PAYS { amount: 4.0}]->(instrumentSeller),
  (alice)-[:PAYS { amount: 5.0}]->(instrumentSeller),
  (alice)-[:PAYS { amount: 6.0}]->(instrumentSeller),

  (bob)-[:PAYS { amount: 3.0}]->(instrumentSeller),
  (bob)-[:PAYS { amount: 4.0}]->(instrumentSeller),
  (carol)-[:PAYS { amount: 5.0}]->(bob),
  (carol)-[:PAYS { amount: 6.0}]->(bob)

2. 执行图投影操作

将上述图投影为名为graph_0的GDS图:

MATCH (source)
OPTIONAL MATCH (source)-[r]->(target)
WITH gds.graph.project(
'graph_0',
source,
target,
{
sourceNodeLabels: labels(source),
targetNodeLabels: labels(target),
relationshipType: type(r)
}
) AS g
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

// 返回结果: 
//graph     nodes   rels
//"graph_0" 4       10

3. 运行随机游走采样算法

基于graph_0执行随机游走采样,生成名为mySample的子图:

MATCH (start:Buyer {name: 'Alice'})
CALL gds.graph.sample.rwr('mySample', 'graph_0', { samplingRatio: 0.66, startNodes: [id(start)] })
YIELD nodeCount, relationshipCount
RETURN nodeCount, relationshipCount
// 返回结果:
// nodeCount    relationshipCount
// 3            8

4. 需求痛点

本例中,两个节点间存在多个同类型关系(例如Alice与Instrument Seller之间的多条PAYS关系),需要了解采样过程中被选中的具体关系(通过关系ID标识),但现有方法仅能查看采样的关系类型,无法获取精确的关系ID。

内容的提问来源于stack exchange,提问作者Hao Chen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 01:20:29