Traverser API

3.1 Overview of Traverser API

HugeGraphServer provides a RESTful API interface for the HugeGraph graph database. In addition to the basic CRUD operations for vertices and edges, it also offers several traversal methods, which we refer to as the traverser API. These traversal methods implement various complex graph algorithms, making it convenient for users to analyze and explore the graph.

The Traverser API supported by HugeGraph includes:

  • K-out API: It finds neighbors that are exactly N steps away from a given starting vertex. There are two versions:
  • The basic version uses the GET method to find neighbors that are exactly N steps away from a given starting vertex.
  • The advanced version uses the POST method to find neighbors that are exactly N steps away from a given starting vertex. The advanced version differs from the basic version in the following ways:
    • Supports counting the number of neighbors only
    • Supports filtering by edge and vertex properties
    • Supports returning the shortest path to reach the neighbor
  • K-neighbor API: It finds all neighbors that are within N steps of a given starting vertex. There are two versions:
  • The basic version uses the GET method to find all neighbors that are within N steps of a given starting vertex.
  • The advanced version uses the POST method to find all neighbors that are within N steps of a given starting vertex. The advanced version differs from the basic version in the following ways:
    • Supports counting the number of neighbors only
    • Supports filtering by edge and vertex properties
    • Supports returning the shortest path to reach the neighbor
  • Same Neighbors: It queries the common neighbors of two vertices.
  • Jaccard Similarity API: It calculates the Jaccard similarity, which includes two types:
  • One type uses the GET method to calculate the similarity (intersection over union) of neighbors between two vertices.
  • The other type uses the POST method to find the top N vertices with the highest Jaccard similarity to a given starting vertex in the entire graph.
  • Shortest Path API: It finds the shortest path between two vertices.
  • All Shortest Paths: It finds all shortest paths between two vertices.
  • Weighted Shortest Path: It finds the shortest weighted path from a starting vertex to a target vertex.
  • Single Source Shortest Path: It finds the weighted shortest path from a single source vertex to all other vertices.
  • Multi Node Shortest Path: It finds the shortest path between every pair of specified vertices.
  • Paths API: It finds all paths between two vertices. There are two versions:
  • The basic version uses the GET method to find all paths between a given starting vertex and an ending vertex.
  • The advanced version uses the POST method to find all paths that meet certain conditions between a set of starting vertices and a set of ending vertices.

3.2 Detailed Explanation of Traverser API

In the following, we provide a detailed explanation of the Traverser API:

  • Customized Paths API: It traverses all paths that pass through a batch of vertices according to a specific pattern.
  • Template Path API: It specifies a starting point, an ending point, and the path information between them to find matching paths.
  • Crosspoints API: It finds the intersection (common ancestors or common descendants) between two vertices.
  • Customized Crosspoints API: It traverses multiple patterns starting from a batch of vertices and finds the intersections with the vertices reached in the final step.
  • Rings API: It finds the cyclic paths that can be reached from a starting vertex.
  • Rays API: It finds the paths from a starting vertex that reach the boundaries (i.e., paths without cycles).
  • Fusiform Similarity API: It finds the fusiform similar vertices to a given vertex.
  • Vertices API:
  • Batch querying vertices by ID.
  • Getting the partitions of vertices.
  • Querying vertices by partition.
  • Edges API:
  • Batch querying edges by ID.
  • Getting the partitions of edges.
  • Querying edges by partition.

3.2 Detailed Explanation of Traverser API

The usage examples provided in this section are based on the graph presented on the TinkerPop official website:

tinkerpop example graph

The data import program is as follows:

