{"record":{"id":"0503412c00c63f5d","repo":"weaviate/weaviate","slug":"could-not-handle-type-of-near-vector-for-target-s","errorCode":null,"errorMessage":"could not handle type of near vector for target %s, got %v","messagePattern":"could not handle type of near vector for target (.+?), got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/handlers/graphql/local/common_filters/near_vector.go","lineNumber":143,"sourceCode":"\t\t\t\t\t// if one target vector has multiple search vectors, the target vector needs to be repeated multiple times\n\t\t\t\t\tfor j, w := range vectorsIn {\n\t\t\t\t\t\tif !targetVectorOrderMatches(i, j, targetVectors, target) {\n\t\t\t\t\t\t\treturn searchparams.NearVector{}, nil, fmt.Errorf(\"target %s is not in the correct order\", target)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvectors[i+j] = w\n\t\t\t\t\t}\n\t\t\t\t} else if multiVectorsIn, ok := vectorPerTargetParsed.([][][]float32); ok {\n\t\t\t\t\t// NOTE the type of multiVectorsIn is [][][]float32 (vs vectorsIn which is [][]float32),\n\t\t\t\t\t// so there are two similar loops here to handle the different types, if there is a simpler\n\t\t\t\t\t// way to handle this, feel free to change it\n\t\t\t\t\tfor j, w := range multiVectorsIn {\n\t\t\t\t\t\tif !targetVectorOrderMatches(i, j, targetVectors, target) {\n\t\t\t\t\t\t\treturn searchparams.NearVector{}, nil, fmt.Errorf(\"multivector target %s is not in the correct order\", target)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvectors[i+j] = w\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn searchparams.NearVector{}, nil, fmt.Errorf(\"could not handle type of near vector for target %s, got %v\", target, vectorPerTargetParsed)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\targs.Vectors = vectors\n\t}\n\n\treturn args, combination, nil\n}\n\nfunc targetVectorOrderMatches(i, j int, targetVectors []string, target string) bool {\n\treturn i+j < len(targetVectors) && targetVectors[i+j] == target\n}\n","sourceCodeStart":125,"sourceCodeEnd":156,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/handlers/graphql/local/common_filters/near_vector.go#L125-L156","documentation":"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.","triggerScenarios":"`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.","commonSituations":"JSON sent with wrong nesting for multi-vector collections (extra or missing bracket level); GraphQL variables serialized as strings; scalar passed instead of array.","solutions":["Check the printed type in the message and reshape the value to [float], [[float]] or [[[float]]] as appropriate.","For single-vector named collections use a flat array of numbers; for multi-vector use arrays of arrays of arrays.","Validate payload shape client-side before sending (see defense validationCode)."],"exampleFix":"// before\nvectorPerTarget: { title: 0.1 }\n// after\nvectorPerTarget: { title: [0.1] }","handlingStrategy":"validation","validationCode":"for (const [t, v] of Object.entries(vectorPerTarget)) {\n  const shape = shapeOf(v);\n  if (!['vec','vecList','multiVecList'].includes(shape)) throw new Error(`vectorPerTarget['${t}'] has invalid shape ${shape}`);\n}\nfunction shapeOf(v){\n  if(!Array.isArray(v)) return 'other';\n  if(typeof v[0]==='number') return 'vec';\n  if(Array.isArray(v[0]) && typeof v[0][0]==='number') return 'vecList';\n  if(Array.isArray(v[0]?.[0])) return 'multiVecList';\n  return 'other';\n}","typeGuard":"function isVectorShape(v) {\n  return Array.isArray(v) && (typeof v[0] === 'number' ||\n    (Array.isArray(v[0]) && typeof v[0][0] === 'number') ||\n    (Array.isArray(v[0]?.[0])));\n}","tryCatchPattern":"try {\n  await query();\n} catch (e) {\n  if (String(e).includes('could not handle type of near vector')) {\n    throw new UsageError('Reshape vectorPerTarget values to number[], number[][], or number[][][]');\n  }\n  throw e;\n}","preventionTips":["Validate vector payloads with a shape checker before every query.","Match nesting depth to the collection's vectorizer (single vs multi-vector).","Read the %v type in the error to identify the offending payload."],"tags":["graphql","vector-search","type-mismatch"],"backgroundTag":"invalid-parameter-type","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}