{"record":{"id":"775a4dcfd46f9058","repo":"dgraph-io/dgraph","slug":"not-allowed-to-insert-mutations-in-vector-index-ke","errorCode":null,"errorMessage":"Not allowed to insert mutations in vector index keys, edge: [%v]","messagePattern":"Not allowed to insert mutations in vector index keys, edge: \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":517,"sourceCode":"\t\t}\n\t}\n\n\treturn errors.Errorf(\"@unique directive not supported on [%v] type predicate\", currentSchema.ValueType.String())\n}\n\n// ValidateAndConvert checks compatibility or converts to the schema type if the storage type is\n// specified. If no storage type is specified then it converts to the schema type.\nfunc ValidateAndConvert(edge *pb.DirectedEdge, su *pb.SchemaUpdate) error {\n\n\tif isDeletePredicateEdge(edge) {\n\t\treturn nil\n\t}\n\tif types.TypeID(edge.ValueType) == types.DefaultID && isStarAll(edge.Value) {\n\t\treturn nil\n\t}\n\n\tif strings.Contains(su.Predicate, hnsw.VecKeyword) {\n\t\treturn errors.Errorf(\"Not allowed to insert mutations in vector index keys, edge: [%v]\", edge)\n\t}\n\n\tstorageType := posting.TypeID(edge)\n\tschemaType := types.TypeID(su.ValueType)\n\n\t// type checks\n\tswitch {\n\tcase edge.Lang != \"\" && !su.GetLang():\n\t\treturn errors.Errorf(\"Attr: [%v] should have @lang directive in schema to mutate edge: [%v]\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase !schemaType.IsScalar() && !storageType.IsScalar():\n\t\treturn nil\n\n\tcase !schemaType.IsScalar() && storageType.IsScalar():\n\t\treturn errors.Errorf(\"Input for predicate %q of type uid is scalar. Edge: %v\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L499-L535","documentation":"Dgraph stores HNSW vector index internals under predicates whose name contains the vector keyword (e.g. a predicate ending in '|hnsw:vector'). These internal edges are managed by the vector index itself; ValidateAndConvert rejects any user mutation whose predicate name contains that keyword so clients cannot corrupt the index structure.","triggerScenarios":"Running a mutation (via runMutation -> proposeAndWait) that writes to a predicate whose name contains 'hnsw' (VecKeyword), typically by copy-pasting the internal vector-index predicate name from a query or backup instead of the original vector predicate.","commonSituations":"Hand-crafting RDF/N-Quad mutations against internal index keys seen in * (expand-all) results; backup/restore tooling or scripts that replay every predicate including internal vector index keys; typos appending the hnsw suffix to a vector predicate.","solutions":["Mutate the original vector predicate (e.g. `emb` of type float32vector) instead of its `<emb|hnsw:...>` internal key.","Filter out predicates containing the vector keyword from migration/backup replay scripts.","Use the standard mutation APIs to update vectors; the HNSW index is maintained automatically."],"exampleFix":"// before (fails)\n<0x1> <emb|hnsw:vector> \"[0.1,0.2]\" .\n\n// after\n<0x1> <emb> \"[0.1,0.2]\"^^<xs:floatVector> .","handlingStrategy":"validation","validationCode":"const vecKeyword = \"|hnsw\"\nfunction isInternalVectorPred(pred) {\n  return typeof pred === 'string' && pred.includes(vecKeyword)\n}\n// filter all N-Quads before mutation:\nnquads = nquads.filter(nq => !isInternalVectorPred(nq.predicate))","typeGuard":"function isUserPredicate(pred) {\n  return typeof pred === 'string' && !pred.includes('|hnsw') && !pred.includes('dgraph.')\n}","tryCatchPattern":"try {\n  await dgraph.mutation(setNquads)\n} catch (e) {\n  if (String(e).includes('vector index keys')) {\n    // strip internal hnsw predicates from the batch and re-run\n  }\n}","preventionTips":["Never mutate predicates returned by expand(*) that contain '|hnsw' or other internal markers.","Filter internal predicates (hnsw, dgraph.*) out of backup-replay/migration scripts.","Update vectors only through the original float32vector predicate."],"tags":["dgraph","mutation","vector-index","hnsw"],"backgroundTag":"internal-key-write-rejected","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}