Schema definition

更新时间:
复制 MD 格式

Before using the Lindorm Graph Engine, you must define a schema. You can use the HTTP API to initialize a schema, extend properties, add vertex and edge types, query the schema, and clean up subgraph data.

Note

The Lindorm Graph Engine is currently in gray release. Submit a ticket to apply for whitelisting before purchasing and using it.

Prerequisites

  • The Lindorm Graph Engine has been activated and the whitelist has been configured.

  • To use the vector capability, the vector engine must be activated.

Initialize the graph schema

Endpoint: /schema/mgmt/apply?db=${DB_NAME}. Defines the complete schema of a subgraph for the first time, including vertex types, edge types, and their connection relationships. The system creates a default subgraph named default. If you do not use the multi-graph feature, all operations are performed on this subgraph.

  • Request format

    curl -X POST "http://${SERVER_HOST}:${GREMLIN_PORT}/schema/mgmt/apply?db=${DB_NAME}" \
      -u ${SUB_USER}:${SUB_PASSWORD} \
      -H "Content-Type: application/json" \
      -d '{
        "vertexLabels": [...],
        "edgeLabels": [...],
        "connections": [...]
      }'
  • Parameters

    Parameter

    Description

    SERVER_HOST

    Server hostname (for example: localhost).

    GREMLIN_PORT

    Gremlin server port (for example: 16032).

    DB_NAME

    Database (subgraph) name. The default value is default.

    SUB_USER

    Authentication username.

    SUB_PASSWORD

    Authentication password.

  • Schema structure definition

    • Without vector search capability

      The following example defines a social network graph schema that contains two vertex types, person and software, and two edge types, knows and created:

      {
        "vertexLabels": [
          {
            "label": "person",
            "properties": [
              {"name": "name", "dataType": "STRING"},
              {"name": "age",  "dataType": "INT"},
              {"name": "city", "dataType": "STRING", "cardinality": "single"}
            ]
          },
          {
            "label": "software",
            "properties": [
              {"name": "name",  "dataType": "STRING"},
              {"name": "lang",  "dataType": "STRING"},
              {"name": "price", "dataType": "INT"}
            ]
          }
        ],
        "edgeLabels": [
          {
            "label": "knows",
            "properties": [
              {"name": "date",   "dataType": "STRING"},
              {"name": "weight", "dataType": "DOUBLE"}
            ]
          },
          {
            "label": "created",
            "properties": [
              {"name": "date",   "dataType": "STRING"},
              {"name": "weight", "dataType": "DOUBLE"}
            ]
          }
        ],
        "connections": [
          {"edgeLabel": "knows",   "outVertex": "person", "inVertex": "person"},
          {"edgeLabel": "created", "outVertex": "person", "inVertex": "software"}
        ]
      }
    • With vector search capability

      If you need to use the vector search capability, you can add a VECTOR_FLOAT type field to the vertex properties:

      {
        "vertexLabels": [
          {
            "label": "person",
            "properties": [
              {"name": "name", "dataType": "STRING"},
              {"name": "age",  "dataType": "INT"},
              {"name": "city", "dataType": "STRING", "cardinality": "single"},
              {
                "name": "embedding",
                "dataType": "VECTOR_FLOAT",
                "vectorMeta": {
                  "dimension": 128,
                  "distanceMethod": "EUCLIDEAN",
                  "indexType": "HNSW",
                  "indexParams": {
                    "M": "24",
                    "EF_CONSTRUCT": "200"
                  }
                }
              }
            ]
          },
          {
            "label": "software",
            "properties": [
              {"name": "name",  "dataType": "STRING"},
              {"name": "lang",  "dataType": "STRING"},
              {"name": "price", "dataType": "INT"}
            ]
          }
        ],
        "edgeLabels": [
          {
            "label": "knows",
            "properties": [
              {"name": "date",   "dataType": "STRING"},
              {"name": "weight", "dataType": "DOUBLE"}
            ]
          },
          {
            "label": "created",
            "properties": [
              {"name": "date",   "dataType": "STRING"},
              {"name": "weight", "dataType": "DOUBLE"}
            ]
          }
        ],
        "connections": [
          {"edgeLabel": "knows",   "outVertex": "person", "inVertex": "person"},
          {"edgeLabel": "created", "outVertex": "person", "inVertex": "software"}
        ]
      }
  • Schema element descriptions

    Element

    Description

    vertexLabels

    Array of vertex type definitions. Each element describes a vertex type.

    edgeLabels

    Array of edge type definitions. Each element describes an edge type.

    connections

    Array of edge connection relationships. Specifies the source and target vertex types of an edge.

    label

    Label array.

    properties

    Array of property definitions.

    name

    Property field name.

    dataType

    Data type of the property.

    • STRING: string.

    • INT: 32-bit integer.

    • LONG: 64-bit integer.

    • DOUBLE: 64-bit floating-point number.

    • FLOAT: 32-bit floating-point number.

    • BOOLEAN: boolean value.

    • VECTOR_FLOAT: floating-point vector. Must be used with vectorMeta. For the values, see the vectorMeta parameter descriptions below.

      Important

      Only vertices are supported. To use the vector capability, you must activate the vector engine and contact our R&D team for backend configuration.

    cardinality

    Property value.

    • single (default): single-value property. Each vertex stores only one value for the field.

    • set: multi-value property. Each vertex can store multiple distinct values for the field. The set property is supported only for vertices and is not supported for edge properties.

    outVertex

    Source vertex label of the edge.

    inVertex

    Target vertex label of the edge.

  • Vector parameter vectorMeta descriptions

    Parameter

    Required

    Description

    dimension

    Yes

    Vector dimension.

    distanceMethod

    No

    Distance metric. The default value is EUCLIDEAN (that is, L2). The optional value is COSINE.

    indexType

    No

    Index type. The default value is HNSW.

    indexParams

    No

    Index build parameters (such as M and EF_CONSTRUCT).