1. public class Loader {
2. public static void main(String[] args) {
3. HugeClient client = new HugeClient("http://127.0.0.1:8080", "hugegraph");
4. SchemaManager schema = client.schema();
5. schema.propertyKey("name").asText().ifNotExist().create();
6. schema.propertyKey("age").asInt().ifNotExist().create();
7. schema.propertyKey("city").asText().ifNotExist().create();
8. schema.propertyKey("weight").asDouble().ifNotExist().create();
9. schema.propertyKey("lang").asText().ifNotExist().create();
10. schema.propertyKey("date").asText().ifNotExist().create();
11. schema.propertyKey("price").asInt().ifNotExist().create();

13. schema.vertexLabel("person")
14. .properties("name", "age", "city")
15. .primaryKeys("name")
16. .nullableKeys("age")
17. .ifNotExist()
18. .create();

20. schema.vertexLabel("software")
21. .properties("name", "lang", "price")
22. .primaryKeys("name")
23. .nullableKeys("price")
24. .ifNotExist()
25. .create();

27. schema.indexLabel("personByCity")
28. .onV("person")
29. .by("city")
30. .secondary()
31. .ifNotExist()
32. .create();

34. schema.indexLabel("personByAgeAndCity")
35. .onV("person")
36. .by("age", "city")
37. .secondary()
38. .ifNotExist()
39. .create();

41. schema.indexLabel("softwareByPrice")
42. .onV("software")
43. .by("price")
44. .range()
45. .ifNotExist()
46. .create();

48. schema.edgeLabel("knows")
49. .multiTimes()
50. .sourceLabel("person")
51. .targetLabel("person")
52. .properties("date", "weight")
53. .sortKeys("date")
54. .nullableKeys("weight")
55. .ifNotExist()
56. .create();

58. schema.edgeLabel("created")
59. .sourceLabel("person").targetLabel("software")
60. .properties("date", "weight")
61. .nullableKeys("weight")
62. .ifNotExist()
63. .create();

65. schema.indexLabel("createdByDate")
66. .onE("created")
67. .by("date")
68. .secondary()
69. .ifNotExist()
70. .create();

72. schema.indexLabel("createdByWeight")
73. .onE("created")
74. .by("weight")
75. .range()
76. .ifNotExist()
77. .create();

79. schema.indexLabel("knowsByWeight")
80. .onE("knows")
81. .by("weight")
82. .range()
83. .ifNotExist()
84. .create();

86. GraphManager graph = client.graph();
87. Vertex marko = graph.addVertex(T.label, "person", "name", "marko",
88. "age", 29, "city", "Beijing");
89. Vertex vadas = graph.addVertex(T.label, "person", "name", "vadas",
90. "age", 27, "city", "Hongkong");
91. Vertex lop = graph.addVertex(T.label, "software", "name", "lop",
92. "lang", "java", "price", 328);
93. Vertex josh = graph.addVertex(T.label, "person", "name", "josh",
94. "age", 32, "city", "Beijing");
95. Vertex ripple = graph.addVertex(T.label, "software", "name", "ripple",
96. "lang", "java", "price", 199);
97. Vertex peter = graph.addVertex(T.label, "person", "name", "peter",
98. "age", 35, "city", "Shanghai");

100. marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5);
101. marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0);
102. marko.addEdge("created", lop, "date", "20171210", "weight", 0.4);
103. josh.addEdge("created", lop, "date", "20091111", "weight", 0.4);
104. josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0);
105. peter.addEdge("created", lop, "date", "20170324", "weight", 0.2);
106. }
107. }

The vertex IDs are:

1. "2:ripple",
2. "1:vadas",
3. "1:peter",
4. "1:josh",
5. "1:marko",
6. "2:lop"

The edge IDs are:

1. "S1:peter>2>>S2:lop",
2. "S1:josh>2>>S2:lop",
3. "S1:josh>2>>S2:ripple",
4. "S1:marko>1>20130220>S1:josh",
5. "S1:marko>1>20160110>S1:vadas",
6. "S1:marko>2>>S2:lop"

3.2.1 K-out API (GET, Basic Version)

3.2.1.1 Functionality Overview

The K-out API allows you to find vertices that are exactly “depth” steps away from a given starting vertex, considering the specified direction, edge type (optional), and depth.

Params
  • source: ID of the starting vertex (required)
  • direction: Direction of traversal from the starting vertex (OUT, IN, BOTH). Optional, default is BOTH.
  • max_depth: Number of steps (required)
  • label: Edge type (optional), represents all edge labels by default
  • nearest: When nearest is set to true, it means the shortest path length from the starting vertex to the result vertices is equal to the depth, and there is no shorter path. When nearest is set to false, it means there is at least one path of length depth from the starting vertex to the result vertices (not necessarily the shortest and may contain cycles). Optional, default is true.
  • max_degree: Maximum number of adjacent edges to traverse per vertex during the query. Optional, default is 10000.
  • capacity: Maximum number of vertices to be visited during the traversal. Optional, default is 10000000.
  • limit: Maximum number of vertices to be returned. Optional, default is 10000000.
3.2.1.2 Usage Example
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/kout?source="1:marko"&max_depth=2
Response Status
1. 200
Response Body
1. {
2. "vertices":[
3. "2:ripple",
4. "1:peter"
5. ]
6. }
3.2.1.3 Use Cases

Finding vertices that are exactly N steps away in a relationship. Two examples:

  • In a family relationship, finding all grandchildren of a person. The set of vertices that can be reached by person A through two consecutive “son” edges.
  • Discovering potential friends in a social network. For example, finding users who are two degrees of friendship away from the target user, reachable through two consecutive “friend” edges.

3.2.2 K-out API (POST, Advanced Version)

3.2.2.1 Functionality Overview

The K-out API allows you to find vertices that are exactly “depth” steps away from a given starting vertex, considering the specified steps (including direction, edge type, and attribute filtering).

The advanced version differs from the basic version of K-out API in the following aspects:

  • Supports counting the number of neighbors only
  • Supports edge attribute filtering
  • Supports returning the shortest path to the neighbor
