weaviate/weaviate · error
distance vectors must have len 2
Error message
distance vectors must have len 2
What it means
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.
Source
Thrown at adapters/repos/db/vector/hnsw/distancer/geo_spatial.go:21
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
// \ V V / __/ (_| |\ V /| | (_| | || __/
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
// Copyright © 2016 - 2026 Weaviate B.V. All rights reserved.
//
// CONTACT: hello@weaviate.io
//
package distancer
import (
"fmt"
"math"
)
func geoDist(a, b []float32) (float32, error) {
if len(a) != 2 || len(b) != 2 {
return 0, fmt.Errorf("distance vectors must have len 2")
}
latA := a[0]
latB := b[0]
lonA := a[1]
lonB := b[1]
const R = float64(6371e3)
latARadian := float64(latA * math.Pi / 180)
latBRadian := float64(latB * math.Pi / 180)
deltaLatRadian := float64(latB-latA) * math.Pi / 180
deltaLonRadian := float64(lonB-lonA) * math.Pi / 180
A := math.Sin(deltaLatRadian/2)*math.Sin(deltaLatRadian/2) +
math.Cos(latARadian)*math.Cos(latBRadian)*math.Sin(deltaLonRadian/2)*math.Sin(deltaLonRadian/2)
C := 2 * math.Atan2(math.Sqrt(A), math.Sqrt(1-A))
View on GitHub (pinned to 75aa4b6d11)
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
Example fix
// before
{"nearGeo": {"latitude": 51.5}}
// after
{"nearGeo": {"latitude": 51.5, "longitude": -0.12, "maxDistance": 2000}} Defensive patterns
Strategy: validation
Validate before calling
func validGeo(coords []float32) bool { return len(coords) == 2 } Type guard
func isLatLon(v interface{}) ([]float32, bool) {
a, ok := v.([]float32)
return a, ok && len(a) == 2
} Try / catch
d, err := geoDist(a, b)
if err != nil {
return 0, fmt.Errorf("nearGeo needs exactly latitude+longitude: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- latitude must be set
- longitude must be set
- invalid arguments: GeoCoordinates in range must be set
- unknown datatype for aggregation type reference: ${dataType}
- tempVectorForIDWithViewThunk cannot be nil
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/23037fa484a6d537.
Report an issue: GitHub.