{"record":{"id":"499d773b905ea744","repo":"weaviate/weaviate","slug":"failed-to-search-for-nearest-neighbors","errorCode":null,"errorMessage":"failed to search for nearest neighbors","messagePattern":"failed to search for nearest neighbors","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/vector/hfresh/rng.go","lineNumber":28,"sourceCode":"//\n\npackage hfresh\n\nimport (\n\t\"github.com/pkg/errors\"\n)\n\n// RNGSelect performs a Relative Neighborhood Graph selection to determine\n// the postings where the vector should be assigned to.\n// It performs a search to find candidate postings, then iteratively selects\n// postings that are not too close to already selected ones based on the RNGFactor.\n// If `reassignedFromID` is non-zero, the function will abort and return false\n// if one of the selected postings is equal to `reassignedFromID`.\nfunc (h *HFresh) RNGSelect(query []float32, reassignedFromID uint64) (*ResultSet, bool, error) {\n\treplicas := NewResultSet(int(h.replicas))\n\tcandidates, err := h.Centroids.Search(query, h.config.InternalPostingCandidates, nil)\n\tif err != nil {\n\t\treturn nil, false, errors.Wrap(err, \"failed to search for nearest neighbors\")\n\t}\n\n\tfor cID, cDistance := range candidates.Iter() {\n\t\tcCenter, err := h.Centroids.Get(cID)\n\t\tif err != nil {\n\t\t\treturn nil, false, errors.Wrap(err, \"failed to get candidate centroid\")\n\t\t}\n\n\t\ttooClose := false\n\t\tfor _, r := range replicas.data {\n\t\t\trCenter, err := h.Centroids.Get(r.ID)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, false, errors.Wrap(err, \"failed to get replica centroid\")\n\t\t\t}\n\t\t\tcenterDist, err := h.distancer.DistanceBetweenVectors(cCenter.Uncompressed, rCenter.Uncompressed)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, false, errors.Wrapf(err, \"failed to compute distance for edge %d -> %d\", cID, r.ID)\n\t\t\t}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/vector/hfresh/rng.go#L10-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"Shard corruption affecting centroids, searches during node shutdown, dimension mismatches or internal centroid index failures after restore.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// validate query dimensionality against collection config before search\nif len(query) != expectedDims {\n    return fmt.Errorf(\"query dims %d != index dims %d\", len(query), expectedDims)\n}","typeGuard":null,"tryCatchPattern":"rs, ok, err := h.RNGSelect(query, reassignedFromID)\nif err != nil {\n    if errors.Is(err, context.Canceled) { return } // shutdown race\n    logger.Warnf(\"RNG select failed, will retry: %v\", err)\n    retryOrQueueForLater(query)\n}","preventionTips":["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."],"tags":["go","vector-index","hfresh","centroid-search"],"backgroundTag":"nearest-neighbor-search-failed","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"}