Params
  • source: The ID of the starting vertex, required.
  • steps: Steps from the starting point, required, with the following structure:
  • direction: Represents the direction of the edges (OUT, IN, BOTH), default is BOTH.
  • edge_steps: The step set of edges, supporting label and properties filtering for the edge. If edge_steps is empty, the edge is not filtered.
    • label: Edge types.
    • properties: Filter edges based on property values.
  • vertex_steps: The step set of vertices, supporting label and properties filtering for the vertex. If vertex_steps is empty, the vertex is not filtered.
    • label: Vertex types.
    • properties: Filter vertices based on property values.
  • max_degree: Maximum number of adjacent edges to traverse for a single vertex, default is 10000 (Note: Prior to version 0.12, the parameter name was “degree” instead of “max_degree”. Starting from version 0.12, “max_degree” is used uniformly, while still supporting the “degree” syntax for backward compatibility).
  • skip_degree: Sets the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional. If enabled, it should satisfy the constraint skip_degree >= max_degree. Default is 0 (not enabled), indicating no skipping of any vertices (Note: Enabling this configuration means that during traversal, an attempt will be made to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it only after understanding the implications).
  • max_depth: Number of steps, required.
  • nearest: When nearest is true, it means the shortest path length from the starting vertex to the result vertex is equal to depth, and there is no shorter path. When nearest is false, it means there is a path of length depth from the starting vertex to the result vertex (not necessarily the shortest and can contain cycles). Optional, default is true.
  • count_only: Boolean value, true indicates only counting the number of results without returning specific results, false indicates returning specific results. Default is false.
  • with_path: When true, it returns the shortest path from the starting vertex to each neighbor. When false, it does not return the shortest path. Optional, default is false.
  • with_edge: Optional parameter, default is false:
  • When true, the result will include complete edge information (all edges in the path):
    • When with_path is true, it returns complete information of all edges in all paths.
    • When with_path is false, no information is returned.
  • When false, it only returns edge IDs.
  • with_vertex: Optional parameter, default is false:
  • When true, the result will include complete vertex information (all vertices in the path):
    • When with_path is true, it returns complete information of all vertices in all paths.
    • When with_path is false, it returns complete information of all neighbors.
  • When false, it only returns vertex IDs.
  • capacity: Maximum number of vertices to visit during traversal. Optional, default is 10000000.
  • limit: Maximum number of vertices to return. Optional, default is 10000000.
  • traverse_mode: Traversal mode. There are two options: “breadth_first_search” and “depth_first_search”, default is “breadth_first_search”.
3.2.2.2 Usage
Method & Url
1. POST http://localhost:8080/graphs/{graph}/traversers/kout
Request Body
1. {
2. "source": "1:marko",
3. "steps": {
4. "direction": "BOTH",
5. "edge_steps": [
6. {
7. "label": "knows",
8. "properties": {
9. "weight": "P.gt(0.1)"
10. }
11. },
12. {
13. "label": "created",
14. "properties": {
15. "weight": "P.gt(0.1)"
16. }
17. }
18. ],
19. "vertex_steps": [
20. {
21. "label": "person",
22. "properties": {
23. "age": "P.lt(32)"
24. }
25. },
26. {
27. "label": "software",
28. "properties": {}
29. }
30. ],
31. "max_degree": 10000,
32. "skip_degree": 100000
33. },
34. "max_depth": 1,
35. "nearest": true,
36. "limit": 10000,
37. "with_vertex": true,
38. "with_path": true,
39. "with_edge": true
40. }
Response Status
1. 200
Response Body
1. {
2. "size": 2,
3. "kout": [
4. "1:vadas",
5. "2:lop"
6. ],
7. "paths": [
8. {
9. "objects": [
10. "1:marko",
11. "2:lop"
12. ]
13. },
14. {
15. "objects": [
16. "1:marko",
17. "1:vadas"
18. ]
19. }
20. ],
21. "vertices": [
22. {
23. "id": "1:marko",
24. "label": "person",
25. "type": "vertex",
26. "properties": {
27. "name": "marko",
28. "age": 29,
29. "city": "Beijing"
30. }
31. },
32. {
33. "id": "1:vadas",
34. "label": "person",
35. "type": "vertex",
36. "properties": {
37. "name": "vadas",
38. "age": 27,
39. "city": "Hongkong"
40. }
41. },
42. {
43. "id": "2:lop",
44. "label": "software",
45. "type": "vertex",
46. "properties": {
47. "name": "lop",
48. "lang": "java",
49. "price": 328
50. }
51. }
52. ],
53. "edges": [
54. {
55. "id": "S1:marko>1>20160110>S1:vadas",
56. "label": "knows",
57. "type": "edge",
58. "outV": "1:marko",
59. "outVLabel": "person",
60. "inV": "1:vadas",
61. "inVLabel": "person",
62. "properties": {
63. "weight": 0.5,
64. "date": "20160110"
65. }
66. },
67. {
68. "id": "S1:marko>2>>S2:lop",
69. "label": "created",
70. "type": "edge",
71. "outV": "1:marko",
72. "outVLabel": "person",
73. "inV": "2:lop",
74. "inVLabel": "software",
75. "properties": {
76. "weight": 0.4,
77. "date": "20171210"
78. }
79. }
80. ]
81. }
3.2.2.3 Use Cases

Refer to 3.2.1.3.

3.2.3 K-neighbor (GET, Basic Version)

3.2.3.1 Function Introduction

Find all vertices that are reachable within depth steps, including the starting vertex, based on the starting vertex, direction, edge type (optional), and depth.

Equivalent to the union of: starting vertex, K-out(1), K-out(2), …, K-out(max_depth).

