{"record":{"id":"b0dca53ae836b9a3","repo":"weaviate/weaviate","slug":"sort-objects-with-distances","errorCode":null,"errorMessage":"sort objects with distances","messagePattern":"sort objects with distances","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"adapters/repos/db/shard_read.go","lineNumber":977,"sourceCode":"\tlsmSorter, err := sorter.NewLSMSorter(s.store, s.index.getSchema.ReadOnlyClass,\n\t\tclassName, s.index.Config.InvertedSorterDisabled)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"sort object list\")\n\t}\n\tdocIDs, err := lsmSorter.Sort(ctx, limit, sort)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"sort object list\")\n\t}\n\treturn docIDs, nil\n}\n\nfunc (s *Shard) sortDocIDsAndDists(ctx context.Context, limit int, sort []filters.Sort,\n\tclassName schema.ClassName, docIDs []uint64, dists []float32,\n) ([]uint64, []float32, error) {\n\tlsmSorter, err := sorter.NewLSMSorter(s.store, s.index.getSchema.ReadOnlyClass,\n\t\tclassName, s.index.Config.InvertedSorterDisabled)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrap(err, \"sort objects with distances\")\n\t}\n\tsortedDocIDs, sortedDists, err := lsmSorter.SortDocIDsAndDists(ctx, limit, sort, docIDs, dists)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrap(err, \"sort objects with distances\")\n\t}\n\treturn sortedDocIDs, sortedDists, nil\n}\n\nfunc (s *Shard) buildAllowList(ctx context.Context, filters *filters.LocalFilter, addl additional.Properties) (helpers.AllowList, error) {\n\tlist, err := inverted.NewSearcher(s.index.logger, s.store, s.index.getSchema.ReadOnlyClass,\n\t\ts.propertyIndicesSnapshot(), s.index.classSearcher, s.index.getStopwordProvider(), s.versioner.Version(),\n\t\ts.isFallbackToSearchable, s.IsRangeableLocallyReady, s.tenant(), s.index.Config.QueryNestedRefLimit, s.bitmapFactory).\n\t\tWithTokenizationResolver(s.TokenizationFor).\n\t\tWithBatchedContainsEnabled(s.index.Config.QueryBatchedContainsEnabled).\n\t\tDocIDs(ctx, filters, addl, s.index.Config.ClassName)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"build inverted filter allow list\")\n\t}","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/shard_read.go#L959-L995","documentation":"Weaviate failed to create or use the LSM sorter used to re-sort vector-search results (doc IDs with their distances) by non-score properties. Shard.sortDocIDsAndDists wraps both sorter construction errors and the SortDocIDsAndDists execution error under this message. It only runs when a GraphQL/REST query combines nearVector-style search with a sort clause, so the underlying cause is always in the inner wrapped error.","triggerScenarios":"A query like Get{Class(nearVector:{...}, sort:[{path:\"price\"}])} where sorter.NewLSMSorter fails (e.g. class/property not readable from schema, inverted sorter disabled configuration mismatch) or lsmSorter.SortDocIDsAndDists fails while iterating LSM buckets for the sort properties.","commonSituations":"Sorting on a property that has no inverted index in the LSM store, schema read-only lookups failing mid-query, disk/IO problems on segment reads, or InvertedSorterDisabled configuration interacting badly with the requested sort.","solutions":["Read the inner wrapped error (errors.Unwrap / log output) to identify the actual sorter failure","Verify every property in the sort path exists on the class and is indexed (indexed: true)","Retry the query; if persistent, check disk health and LSM segment files for the shard","As a workaround, drop the sort clause from the vector search and sort client-side, or re-run as a filtered query without nearVector"],"exampleFix":"// before: sort over a non-indexed property\nsort: [{path: \"description\"}]\n// after: ensure the property is indexed in the collection schema\n{\"properties\":[{\"name\":\"description\",\"indexFilterable\":true,\"indexSearchable\":true}]}","handlingStrategy":"try-catch","validationCode":"// client-side: only send sort on properties known to be indexed\nconst prop = schema.classes.find(c=>c.class==='Article').properties.find(p=>p.name==='price');\nif (!prop || prop.indexFilterable === false) throw new Error('sort property not indexed');","typeGuard":null,"tryCatchPattern":"try {\n  const res = await weaviate.graphql.get().withClassName('Article').withNearVector({vector}).withSort([{path:['price']}]).do();\n} catch (e) {\n  if (String(e).includes('sort objects with distances')) {\n    // fallback: unsorted vector search, sort client-side\n  }\n}","preventionTips":["Keep sort properties indexed (indexFilterable: true)","Test sorted vector searches after schema migrations","Monitor disk health on storage nodes"],"tags":["weaviate","go","sort","vector-search","lsm"],"backgroundTag":"sort-query-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"}