Extend properties for an existing type

Endpoint: POST /schema/mgmt/addProperty?db=${dbName}. /schema/mgmt/apply is used only for the initial setup. To add properties to existing vertex or edge types, use this endpoint. The following examples cover four typical use cases: regular properties, set multi-value properties, vector properties, and edge property extension.

  • Add regular properties

    • Request format:

      curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "person",
          "labelType": "vertex",
          "properties": [
            {"name": "email", "dataType": "STRING"},
            {"name": "score", "dataType": "DOUBLE"}
          ]
        }'
    • Response example:

      {
        "status": "200 OK",
        "payload": {
          "label": "person",
          "labelType": "vertex",
          "propertiesAdded": ["email", "score"]
        }
      }
  • Add a set property (multi-value property)

    A set property allows a field to store multiple values (such as a list of tags). The set property is supported only for vertices, and labelType must be vertex.

    curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "person",
        "labelType": "vertex",
        "properties": [
          {"name": "tags", "dataType": "STRING", "cardinality": "set"}
        ]
      }'
  • Add a vector property

    A vector property requires an additional vectorMeta field. The system automatically creates the corresponding vector index table. Vector properties are supported only for vertices, and labelType must be vertex.

    curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "person",
        "labelType": "vertex",
        "properties": [
          {
            "name": "embedding",
            "dataType": "VECTOR_FLOAT",
            "vectorMeta": {
              "dimension": 128,
              "distanceMethod": "EUCLIDEAN",
              "indexType": "HNSW",
              "indexParams": {
                "M": "16",
                "EF_CONSTRUCT": "200"
              }
            }
          }
        ]
      }'
  • Extend properties for an existing edge type

    Set labelType to edge to extend properties for an edge type. Edges do not support set properties or vector properties.

    • Request format:

      curl -X POST 'http://${host}:${port}/schema/mgmt/addProperty?db=default' \
        -H 'Content-Type: application/json' \
        -u '${user}:${password}' \
        -d '{
          "label": "knows",
          "labelType": "edge",
          "properties": [
            {"name": "since", "dataType": "LONG"}
          ]
        }'
    • Response example:

      {
        "status": "200 OK",
        "payload": {
          "label": "knows",
          "labelType": "edge",
          "propertiesAdded": ["since"]
        }
      }