Params
  • source: ID of the starting vertex, required.
  • direction: Direction in which the starting vertex’s edges extend (OUT, IN, BOTH). Optional, default is BOTH.
  • max_depth: Number of steps, required.
  • label: Edge type, optional, default represents all edge labels.
  • max_degree: Maximum number of adjacent edges to traverse for a single vertex during the query process. Optional, default is 10000.
  • limit: Maximum number of vertices to return, also represents the maximum number of vertices to visit during traversal. Optional, default is 10000000.
3.2.3.2 Usage
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/kneighbor?source=“1:marko”&max_depth=2
Response Status
1. 200
Response Body
1. {
2. "vertices":[
3. "2:ripple",
4. "1:marko",
5. "1:josh",
6. "1:vadas",
7. "1:peter",
8. "2:lop"
9. ]
10. }
3.2.3.3 Use Cases

Find all vertices reachable within N steps, for example:

  • In a family relationship, find all descendants within five generations of a person. This can be achieved by traversing five consecutive “parent-child” edges from person A.
  • In a social network, discover friend circles. For example, users who can be reached by 1, 2, or 3 “friend” edges from the target user can form the target user’s friend circle.

3.2.4 K-neighbor API (POST, Advanced Version)

3.2.4.1 Function Introduction

Find all vertices that are reachable within depth steps from the starting vertex, based on the starting vertex, steps (including direction, edge type, and filter properties), and depth.

The difference from the Basic Version of K-neighbor API is that:

  • It supports counting the number of neighbors only.
  • It supports filtering edges based on their properties.
  • It supports returning the shortest path to reach the neighbors.
Params
  • source: Starting vertex ID, required.
  • steps: Steps from the starting point, required, with the following structure:
  • direction: Represents the direction of the edges (OUT, IN, BOTH), default is BOTH.
  • edge_steps: The step set of edges, supporting label and properties filtering for the edge. If edge_steps is empty, the edge is not filtered.
    • label: Edge types.
    • properties: Filter edges based on property values.
  • vertex_steps: The step set of vertices, supporting label and properties filtering for the vertex. If vertex_steps is empty, the vertex is not filtered.
    • label: Vertex types.
    • properties: Filter vertices based on property values.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Default is 10000. (Note: Before version 0.12, the parameter name within the step only supported “degree.” Starting from version 0.12, it is unified as “max_degree” and is backward compatible with the “degree” notation.)
  • skip_degree: Used to set the minimum number of edges to discard super vertices during the query process. When the number of adjacent edges for a vertex exceeds skip_degree, the vertex is completely discarded. This is an optional parameter. If enabled, it should satisfy the constraint skip_degree >= max_degree. Default is 0 (not enabled), which means no vertices are skipped. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges for each vertex, not just max_degree edges. This incurs additional traversal overhead and may significantly impact query performance. Please make sure to understand this before enabling.)
  • max_depth: Number of steps, required.
  • count_only: Boolean value. If true, only the count of results is returned without the actual results. If false, the specific results are returned. Default is false.
  • with_path: If true, the shortest path from the starting point to each neighbor is returned. If false, the shortest path from the starting point to each neighbor is not returned. This is an optional parameter. Default is false.
  • with_edge: Optional parameter, default is false:
  • When true, the result will include complete edge information (all edges in the path):
    • When with_path is true, it returns complete information of all edges in all paths.
    • When with_path is false, no information is returned.
  • When false, it only returns edge IDs.
  • with_vertex: Optional parameter, default is false:
  • When true, the result will include complete vertex information (all vertices in the path):
    • When with_path is true, it returns complete information of all vertices in all paths.
    • When with_path is false, it returns complete information of all neighbors.
  • When false, it only returns vertex IDs.
  • limit: Maximum number of vertices to be returned. Also, the maximum number of vertices visited during the traversal process. This is an optional parameter. Default is 10000000.
