{"record":{"id":"23037fa484a6d537","repo":"weaviate/weaviate","slug":"distance-vectors-must-have-len-2","errorCode":null,"errorMessage":"distance vectors must have len 2","messagePattern":"distance vectors must have len 2","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/vector/hnsw/distancer/geo_spatial.go","lineNumber":21,"sourceCode":"// \\ \\ /\\ / / _ \\/ _` \\ \\ / / |/ _` | __/ _ \\\n//  \\ V  V /  __/ (_| |\\ V /| | (_| | ||  __/\n//   \\_/\\_/ \\___|\\__,_| \\_/ |_|\\__,_|\\__\\___|\n//\n//  Copyright © 2016 - 2026 Weaviate B.V. All rights reserved.\n//\n//  CONTACT: hello@weaviate.io\n//\n\npackage distancer\n\nimport (\n\t\"fmt\"\n\t\"math\"\n)\n\nfunc geoDist(a, b []float32) (float32, error) {\n\tif len(a) != 2 || len(b) != 2 {\n\t\treturn 0, fmt.Errorf(\"distance vectors must have len 2\")\n\t}\n\n\tlatA := a[0]\n\tlatB := b[0]\n\tlonA := a[1]\n\tlonB := b[1]\n\tconst R = float64(6371e3)\n\n\tlatARadian := float64(latA * math.Pi / 180)\n\tlatBRadian := float64(latB * math.Pi / 180)\n\tdeltaLatRadian := float64(latB-latA) * math.Pi / 180\n\tdeltaLonRadian := float64(lonB-lonA) * math.Pi / 180\n\n\tA := math.Sin(deltaLatRadian/2)*math.Sin(deltaLatRadian/2) +\n\t\tmath.Cos(latARadian)*math.Cos(latBRadian)*math.Sin(deltaLonRadian/2)*math.Sin(deltaLonRadian/2)\n\n\tC := 2 * math.Atan2(math.Sqrt(A), math.Sqrt(1-A))\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/vector/hnsw/distancer/geo_spatial.go#L3-L39","documentation":"geoDist validates that both operands of a geo-coordinate distance computation are 2-dimensional [lat, lon] pairs. If either vector is nil, empty, or has more than 2 elements it returns this error instead of panicking on index access. It is surfaced through Distance/SingleDist of the geo distancer.","triggerScenarios":"Using nearGeo with a malformed coordinates payload (missing latitude or longitude, or nested arrays); comparing vectors where the 'geo' property was not stored as exactly two floats; programmatic use of the geo distancer with arbitrary slices.","commonSituations":"GraphQL nearGeo query with geoCoordinates given only latitude; clients sending [lat,lon,alt] triplets; objects imported with null/empty geoCoordinates then queried; custom code calling the distancer package directly with wrong-shaped slices.","solutions":["Provide exactly {latitude, longitude} in nearGeo and in stored geoCoordinates properties","Validate the coordinate array length is 2 before invoking the distancer","Fix objects with missing/invalid geoCoordinates by re-importing with complete coordinates","Remove altitude/third elements from coordinate arrays"],"exampleFix":"// before\n{\"nearGeo\": {\"latitude\": 51.5}}\n// after\n{\"nearGeo\": {\"latitude\": 51.5, \"longitude\": -0.12, \"maxDistance\": 2000}}","handlingStrategy":"validation","validationCode":"func validGeo(coords []float32) bool { return len(coords) == 2 }","typeGuard":"func isLatLon(v interface{}) ([]float32, bool) {\n    a, ok := v.([]float32)\n    return a, ok && len(a) == 2\n}","tryCatchPattern":"d, err := geoDist(a, b)\nif err != nil {\n    return 0, fmt.Errorf(\"nearGeo needs exactly latitude+longitude: %w\", err)\n}","preventionTips":["Always send both latitude and longitude in nearGeo","Strip altitude from coordinate arrays","Backfill objects with missing geoCoordinates before geo queries","Validate geoCoordinates in your import pipeline"],"tags":["go","geo","validation","dimension-mismatch"],"backgroundTag":"vector-dimension-mismatch","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"}