go-redis/redis · error

FT.CREATE: Type, Dim and DistanceMetric are required for VEC

Error message

FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR FLAT

What it means

Returned by FTCreate when FlatOptions is selected but Type, Dim, or DistanceMetric is unset (Type=="", Dim==0, or DistanceMetric==""). These are the mandatory parameters for a VECTOR FLAT index. The guard is at search_commands.go:1487.

Source

Thrown at search_commands.go:1489

			if schema.VectorArgs.FlatOptions != nil {
				optionCount++
			}
			if schema.VectorArgs.HNSWOptions != nil {
				optionCount++
			}
			if schema.VectorArgs.VamanaOptions != nil {
				optionCount++
			}
			if optionCount != 1 {
				cmd := NewStatusCmd(ctx, args...)
				cmd.SetErr(fmt.Errorf("FT.CREATE: SCHEMA VectorArgs must have exactly one of FlatOptions, HNSWOptions, or VamanaOptions"))
				return cmd
			}
			if schema.VectorArgs.FlatOptions != nil {
				args = append(args, "FLAT")
				if schema.VectorArgs.FlatOptions.Type == "" || schema.VectorArgs.FlatOptions.Dim == 0 || schema.VectorArgs.FlatOptions.DistanceMetric == "" {
					cmd := NewStatusCmd(ctx, args...)
					cmd.SetErr(fmt.Errorf("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR FLAT"))
					return cmd
				}
				flatArgs := []interface{}{
					"TYPE", schema.VectorArgs.FlatOptions.Type,
					"DIM", schema.VectorArgs.FlatOptions.Dim,
					"DISTANCE_METRIC", schema.VectorArgs.FlatOptions.DistanceMetric,
				}
				if schema.VectorArgs.FlatOptions.InitialCapacity > 0 {
					flatArgs = append(flatArgs, "INITIAL_CAP", schema.VectorArgs.FlatOptions.InitialCapacity)
				}
				if schema.VectorArgs.FlatOptions.BlockSize > 0 {
					flatArgs = append(flatArgs, "BLOCK_SIZE", schema.VectorArgs.FlatOptions.BlockSize)
				}
				args = append(args, len(flatArgs))
				args = append(args, flatArgs...)
			}
			if schema.VectorArgs.HNSWOptions != nil {
				args = append(args, "HNSW")

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Set FlatOptions.Type ("FLOAT32"/"FLOAT16"/"BFLOAT16"), FlatOptions.Dim (>0, matches embedding size), and FlatOptions.DistanceMetric ("COSINE"/"L2"/"IP").
  2. Load Dim from the embedding model config and assert it is non-zero before index creation.
  3. Validate the triplet in a helper before calling FTCreate.

Example fix

// before
&redis.FTFlatOptions{Type: "FLOAT32", Dim: 0}

// after
&redis.FTFlatOptions{Type: "FLOAT32", Dim: 768, DistanceMetric: "COSINE"}
Defensive patterns

Strategy: validation

Validate before calling

o := f.VectorArgs.FlatOptions
if o.Type == "" || o.Dim == 0 || o.DistanceMetric == "" {
    return fmt.Errorf("FLAT vector field %q needs Type, Dim>0, DistanceMetric", f.FieldName)
}

Prevention

When it happens

Trigger: Constructing &redis.FTFlatOptions{} without setting Type (e.g. "FLOAT32"), Dim (vector dimensionality > 0), or DistanceMetric (e.g. "COSINE", "L2", "IP").

Common situations: Reading Dim from a config/env that defaults to 0, forgetting the distance metric string, or using an unsupported Type token. Note zero Dim is indistinguishable from unset because Dim is an int.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/716266883ae71e0d.json. Report an issue: GitHub.