3.2.4.2 Usage Method
Method & Url
1. POST http://localhost:8080/graphs/{graph}/traversers/kneighbor
Request Body
1. {
2. "source": "1:marko",
3. "steps": {
4. "direction": "BOTH",
5. "edge_steps": [
6. {
7. "label": "knows",
8. "properties": {
9. "weight": "P.gt(0.1)"
10. }
11. },
12. {
13. "label": "created",
14. "properties": {
15. "weight": "P.gt(0.1)"
16. }
17. }
18. ],
19. "vertex_steps": [
20. {
21. "label": "person",
22. "properties": {
23. "age": "P.lt(32)"
24. }
25. },
26. {
27. "label": "software",
28. "properties": {}
29. }
30. ],
31. "max_degree": 10000,
32. "skip_degree": 100000
33. },
34. "max_depth": 1,
35. "nearest": true,
36. "limit": 10000,
37. "with_vertex": true,
38. "with_path": true,
39. "with_edge": true
40. }
Response Status
1. 200
Response Body
1. {
2. "size": 4,
3. "kneighbor": [
4. "1:josh",
5. "2:lop",
6. "1:peter",
7. "2:ripple"
8. ],
9. "paths": [
10. {
11. "objects": [
12. "1:marko",
13. "2:lop"
14. ]
15. },
16. {
17. "objects": [
18. "1:marko",
19. "2:lop",
20. "1:peter"
21. ]
22. },
23. {
24. "objects": [
25. "1:marko",
26. "1:josh"
27. ]
28. },
29. {
30. "objects": [
31. "1:marko",
32. "1:josh",
33. "2:ripple"
34. ]
35. }
36. ],
37. "vertices": [
38. {
39. "id": "2:ripple",
40. "label": "software",
41. "type": "vertex",
42. "properties": {
43. "name": "ripple",
44. "lang": "java",
45. "price": 199
46. }
47. },
48. {
49. "id": "1:marko",
50. "label": "person",
51. "type": "vertex",
52. "properties": {
53. "name": "marko",
54. "age": 29,
55. "city": "Beijing"
56. }
57. },
58. {
59. "id": "1:josh",
60. "label": "person",
61. "type": "vertex",
62. "properties": {
63. "name": "josh",
64. "age": 32,
65. "city": "Beijing"
66. }
67. },
68. {
69. "id": "1:peter",
70. "label": "person",
71. "type": "vertex",
72. "properties": {
73. "name": "peter",
74. "age": 35,
75. "city": "Shanghai"
76. }
77. },
78. {
79. "id": "2:lop",
80. "label": "software",
81. "type": "vertex",
82. "properties": {
83. "name": "lop",
84. "lang": "java",
85. "price": 328
86. }
87. }
88. ],
89. "edges": [
90. {
91. "id": "S1:josh>2>>S2:ripple",
92. "label": "created",
93. "type": "edge",
94. "outV": "1:josh",
95. "outVLabel": "person",
96. "inV": "2:ripple",
97. "inVLabel": "software",
98. "properties": {
99. "weight": 1.0,
100. "date": "20171210"
101. }
102. },
103. {
104. "id": "S1:marko>2>>S2:lop",
105. "label": "created",
106. "type": "edge",
107. "outV": "1:marko",
108. "outVLabel": "person",
109. "inV": "2:lop",
110. "inVLabel": "software",
111. "properties": {
112. "weight": 0.4,
113. "date": "20171210"
114. }
115. },
116. {
117. "id": "S1:marko>1>20130220>S1:josh",
118. "label": "knows",
119. "type": "edge",
120. "outV": "1:marko",
121. "outVLabel": "person",
122. "inV": "1:josh",
123. "inVLabel": "person",
124. "properties": {
125. "weight": 1.0,
126. "date": "20130220"
127. }
128. },
129. {
130. "id": "S1:peter>2>>S2:lop",
131. "label": "created",
132. "type": "edge",
133. "outV": "1:peter",
134. "outVLabel": "person",
135. "inV": "2:lop",
136. "inVLabel": "software",
137. "properties": {
138. "weight": 0.2,
139. "date": "20170324"
140. }
141. }
142. ]
143. }
3.2.4.3 Use Cases

See 3.2.3.3

3.2.5 Same Neighbors

3.2.5.1 Function Introduction

Retrieve the common neighbors of two vertices.

Params
  • vertex: ID of one vertex, required.
  • other: ID of another vertex, required.
  • direction: Direction in which the vertex expands outward (OUT, IN, BOTH). Optional, default is BOTH.
  • label: Edge type. Optional, default represents all edge labels.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Optional, default is 10000.
  • limit: Maximum number of common neighbors to be returned. Optional, default is 10000000.
3.2.5.2 Usage Method
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/sameneighbors?vertex=“1:marko”&other="1:josh"
Response Status
1. 200
Response Body
1. {
2. "same_neighbors":[
3. "2:lop"
4. ]
5. }
3.2.5.3 Use Cases

Find the common neighbors of two vertices:

  • In a social network, find the common followers or users both users are following.

3.2.6 Jaccard Similarity (GET)

3.2.6.1 Function Introduction

Compute the Jaccard similarity between two vertices (the intersection of the neighbors of the two vertices divided by the union of the neighbors of the two vertices).

Params
  • vertex: ID of one vertex, required.
  • other: ID of another vertex, required.
  • direction: Direction in which the vertex expands outward (OUT, IN, BOTH). Optional, default is BOTH.
  • label: Edge type. Optional, default represents all edge labels.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Optional, default is 10000.
3.2.6.2 Usage Method
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/jaccardsimilarity?vertex="1:marko"&other="1:josh"
Response Status
1. 200
Response Body
1. {
2. "jaccard_similarity": 0.2
3. }
3.2.6.3 Use Cases

Used to evaluate the similarity or closeness between two vertices.

3.2.7 Jaccard Similarity (POST)

3.2.7.1 Function Introduction

Compute the N vertices with the highest Jaccard similarity to a specified vertex.

The Jaccard similarity is calculated as the intersection of the neighbors of the two vertices divided by the union of the neighbors of the two vertices.

