{"id":"2ac6d948093478e6","repo":"go-redis/redis","slug":"ft-create-schema-fieldtype-vector-is-required-for","errorCode":null,"errorMessage":"FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs","messagePattern":"FT\\.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":1466,"sourceCode":"\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA is required\"))\n\t\treturn cmd\n\t}\n\targs = append(args, \"SCHEMA\")\n\tfor _, schema := range schema {\n\t\tif schema.FieldName == \"\" || schema.FieldType == SearchFieldTypeInvalid {\n\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA FieldName and FieldType are required\"))\n\t\t\treturn cmd\n\t\t}\n\t\targs = append(args, schema.FieldName)\n\t\tif schema.As != \"\" {\n\t\t\targs = append(args, \"AS\", schema.As)\n\t\t}\n\t\targs = append(args, schema.FieldType.String())\n\t\tif schema.VectorArgs != nil {\n\t\t\tif schema.FieldType != SearchFieldTypeVector {\n\t\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs\"))\n\t\t\t\treturn cmd\n\t\t\t}\n\t\t\t// Check mutual exclusivity of vector options\n\t\t\toptionCount := 0\n\t\t\tif schema.VectorArgs.FlatOptions != nil {\n\t\t\t\toptionCount++\n\t\t\t}\n\t\t\tif schema.VectorArgs.HNSWOptions != nil {\n\t\t\t\toptionCount++\n\t\t\t}\n\t\t\tif schema.VectorArgs.VamanaOptions != nil {\n\t\t\t\toptionCount++\n\t\t\t}\n\t\t\tif optionCount != 1 {\n\t\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA VectorArgs must have exactly one of FlatOptions, HNSWOptions, or VamanaOptions\"))\n\t\t\t\treturn cmd\n\t\t\t}","sourceCodeStart":1448,"sourceCodeEnd":1484,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L1448-L1484","documentation":"Returned by FTCreate when VectorArgs is non-nil but the FieldSchema.FieldType is not SearchFieldType. Only a VECTOR field carries vector index options (FLAT/HNSW/Vamana); attaching VectorArgs to a TEXT/NUMERIC/TAG field is contradictory. The guard is at search_commands.go:1464.","triggerScenarios":"Setting schema.VectorArgs on a FieldSchema whose FieldType was left as the default or explicitly set to a non-VECTOR type. Common when reusing a FieldSchema template for multiple field kinds.","commonSituations":"Copy-pasting a text field schema and adding VectorArgs without changing FieldType, or building a field map where the type key and vector options come from different sources that disagree.","solutions":["Set FieldType: redis.SearchFieldTypeVector on any FieldSchema that also sets VectorArgs.","Centralize vector-field construction in a helper that always sets both together.","Add a unit test asserting every FieldSchema with VectorArgs has FieldType == SearchFieldTypeVector."],"exampleFix":"// before\n&redis.FieldSchema{FieldName: \"v\", FieldType: redis.SearchFieldTypeText, VectorArgs: vec}\n\n// after\n&redis.FieldSchema{FieldName: \"v\", FieldType: redis.SearchFieldTypeVector, VectorArgs: vec}","handlingStrategy":"validation","validationCode":"if f.VectorArgs != nil && f.FieldType != redis.SearchFieldTypeVector {\n    return fmt.Errorf(\"field %q: VectorArgs requires FieldType=VECTOR\", f.FieldName)\n}","typeGuard":"func vectorArgsConsistent(f *redis.FieldSchema) bool {\n    if f.VectorArgs == nil {\n        return true\n    }\n    return f.FieldType == redis.SearchFieldTypeVector\n}","tryCatchPattern":null,"preventionTips":["Always pair VectorArgs with FieldType: SearchFieldTypeVector in the same constructor.","Unit-test that no field mixes VectorArgs with a non-VECTOR type.","Keep vector-field creation in a dedicated helper to avoid the inconsistency."],"tags":["redisearch","ft-create","vector","schema","validation"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}