Help Center/ Graph Engine Service/ API Reference/ Application Examples/ Analyzing Graphs Using HyG Algorithms
Updated on 2024-05-20 GMT+08:00

Analyzing Graphs Using HyG Algorithms

GES offers a range of fundamental graph algorithms, graph analysis algorithms, and graph metric algorithms. These algorithms can be used for analyzing relationships within a graph.

Prerequisites

The HyG computing engine slider was toggled on when creating a graph of the database edition.

Figure 1 HyG computing engine

Procedure

  1. Create a HyG graph.
    1. Send POST /ges/v1.0/{project_id}/hyg/{graph_name}. project_id indicates the project ID, and graph_name indicates the name of a graph created in the graph database.
    2. Add X-Auth-Token to the request header.
    3. Specify the following parameters in the request body:
      {
          "inEdge": true  // Whether the graph contains the incoming edge
      }
    4. Check the response. The request is successful if the following response is displayed:
      {
          "result": "success"
      }

      If the request is abnormal, locate the fault by referring to Error Codes for Service Plane APIs.

  2. Synchronize data from the graph database to the HyG computing engine.
    1. Send POST /ges/v1.0/{project_id}/hyg/{graph_name}/sync. project_id indicates the project ID, and graph_name indicates the graph name.
    2. Add X-Auth-Token to the request header.
    3. Specify the following parameters in the request body:
      {
          "vertex": [], // Vertex property list
       
          "edge": [
              {
                  "property": [
                      "Rating"
                  ],
                  "label": "rate"
              }
          ] // Edge property list
      }
    4. Check the response based on the job ID. The request is successful if the following response is displayed:
      {
          "status": "complete",
          "result": "success"
      }

      If the request is abnormal, locate the fault by referring to Error Codes for Service Plane APIs.

      With this API, you can synchronize any changes made to the graph database, whether it be adding, deleting, or modifying data, to the HyG computing engine. During the initial data synchronization, the vertex and edge parameters specified in the request body will be applied. For subsequent synchronizations, these parameters will default to the values specified during the first synchronization.

  3. Check details about the HyG graph.
    1. Send GET /ges/v1.0/{project_id}/hyg/{graph_name}/summary. project_id indicates the project ID, and graph_name indicates the graph name.
    2. Add X-Auth-Token to the request header.
    3. Check the response. The request is successful if the following response is displayed:
      {
          "data": {
              "inEdge": true,
              "idIndex": true,
              "policy": "oec",
              "updateTime": "2024-01-25 10:55:31",
              "vertex": [],
              "edge": [
                  {
                      "label": "rate",
                      "property": [
                          "Rating"
                      ]
                  }
              ],
              "vertexNum": 146,
              "edgeNum": 1659
          },
          "result": "success"
      }

      If the request is abnormal, locate the fault by referring to Error Codes for Service Plane APIs.

  4. Execute the algorithm.
    1. Send POST /ges/v1.0/{project_id}/hyg/{graph_name}/algorithm. project_id indicates the project ID, and graph_name indicates the graph name.
    2. Add X-Auth-Token to the request header.
    3. Specify the following parameters in the request body (using PageRank as an example):
      {
      "algorithmName":"pagerank",
        "parameters":{
              "alpha":0.85,
              "convergence":0.00001,
              "max_iterations":1000,
              "directed":true
        }
      }
    4. Check the response based on the job ID. The request is successful if the following response is displayed:
      {
          "status": "complete",
          "data": {
              "outputs": {
                  "data_offset": 0,
                  "data_return_size": 147,
                  "data_total_size": 147,
                  "pagerank": [
                      {
                          "38": 0.02115960730038959
                      },
                      {
                          "13": 0.018535705068819635
                      },
                      {
                          "7": 0.0166381431701182
                      },
                      ... ...
                  ],
                  "runtime": 0.022
              }
          },
          "result": "success"
      }

      If the request is abnormal, locate the fault by referring to Error Codes for Service Plane APIs.

  5. Delete the HyG graph.
    1. Send DELETE /ges/v1.0/{project_id}/hyg/{graph_name}. project_id indicates the project ID, and graph_name indicates the graph name.
    2. Add X-Auth-Token to the request header.
    3. Check the response based on the job ID. The request is successful if the following response is displayed:
      {
          "status": "complete",
          "result": "success"
      }

      If the request is abnormal, locate the fault by referring to Error Codes for Service Plane APIs.