Params
  • vertex: ID of a vertex, required.
  • Steps from the starting point, required. The structure is as follows:
  • direction: Direction of the edges (OUT, IN, BOTH). Optional, default is BOTH.
  • labels: List of edge types.
  • properties: Filter edges based on property values.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Default is 10000. (Note: Prior to version 0.12, the parameter name inside “step” was “degree”. Starting from version 0.12, it is unified as “max_degree” and still compatible with “degree” notation.)
  • skip_degree: Used to set the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional, default is 0 (not enabled), which means no skipping. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it after understanding and confirming.)
  • top: Return the top N vertices with the highest Jaccard similarity for a starting vertex. Optional, default is 100.
  • capacity: Maximum number of vertices to be visited during the traversal process. Optional, default is 10000000.
3.2.7.2 Usage Method
Method & Url
1. POST http://localhost:8080/graphs/{graph}/traversers/jaccardsimilarity
Request Body
1. {
2. "vertex": "1:marko",
3. "step": {
4. "direction": "BOTH",
5. "labels": [],
6. "max_degree": 10000,
7. "skip_degree": 100000
8. },
9. "top": 3
10. }
Response Status
1. 200
Response Body
1. {
2. "2:ripple": 0.3333333333333333,
3. "1:peter": 0.3333333333333333,
4. "1:josh": 0.2
5. }
3.2.7.3 Use Cases

Used to find the vertices in the graph that have the highest similarity to a specified vertex.

3.2.8 Shortest Path

3.2.8.1 Function Introduction

Find the shortest path between a starting vertex and a target vertex based on the direction, edge type (optional), and maximum depth.

Params
  • source: ID of the starting vertex, required.
  • target: ID of the target vertex, required.
  • direction: Direction in which the starting vertex expands (OUT, IN, BOTH). Optional, default is BOTH.
  • max_depth: Maximum number of steps, required.
  • label: Edge type, optional. Default represents all edge labels.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Optional, default is 10000.
  • skip_degree: Used to set the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional, default is 0 (not enabled), which means no skipping. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it after understanding and confirming.)
  • capacity: Maximum number of vertices to be visited during the traversal process. Optional, default is 10000000.
3.2.8.2 Usage Method
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/shortestpath?source="1:marko"&target="2:ripple"&max_depth=3
Response Status
1. 200
Response Body
1. {
2. "path":[
3. "1:marko",
4. "1:josh",
5. "2:ripple"
6. ]
7. }
3.2.8.3 Use Cases

Used to find the shortest path between two vertices, for example:

  • In a social network, finding the shortest path between two users, representing the closest friend relationship chain.
  • In a device association network, finding the shortest association relationship between two devices.

3.2.9 All Shortest Paths

3.2.9.1 Function Introduction

Find all shortest paths between a starting vertex and a target vertex based on the direction, edge type (optional), and maximum depth.

Params
  • source: ID of the starting vertex, required.
  • target: ID of the target vertex, required.
  • direction: Direction in which the starting vertex expands (OUT, IN, BOTH). Optional, default is BOTH.
  • max_depth: Maximum number of steps, required.
  • label: Edge type, optional. Default represents all edge labels.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Optional, default is 10000.
  • skip_degree: Used to set the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional, default is 0 (not enabled), which means no skipping. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it after understanding and confirming.)
  • capacity: Maximum number of vertices to be visited during the traversal process. Optional, default is 10000000.
3.2.9.2 Usage Method
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/allshortestpaths?source="A"&target="Z"&max_depth=10
Response Status
1. 200
Response Body
1. {
2. "paths":[
3. {
4. "objects": [
5. "A",
6. "B",
7. "C",
8. "Z"
9. ]
10. },
11. {
12. "objects": [
13. "A",
14. "M",
15. "N",
16. "Z"
17. ]
18. }
19. ]
20. }
3.2.9.3 Use Cases

Used to find all shortest paths between two vertices, for example:

  • In a social network, finding all shortest paths between two users, representing all the closest friend relationship chains.
  • In a device association network, finding all shortest association relationships between two devices.

3.2.10 Weighted Shortest Path

3.2.10.1 Function Introduction

Find a weighted shortest path between a starting vertex and a target vertex based on the direction, edge type (optional), maximum depth, and edge weight property.

Params
  • source: ID of the starting vertex, required.
  • target: ID of the target vertex, required.
  • direction: Direction in which the starting vertex expands (OUT, IN, BOTH). Optional, default is BOTH.
  • label: Edge type, optional. Default represents all edge labels.
  • weight: Edge weight property, required. It must be a numeric property.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Optional, default is 10000.
  • skip_degree: Used to set the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional, default is 0 (not enabled), which means no skipping. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it after understanding and confirming.)
  • capacity: Maximum number of vertices to be visited during the traversal process. Optional, default is 10000000.
  • with_vertex: true to include complete vertex information (all vertices in the path) in the result, false to only return vertex IDs. Optional, default is false.
3.2.10.2 Usage Method
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/weightedshortestpath?source="1:marko"&target="2:ripple"&weight="weight"&with_vertex=true
Response Status
1. 200
Response Body
1. {
2. "path": {
3. "weight": 2.0,
4. "vertices": [
5. "1:marko",
6. "1:josh",
7. "2:ripple"
8. ]
9. },
10. "vertices": [
11. {
12. "id": "1:marko",
13. "label": "person",
14. "type": "vertex",
15. "properties": {
16. "name": "marko",
17. "age": 29,
18. "city": "Beijing"
19. }
20. },
21. {
22. "id": "1:josh",
23. "label": "person",
24. "type": "vertex",
25. "properties": {
26. "name": "josh",
27. "age": 32,
28. "city": "Beijing"
29. }
30. },
31. {
32. "id": "2:ripple",
33. "label": "software",
34. "type": "vertex",
35. "properties": {
36. "name": "ripple",
37. "lang": "java",
38. "price": 199
39. }
40. }
41. ]
42. }
3.2.10.3 Use Cases

