weaviate/weaviate · error

could not handle type of near vector for target %s, got %v

Error message

could not handle type of near vector for target %s, got %v

What it means

This is the final type-check in the vectorPerTarget loop: after []float32, [][]float32 and [][][]float32 all fail, the value's type is unhandled and ExtractNearVector returns this error including the target name and the Go dynamic type (%v of vectorPerTargetParsed). It guards against arbitrary malformed payloads reaching the search layer.

Source

Thrown at adapters/handlers/graphql/local/common_filters/near_vector.go:143

					// if one target vector has multiple search vectors, the target vector needs to be repeated multiple times
					for j, w := range vectorsIn {
						if !targetVectorOrderMatches(i, j, targetVectors, target) {
							return searchparams.NearVector{}, nil, fmt.Errorf("target %s is not in the correct order", target)
						}
						vectors[i+j] = w
					}
				} else if multiVectorsIn, ok := vectorPerTargetParsed.([][][]float32); ok {
					// NOTE the type of multiVectorsIn is [][][]float32 (vs vectorsIn which is [][]float32),
					// so there are two similar loops here to handle the different types, if there is a simpler
					// way to handle this, feel free to change it
					for j, w := range multiVectorsIn {
						if !targetVectorOrderMatches(i, j, targetVectors, target) {
							return searchparams.NearVector{}, nil, fmt.Errorf("multivector target %s is not in the correct order", target)
						}
						vectors[i+j] = w
					}
				} else {
					return searchparams.NearVector{}, nil, fmt.Errorf("could not handle type of near vector for target %s, got %v", target, vectorPerTargetParsed)
				}
			}
		}
		args.Vectors = vectors
	}

	return args, combination, nil
}

func targetVectorOrderMatches(i, j int, targetVectors []string, target string) bool {
	return i+j < len(targetVectors) && targetVectors[i+j] == target
}

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Check the printed type in the message and reshape the value to [float], [[float]] or [[[float]]] as appropriate.
  2. For single-vector named collections use a flat array of numbers; for multi-vector use arrays of arrays of arrays.
  3. Validate payload shape client-side before sending (see defense validationCode).

Example fix

// before
vectorPerTarget: { title: 0.1 }
// after
vectorPerTarget: { title: [0.1] }
Defensive patterns

Strategy: validation

Validate before calling

for (const [t, v] of Object.entries(vectorPerTarget)) {
  const shape = shapeOf(v);
  if (!['vec','vecList','multiVecList'].includes(shape)) throw new Error(`vectorPerTarget['${t}'] has invalid shape ${shape}`);
}
function shapeOf(v){
  if(!Array.isArray(v)) return 'other';
  if(typeof v[0]==='number') return 'vec';
  if(Array.isArray(v[0]) && typeof v[0][0]==='number') return 'vecList';
  if(Array.isArray(v[0]?.[0])) return 'multiVecList';
  return 'other';
}

Type guard

function isVectorShape(v) {
  return Array.isArray(v) && (typeof v[0] === 'number' ||
    (Array.isArray(v[0]) && typeof v[0][0] === 'number') ||
    (Array.isArray(v[0]?.[0])));
}

Try / catch

try {
  await query();
} catch (e) {
  if (String(e).includes('could not handle type of near vector')) {
    throw new UsageError('Reshape vectorPerTarget values to number[], number[][], or number[][][]');
  }
  throw e;
}

Prevention

When it happens

Trigger: `vectorPerTarget: { target: 42 }`, `{ target: "abc" }`, or a deeply/irregularly nested list (e.g. []interface{} mixing numbers and arrays) that matches none of the three accepted slice types.

Common situations: JSON sent with wrong nesting for multi-vector collections (extra or missing bracket level); GraphQL variables serialized as strings; scalar passed instead of array.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/0503412c00c63f5d. Report an issue: GitHub.