weaviate/weaviate · error
failed to search for nearest neighbors
Error message
failed to search for nearest neighbors
What it means
HFresh.RNGSelect performs an RNG-based neighbor selection starting from a centroid search (h.Centroids.Search) for the query vector; this error wraps a failure of that underlying nearest-centroid search. Without the candidate centroid list, RNG selection cannot proceed, so add, ensureInitialPosting, and doReassign all fail.
Source
Thrown at adapters/repos/db/vector/hfresh/rng.go:28
//
package hfresh
import (
"github.com/pkg/errors"
)
// RNGSelect performs a Relative Neighborhood Graph selection to determine
// the postings where the vector should be assigned to.
// It performs a search to find candidate postings, then iteratively selects
// postings that are not too close to already selected ones based on the RNGFactor.
// If `reassignedFromID` is non-zero, the function will abort and return false
// if one of the selected postings is equal to `reassignedFromID`.
func (h *HFresh) RNGSelect(query []float32, reassignedFromID uint64) (*ResultSet, bool, error) {
replicas := NewResultSet(int(h.replicas))
candidates, err := h.Centroids.Search(query, h.config.InternalPostingCandidates, nil)
if err != nil {
return nil, false, errors.Wrap(err, "failed to search for nearest neighbors")
}
for cID, cDistance := range candidates.Iter() {
cCenter, err := h.Centroids.Get(cID)
if err != nil {
return nil, false, errors.Wrap(err, "failed to get candidate centroid")
}
tooClose := false
for _, r := range replicas.data {
rCenter, err := h.Centroids.Get(r.ID)
if err != nil {
return nil, false, errors.Wrap(err, "failed to get replica centroid")
}
centerDist, err := h.distancer.DistanceBetweenVectors(cCenter.Uncompressed, rCenter.Uncompressed)
if err != nil {
return nil, false, errors.Wrapf(err, "failed to compute distance for edge %d -> %d", cID, r.ID)
}View on GitHub (pinned to 75aa4b6d11)
Solutions
- Inspect the wrapped inner error from Centroids.Search for the root cause.
- Verify centroid store integrity and that vector dimensions match the collection config.
- Retry after confirming the shard is healthy; restore from backup if centroids are corrupt.
- Avoid shutting down the node while background add/reassign operations run.
Defensive patterns
Strategy: retry
Validate before calling
// validate query dimensionality against collection config before search
if len(query) != expectedDims {
return fmt.Errorf("query dims %d != index dims %d", len(query), expectedDims)
} Try / catch
rs, ok, err := h.RNGSelect(query, reassignedFromID)
if err != nil {
if errors.Is(err, context.Canceled) { return } // shutdown race
logger.Warnf("RNG select failed, will retry: %v", err)
retryOrQueueForLater(query)
} Prevention
- Keep vector dimensions consistent with collection schema.
- Avoid shutdown while background adds/reassigns run.
- Verify centroid store integrity after crashes/restores.
- Back up shards; rebuild index if centroids are corrupt.
When it happens
Trigger: RNGSelect(query, reassignedFromID) where h.Centroids.Search(query, h.config.InternalPostingCandidates, nil) returns an error — e.g. corrupted or unreadable centroid store, shutdown during search, or an empty/failed search backend.
Common situations: Shard corruption affecting centroids, searches during node shutdown, dimension mismatches or internal centroid index failures after restore.
Related errors
- failed to enqueue reassign for vector %d after merge
- failed to merge posting %d with candidate %d
- failed to set size of filtered posting %d
- failed to get existing posting metadata for posting %d
- failed to get posting metadata for %d
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/499d773b905ea744.
Report an issue: GitHub.