Used to find the weighted shortest path between two vertices, for example:

  • In a transportation network, finding the transportation method that requires the least cost from city A to city B.

3.2.11 Single Source Shortest Path

3.2.11.1 Function Introduction

Starting from a vertex, find the shortest paths from that vertex to other vertices in the graph (optional with weight).

Params
  • source: ID of the starting vertex, required.
  • direction: Direction in which the starting vertex expands (OUT, IN, BOTH). Optional, default is BOTH.
  • label: Edge type, optional. Default represents all edge labels.
  • weight: Edge weight property, optional. It must be a numeric property. If not provided or the edges don’t have this property, the weight is considered as 1.0.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Optional, default is 10000.
  • skip_degree: Used to set the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional, default is 0 (not enabled), which means no skipping. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it after understanding and confirming.)
  • capacity: Maximum number of vertices to be visited during the traversal process. Optional, default is 10000000.
  • limit: Number of target vertices to be queried and the number of shortest paths to be returned. Optional, default is 10.
  • with_vertex: true to include complete vertex information (all vertices in the path) in the result, false to only return vertex IDs. Optional, default is false.
3.2.11.2 Usage Method
Method & Url
1. GET http://localhost:8080/graphs/{graph}/traversers/singlesourceshortestpath?source="1:marko"&with_vertex=true
Response Status
1. 200
Response Body
1. {
2. "paths": {
3. "2:ripple": {
4. "weight": 2.0,
5. "vertices": [
6. "1:marko",
7. "1:josh",
8. "2:ripple"
9. ]
10. },
11. "1:josh": {
12. "weight": 1.0,
13. "vertices": [
14. "1:marko",
15. "1:josh"
16. ]
17. },
18. "1:vadas": {
19. "weight": 1.0,
20. "vertices": [
21. "1:marko",
22. "1:vadas"
23. ]
24. },
25. "1:peter": {
26. "weight": 2.0,
27. "vertices": [
28. "1:marko",
29. "2:lop",
30. "1:peter"
31. ]
32. },
33. "2:lop": {
34. "weight": 1.0,
35. "vertices": [
36. "1:marko",
37. "2:lop"
38. ]
39. }
40. },
41. "vertices": [
42. {
43. "id": "2:ripple",
44. "label": "software",
45. "type": "vertex",
46. "properties": {
47. "name": "ripple",
48. "lang": "java",
49. "price": 199
50. }
51. },
52. {
53. "id": "1:marko",
54. "label": "person",
55. "type": "vertex",
56. "properties": {
57. "name": "marko",
58. "age": 29,
59. "city": "Beijing"
60. }
61. },
62. {
63. "id": "1:josh",
64. "label": "person",
65. "type": "vertex",
66. "properties": {
67. "name": "josh",
68. "age": 32,
69. "city": "Beijing"
70. }
71. },
72. {
73. "id": "1:vadas",
74. "label": "person",
75. "type": "vertex",
76. "properties": {
77. "name": "vadas",
78. "age": 27,
79. "city": "Hongkong"
80. }
81. },
82. {
83. "id": "1:peter",
84. "label": "person",
85. "type": "vertex",
86. "properties": {
87. "name": "peter",
88. "age": 35,
89. "city": "Shanghai"
90. }
91. },
92. {
93. "id": "2:lop",
94. "label": "software",
95. "type": "vertex",
96. "properties": {
97. "name": "lop",
98. "lang": "java",
99. "price": 328
100. }
101. }
102. ]
103. }
3.2.11.3 Use Cases

Used to find the weighted shortest path from one vertex to other vertices, for example:

  • Finding the shortest travel time by bus from Beijing to all other cities in the country.

3.2.12 Multi Node Shortest Path

3.2.12.1 Function Introduction

Finds the shortest paths between pairs of specified vertices.

Params
  • vertices: Defines the starting vertices, required. It can be specified in the following ways:

  • ids: Provide a list of vertex IDs as starting vertices.

  • label and properties: If no IDs are specified, use the combined conditions of label and properties to query the starting vertices.

    • label: Vertex type.
    • properties: Query the starting vertices based on property values.

      Note: Property values in properties can be a list, indicating that the value of the key can be any value in the list.

    • step: Represents the path from the starting vertices to the destination vertices, required. The structure of the step is as follows:
  • direction: Represents the direction of the edges (OUT, IN, BOTH). Default is BOTH.

  • labels: List of edge types.
  • properties: Filters the edges based on property values.
  • max_degree: Maximum number of adjacent edges to traverse for each vertex during the query process. Default is 10000. (Note: Before version 0.12, the step only supported “degree” as the parameter name. Starting from version 0.12, “max_degree” is used uniformly, and “degree” is still supported for backward compatibility.)
  • skip_degree: Used to set the minimum number of edges to skip super vertices during the query process. If the number of adjacent edges for a vertex is greater than skip_degree, the vertex is completely skipped. Optional, default is 0 (not enabled), which means no skipping. (Note: When this configuration is enabled, the traversal will attempt to access skip_degree edges of a vertex, not just max_degree edges. This incurs additional traversal overhead and may have a significant impact on query performance. Please enable it after understanding and confirming.)
  • max_depth: Number of steps, required.
  • capacity: Maximum number of vertices to be visited during the traversal process. Optional, default is 10000000.
  • with_vertex: true to include complete vertex information (all vertices in the path) in the result, false to only return vertex IDs. Optional, default is false.
