Schema definition with vector capabilities

Updated at:

This topic describes how to define vector properties and vector indexes in vertex schemas of the Lindorm graph engine. The related APIs are fully reused from the Schema definition topic.

Prerequisites

  • Lindorm Graph Engine is activated and the access whitelist is configured.

  • Lindorm Vector Engine is activated.

  • The connection endpoint, database name, username, and password of the graph engine are obtained.

Notes

When using vector properties, note the following limits:

  • Vector properties are supported only on vertices. Edges do not support vector properties.

  • Do not name a vertex property _score. This name is reserved for vector search results.

  • Only FLOAT32 vectors are supported. The corresponding property type is VECTOR_FLOAT.

  • VECTOR_FLOAT must be used together with vectorMeta.

  • A single vertex type can have multiple vector properties, each with its own dimension and index configuration.

  • The distance method is determined at the Schema level and cannot be changed per query.

Vector property definition

Basic structure

Vector indexes are created through the Schema API. Currently, vector properties are supported only on vertices. Set dataType to VECTOR_FLOAT in a vertex property and configure vectorMeta. The system creates a corresponding vector index table for the vertex type.

Example of a vector property definition:

{
  "name": "embedding",
  "dataType": "VECTOR_FLOAT",
  "vectorMeta": {
    "dimension": 128,
    "distanceMethod": "L2",
    "indexType": "HNSW",
    "indexParams": {
      "M": "24",
      "EF_CONSTRUCT": "200"
    }
  }
}

Common parameters

Parameter

Required

Description

dimension

Yes

The number of dimensions of the vector. Valid values: [1,131072]. The dimension of the written vectors and query vectors must match this value.

distanceMethod

No

The distance metric. Default value: L2. Valid values: L2 and COSINE. If other values such as EUCLIDEAN are passed, they are treated as L2 for vector computation. IP and JACCARD are currently disabled.

indexType

No

The index type. Default value: HNSW. Valid values: HNSW, HNSWQ, IVFPQ, and IVFBQ. For more information about index type selection, see Basic features in the Vector Engine documentation.

indexParams

No

The index parameters, specified as key-value string pairs. Different index types support different parameters.

indexParams has different parameter requirements for different index types.

Index parameters

HNSW index parameters

HNSW is a hierarchical navigable small world graph index. It takes effect immediately upon data write and does not require manual building.

Parameter

Type

Default

Valid values

Description

M

int

24

[1,100]

The maximum number of outgoing edges at each layer of the graph. Optional.

EF_CONSTRUCT

int

500

[1,1000]

The length of the dynamic list during index construction. Optional.

HNSWQ index parameters

HNSWQ is a compressed index that combines HNSW with multi-level quantization. It requires manual triggering of the build process after training data is written.

Parameter

Type

Default

Valid values

Description

M

int

24

[1,100]

The maximum number of outgoing edges at each layer of the graph. Optional.

EF_CONSTRUCT

int

500

[1,1000]

The length of the dynamic list during index construction. Optional.

IVFPQ index parameters

IVFPQ is an index that combines inverted file with product quantization. It requires manual triggering of the build process after training data is written.

Parameter

Type

Default

Valid values

Description

M

int

dimension

[2,131072]

The number of subspaces in product quantization. Optional.

Important

When creating an IVFPQ index, the value of this parameter must be the same as the value of the dimension common parameter.

NLIST

int

10000

[2,1000000]

The number of clustering centers. Optional.

IVFBQ index parameters

IVFBQ is an index that combines inverted file with binary quantization (RaBitQ). It requires manual triggering of the build process after training data is written.

Parameter

Type

Default

Valid values

Description

EXBITS

int

0

0, 2, 3, 4, 6, 7, 8

Specifies the number of additional bytes used to represent quantized vectors. A larger value indicates higher precision but greater storage overhead. Optional.

NLIST

int

10000

[2,1000000]

The number of clustering centers. Optional.

Initialize a graph Schema with vector capabilities

Note

This section provides only some examples. For detailed API descriptions and limits, see the Schema definition topic.

The API endpoint is POST /schema/mgmt/apply?db=${DB_NAME}. The following example defines a person vertex type with regular properties named name and age, and a 128-dimensional HNSW vector property named embedding:

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": [{
      "label": "person",
      "properties": [
        {"name": "name", "dataType": "STRING"},
        {"name": "age", "dataType": "INT"},
        {
          "name": "embedding",
          "dataType": "VECTOR_FLOAT",
          "vectorMeta": {
            "dimension": 128,
            "distanceMethod": "L2",
            "indexType": "HNSW",
            "indexParams": {
              "M": "24",
              "EF_CONSTRUCT": "200"
            }
          }
        }
      ]
    }]
  }'

Sample response:

{
  "status": "200 OK",
  "payload": {
    "vertexLabelsCreated": [
      "person"
    ],
    "edgeLabelsCreated": [],
    "connectionsRegistered": []
  }
}

Extend vector capabilities for an existing Schema

Note

This section provides only some examples. For detailed API descriptions and limits, see the Schema definition topic.

Add vector properties to an existing vertex type

The API endpoint is POST /schema/mgmt/addProperty?db=${DB_NAME}. The following example adds a 128-dimensional HNSW vector property named embedding to the person vertex type.

curl -X POST \
  "http://${SERVER_HOST}:${GREMLIN_PORT}/schema/mgmt/addProperty?db=${DB_NAME}" \
  -u "${SUB_USER}:${SUB_PASSWORD}" \
  -H 'Content-Type: application/json' \
  -d '{
    "label": "person",
    "labelType": "vertex",
    "properties": [{
      "name": "embedding",
      "dataType": "VECTOR_FLOAT",
      "vectorMeta": {
        "dimension": 128,
        "distanceMethod": "L2",
        "indexType": "HNSW",
        "indexParams": {
          "M": "16",
          "EF_CONSTRUCT": "200"
        }
      }
    }]
  }'

Sample response:

{
  "status": "200 OK",
  "payload": {
    "label": "person",
    "labelType": "vertex",
    "propertiesAdded": [
      "embedding"
    ]
  }
}

Add a new vertex type with vector properties

The API endpoint is POST /schema/mgmt/addVertexLabel?db=${DB_NAME}. The following example adds an article vertex type to an existing subgraph, with a regular property named title and a 512-dimensional IVFBQ vector property named content_vector:

curl -X POST \
  "http://${SERVER_HOST}:${GREMLIN_PORT}/schema/mgmt/addVertexLabel?db=${DB_NAME}" \
  -u "${SUB_USER}:${SUB_PASSWORD}" \
  -H 'Content-Type: application/json' \
  -d '{
    "label": "article",
    "properties": [
      {"name": "title", "dataType": "STRING"},
      {
        "name": "content_vector",
        "dataType": "VECTOR_FLOAT",
        "vectorMeta": {
          "dimension": 512,
          "distanceMethod": "COSINE",
          "indexType": "IVFBQ",
          "indexParams": {
            "NLIST": "5000",
            "EXBITS": "2"
          }
        }
      }
    ]
  }'

Sample response:

{
  "status": "200 OK",
  "payload": {
    "vertexLabelCreated": "article",
    "propertiesCount": 2
  }
}