Vector data insertion and index building
After defining vector properties in the graph schema, you can write vector data to vertices. HNSW indexes take effect automatically when data is written. HNSWQ, IVFPQ, and IVFBQ indexes require manual triggering after sufficient training data has been written. This topic describes the write requirements, write methods, index build procedures for different index types, and how to query index build progress.
Prerequisites
Lindorm Graph Engine is activated and the access whitelist is configured.
Lindorm Vector Engine is activated.
The graph schema is initialized, and the target vertex type has
VECTOR_FLOATvector properties andvectorMetadefined.The connection endpoint, database name, username, and password of Graph Engine are obtained.
Insert vector data
Write requirements
Vector data is written as vertex properties. Before writing, make sure the following requirements are met:
Vector properties are supported only on vertices. Edges do not support vector properties.
The data type of vector properties is
VECTOR_FLOAT. FLOAT32 vectors are used.Each element in the vector array must be a numeric value.
The vector array length must match the dimension defined by
vectorMeta.dimensionin the schema.The distance type is determined by
distanceMethodin the schema and cannot be specified separately when writing data.When using
COSINEdistance, do not write zero vectors because the cosine similarity of a zero vector is undefined.
The following examples assume that the document vertex type and its properties are already defined in the schema:
Property | Data type | Description |
|
| A 4-dimensional vector property. |
|
| The document title. |
|
| The document category. |
|
| The document status. |
Write vertices using Gremlin
Use property() to write vector properties. Vector values are represented as numeric arrays:
g.addV('document')
.property(id, 'doc_same')
.property('embedding', [1.0d, 0.0d, 0.0d, 0.0d])
.property('title', 'Exact match')
.property('category', 'guide')
.property('status', 'online')The corresponding HTTP request is as follows:
curl -sS -u "${SUB_USER}:${SUB_PASSWORD}" -X POST \
"http://${SERVER_HOST}:${GREMLIN_PORT}/gremlin/${DB_NAME}" \
-H 'Content-Type: application/json' \
--data '{
"gremlin": "g.addV(\"document\").property(id,\"doc_same\").property(\"embedding\",[1.0d,0.0d,0.0d,0.0d]).property(\"title\",\"Exact match\").property(\"category\",\"guide\").property(\"status\",\"online\")"
}'The Gremlin HTTP interface returns a GraphSON 3 standard response envelope. When the write succeeds, verify that both the HTTP status code and status.code in the response are 200.
Sample data
You can continue to write the following vertices in the same way:
Vertex ID | embedding | title | category | status |
|
| Exact match | guide | online |
|
| Same direction different length | guide | online |
|
| Orthogonal vector | reference | offline |
|
| Opposite vector | archive | online |
For example, write doc_scaled:
curl -sS -u "${SUB_USER}:${SUB_PASSWORD}" -X POST \
"http://${SERVER_HOST}:${GREMLIN_PORT}/gremlin/${DB_NAME}" \
-H 'Content-Type: application/json' \
--data '{
"gremlin": "g.addV(\"document\").property(id,\"doc_scaled\").property(\"embedding\",[2.0d,0.0d,0.0d,0.0d]).property(\"title\",\"Same direction different length\").property(\"category\",\"guide\").property(\"status\",\"online\")"
}'Update vector properties
To update the vector property of a vertex, also use property(). The new vector must meet the dimension requirements in the schema:
g.V('doc_same')
.property('embedding', [0.9d, 0.1d, 0.0d, 0.0d])The corresponding HTTP request is as follows:
curl -sS -u "${SUB_USER}:${SUB_PASSWORD}" -X POST \
"http://${SERVER_HOST}:${GREMLIN_PORT}/gremlin/${DB_NAME}" \
-H 'Content-Type: application/json' \
--data '{
"gremlin": "g.V(\"doc_same\").property(\"embedding\",[0.9d,0.1d,0.0d,0.0d])"
}'Build vector indexes
For more information about vector index build, including constraints and considerations, see the index build section in Basic features of the Vector Engine documentation.
HNSW type
HNSW indexes take effect immediately when data is written. No manual index build is required.
HNSWQ, IVFPQ, and IVFBQ types
For HNSWQ, IVFPQ, and IVFBQ indexes, you must first write sufficient training data before manually triggering the build. Make sure that all data is written and meets the minimum data volume requirement before triggering the build.
After the manual index build for HNSWQ, IVFPQ, and IVFBQ is complete, you can continue to write and query data normally. No rebuild is required.
The minimum training data volumes are as follows:
Index type | Minimum data volume |
|
|
|
|
|
|
The manual build API is:
POST /schema/mgmt/index/build?db={dbName}Example curl command:
curl -X POST \
"http://${SERVER_HOST}:${GREMLIN_PORT}/schema/mgmt/index/build?db=${DB_NAME}" \
-u "${SUB_USER}:${SUB_PASSWORD}" \
-H 'Content-Type: application/json' \
-d '{
"label": "person",
"propertyName": "embedding"
}'The request parameters are as follows.
Parameter | Required | Description |
| Yes | The vertex type name. |
| Yes | The name of the vector property for which to build the index. |
Example response:
{
"status": "200 OK",
"payload": {
"label": "person",
"propertyName": "embedding",
"message": "Build index job submitted. Use GET /schema/mgmt/index/progress to poll for completion."
}
}A successful response indicates that the build job has been submitted, not that the index build is complete. You must continue to poll the build progress until the status changes to DONE and indexBuilt is true.
Query index build progress
Request format
The progress query API is:
GET /schema/mgmt/index/progress?db={dbName}&label={label}&propertyName={propertyName}Example curl command:
curl -X GET \
"http://${SERVER_HOST}:${GREMLIN_PORT}/schema/mgmt/index/progress?db=${DB_NAME}&label=person&propertyName=embedding" \
-u "${SUB_USER}:${SUB_PASSWORD}"The request parameters are as follows.
Parameter | Required | Description |
| Yes | The database name, also known as the subgraph name. |
| Yes | The vertex type name. |
| Yes | The vector property name. |
Response and status description
Example response:
{
"status": "200 OK",
"payload": {
"label": "person",
"propertyName": "embedding",
"status": "DONE",
"indexBuilt": true
}
}The response fields are described as follows.
Field | Description |
| The build job status. Valid values: |
|
|
| Returned when error details are available. You can use this field to troub the cause of a build failure. |
The status values are described as follows.
Status | Description |
| The index is being built. |
| The index build is complete. Also confirm that |
| The index build failed. Check |
Schema query
For more information about the schema query API, including constraints and considerations, see the query current schema section in Graph Schema Definition.
For vector properties in the schema, indexed is always false. indexBuilt indicates whether the index has been built through an explicit build job.
HNSW indexes take effect immediately when data is written. After the schema is created and before any explicit build call, both indexed and indexBuilt are false. This does not affect HNSW queries. A complete sample response is as follows:
{
"status": "200 OK",
"payload": {
"schemaVersion": 1,
"vertexLabels": {
"document": [
{
"name": "embedding",
"dataType": "VECTOR_FLOAT",
"indexed": false,
"indexBuilt": false,
"vectorMeta": {
"dimension": 128,
"distanceMethod": "L2",
"indexType": "HNSW",
"indexParams": {
"M": "16",
"EF_CONSTRUCT": "200"
}
}
}
]
},
"edgeLabels": {},
"edgeConnections": {}
}
}For property types that require training, such as HNSWQ, IVFPQ, and IVFBQ, indexBuilt changes to true after a successful explicit build. The build job runs asynchronously after submission, so an immediate schema query may still show false. Use the progress API returning DONE with indexBuilt=true as the confirmation of completion.
The following is the schema data for a 128-dimensional HNSWQ vector property named embedding before the index build. Both indexed and indexBuilt are false.
{
"status": "200 OK",
"payload": {
"schemaVersion": 1,
"vertexLabels": {
"document": [
{
"name": "embedding",
"dataType": "VECTOR_FLOAT",
"indexed": false,
"indexBuilt": false,
"vectorMeta": {
"dimension": 128,
"distanceMethod": "L2",
"indexType": "HNSWQ",
"indexParams": {
"M": "16",
"EF_CONSTRUCT": "200"
}
}
}
]
},
"edgeLabels": {},
"edgeConnections": {}
}
}After calling the index build API and confirming that the build is complete, the schema data may look like the following. indexed remains false, and indexBuilt is updated to true.
{
"status": "200 OK",
"payload": {
"schemaVersion": 2,
"vertexLabels": {
"document": [
{
"name": "embedding",
"dataType": "VECTOR_FLOAT",
"indexed": false,
"indexBuilt": true,
"vectorMeta": {
"dimension": 128,
"distanceMethod": "L2",
"indexType": "HNSWQ",
"indexParams": {
"M": "16",
"EF_CONSTRUCT": "200"
}
}
}
]
},
"edgeLabels": {},
"edgeConnections": {}
}
}Recommended operation procedure
HNSW
Define a
VECTOR_FLOATproperty for the vertex in the schema, and setindexTypetoHNSW.Write vector data that meets the dimension requirements.
The index takes effect automatically after data is written. No build job is required.
HNSWQ, IVFPQ, and IVFBQ
Define the vector index of the corresponding type in the schema.
Write vector data that meets or exceeds the minimum training data volume.
Call
/schema/mgmt/index/buildto submit the index build job.Poll
/schema/mgmt/index/progress.Wait for
statusto returnDONE, and confirm thatindexBuiltistrue.
If the build job fails, check errorInfo in the response to troubleshoot the issue. Do not treat the index as available until the build is complete.