3.2.12.2 Usage Method
Method & Url
1. POST http://localhost:8080/graphs/{graph}/traversers/multinodeshortestpath
Request Body
1. {
2. "vertices": {
3. "ids": ["382:marko", "382:josh", "382:vadas", "382:peter", "383:lop", "383:ripple"]
4. },
5. "step": {
6. "direction": "BOTH",
7. "properties": {
8. }
9. },
10. "max_depth": 10,
11. "capacity": 100000000,
12. "with_vertex": true
13. }
Response Status
1. 200
Response Body
1. {
2. "paths": [
3. {
4. "objects": [
5. "382:peter",
6. "383:lop"
7. ]
8. },
9. {
10. "objects": [
11. "382:peter",
12. "383:lop",
13. "382:marko"
14. ]
15. },
16. {
17. "objects": [
18. "382:peter",
19. "383:lop",
20. "382:josh"
21. ]
22. },
23. {
24. "objects": [
25. "382:peter",
26. "383:lop",
27. "382:marko",
28. "382:vadas"
29. ]
30. },
31. {
32. "objects": [
33. "383:lop",
34. "382:marko"
35. ]
36. },
37. {
38. "objects": [
39. "383:lop",
40. "382:josh"
41. ]
42. },
43. {
44. "objects": [
45. "383:lop",
46. "382:marko",
47. "382:vadas"
48. ]
49. },
50. {
51. "objects": [
52. "382:peter",
53. "383:lop",
54. "382:josh",
55. "383:ripple"
56. ]
57. },
58. {
59. "objects": [
60. "382:marko",
61. "382:josh"
62. ]
63. },
64. {
65. "objects": [
66. "383:lop",
67. "382:josh",
68. "383:ripple"
69. ]
70. },
71. {
72. "objects": [
73. "382:marko",
74. "382:vadas"
75. ]
76. },
77. {
78. "objects": [
79. "382:marko",
80. "382:josh",
81. "383:ripple"
82. ]
83. },
84. {
85. "objects": [
86. "382:josh",
87. "383:ripple"
88. ]
89. },
90. {
91. "objects": [
92. "382:josh",
93. "382:marko",
94. "382:vadas"
95. ]
96. },
97. {
98. "objects": [
99. "382:vadas",
100. "382:marko",
101. "382:josh",
102. "383:ripple"
103. ]
104. }
105. ],
106. "vertices": [
107. {
108. "id": "382:peter",
109. "label": "person",
110. "type": "vertex",
111. "properties": {
112. "name": "peter",
113. "age": 29,
114. "city": "Shanghai"
115. }
116. },
117. {
118. "id": "383:lop",
119. "label": "software",
120. "type": "vertex",
121. "properties": {
122. "name": "lop",
123. "lang": "java",
124. "price": 328
125. }
126. },
127. {
128. "id": "382:marko",
129. "label": "person",
130. "type": "vertex",
131. "properties": {
132. "name": "marko",
133. "age": 29,
134. "city": "Beijing"
135. }
136. },
137. {
138. "id": "382:josh",
139. "label": "person",
140. "type": "vertex",
141. "properties": {
142. "name": "josh",
143. "age": 32,
144. "city": "Beijing"
145. }
146. },
147. {
148. "id": "382:vadas",
149. "label": "person",
150. "type": "vertex",
151. "properties": {
152. "name": "vadas",
153. "age": 27,
154. "city": "Hongkong"
155. }
156. },
157. {
158. "id": "383:ripple",
159. "label": "software",
160. "type": "vertex",
161. "properties": {
162. "name": "ripple",
163. "lang": "java",
164. "price": 199
165. }
166. }
167. ]
168. }
3.2.12.3 Use Cases

Used to find the shortest paths between multiple vertices, for example:

  • Finding the shortest paths between multiple companies and their legal representatives.

3.2.13 Paths (GET, Basic Version)

3.2.13.1 Function Introduction

Finds all paths based on conditions such as the starting vertex, destination vertex, direction, edge types (optional), and maximum depth.

Params
  • source: ID of the starting vertex, required.
  • target: ID of the destination vertex, required.
  • direction: Direction in which the starting vertex expands (OUT, IN, BOTH). Optional, default is BOTH.
  • label: Edge type. Optional, default represents all edge labels.
  • max_depth: Numb

(本文超出站点单文档体积上限,已截断)