Add a new vertex type

Endpoint: POST /schema/mgmt/addVertexLabel?db=${dbName}. Creates a new vertex type in an existing subgraph and defines its properties. The system automatically creates the corresponding underlying physical table.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/addVertexLabel?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "product",
        "properties": [
          {"name": "productName", "dataType": "STRING"},
          {"name": "price",       "dataType": "DOUBLE"},
          {"name": "category",    "dataType": "STRING"}
        ]
      }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "vertexLabelCreated": "product",
        "propertiesCount": 3
      }
    }

Add a new edge type

Endpoint: POST /schema/mgmt/addEdgeLabel?db=${dbName}. Creates a new edge type in an existing subgraph. The connection field specifies the source and target vertex types, which must already exist; otherwise, the endpoint returns an error.

  • Request format:

    curl -X POST 'http://${host}:${port}/schema/mgmt/addEdgeLabel?db=default' \
      -H 'Content-Type: application/json' \
      -u '${user}:${password}' \
      -d '{
        "label": "purchased",
        "properties": [
          {"name": "purchaseDate", "dataType": "STRING"},
          {"name": "quantity",     "dataType": "INT"}
        ],
        "connection": {
          "outVertex": "person",
          "inVertex": "product"
        }
      }'
  • Response example:

    {
      "status": "200 OK",
      "payload": {
        "edgeLabelCreated": "purchased",
        "propertiesCount": 2,
        "connectionRegistered": "person-purchased->product"
      }
    }

    The connectionRegistered field in the response is formatted as ${outVertex}-${edgeLabel}->${inVertex}, which indicates the edge direction that has been successfully registered.

Query the current schema

Endpoint: GET /schema/mgmt/list?db=${dbName}. Returns the complete schema definition of the specified subgraph, including all vertex types, edge types, and their connection relationships. Requires the READDATA permission.

  • Request format:

    curl -X GET 'http://${host}:${port}/schema/mgmt/list?db=default' \
      -u '${user}:${password}'
  • Response example:

    {
      "payload": {
        "edgeConnections": {
          "created": [
            "person",
            "software"
          ],
          "knows": [
            "person",
            "person"
          ]
        },
        "edgeLabels": {
          "created": [
            {
              "dataType": "STRING",
              "name": "date"
            },
            {
              "dataType": "DOUBLE",
              "name": "weight"
            }
          ],
          "knows": [
            {
              "dataType": "STRING",
              "name": "date"
            },
            {
              "dataType": "DOUBLE",
              "name": "weight"
            }
          ]
        },
        "schemaVersion": 0,
        "vertexLabels": {
          "software": [
            {
              "dataType": "STRING",
              "name": "name"
            },
            {
              "dataType": "STRING",
              "name": "lang"
            },
            {
              "dataType": "INT",
              "name": "price"
            }
          ],
          "person": [
            {
              "dataType": "STRING",
              "name": "name"
            },
            {
              "dataType": "INT",
              "name": "age"
            },
            {
              "dataType": "STRING",
              "name": "city"
            }
          ]
        }
      },
      "status": "200 OK"
    }

Clean up subgraph data

Endpoint: /db/del. Quickly cleans up a subgraph. Requires the root account. For the default subgraph default, this endpoint clears the data and deletes the schema definition but retains the subgraph itself. For any other subgraph, the entire subgraph is deleted.

curl -X GET 'http://${host}:${port}/db/del?db=default' \
  -u '${root_user}:${root_password}'