weaviate/weaviate · error

sort objects with distances

Error message

sort objects with distances

What it means

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.

Source

Thrown at adapters/repos/db/shard_read.go:977

	lsmSorter, err := sorter.NewLSMSorter(s.store, s.index.getSchema.ReadOnlyClass,
		className, s.index.Config.InvertedSorterDisabled)
	if err != nil {
		return nil, errors.Wrap(err, "sort object list")
	}
	docIDs, err := lsmSorter.Sort(ctx, limit, sort)
	if err != nil {
		return nil, errors.Wrap(err, "sort object list")
	}
	return docIDs, nil
}

func (s *Shard) sortDocIDsAndDists(ctx context.Context, limit int, sort []filters.Sort,
	className schema.ClassName, docIDs []uint64, dists []float32,
) ([]uint64, []float32, error) {
	lsmSorter, err := sorter.NewLSMSorter(s.store, s.index.getSchema.ReadOnlyClass,
		className, s.index.Config.InvertedSorterDisabled)
	if err != nil {
		return nil, nil, errors.Wrap(err, "sort objects with distances")
	}
	sortedDocIDs, sortedDists, err := lsmSorter.SortDocIDsAndDists(ctx, limit, sort, docIDs, dists)
	if err != nil {
		return nil, nil, errors.Wrap(err, "sort objects with distances")
	}
	return sortedDocIDs, sortedDists, nil
}

func (s *Shard) buildAllowList(ctx context.Context, filters *filters.LocalFilter, addl additional.Properties) (helpers.AllowList, error) {
	list, err := inverted.NewSearcher(s.index.logger, s.store, s.index.getSchema.ReadOnlyClass,
		s.propertyIndicesSnapshot(), s.index.classSearcher, s.index.getStopwordProvider(), s.versioner.Version(),
		s.isFallbackToSearchable, s.IsRangeableLocallyReady, s.tenant(), s.index.Config.QueryNestedRefLimit, s.bitmapFactory).
		WithTokenizationResolver(s.TokenizationFor).
		WithBatchedContainsEnabled(s.index.Config.QueryBatchedContainsEnabled).
		DocIDs(ctx, filters, addl, s.index.Config.ClassName)
	if err != nil {
		return nil, errors.Wrap(err, "build inverted filter allow list")
	}

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Read the inner wrapped error (errors.Unwrap / log output) to identify the actual sorter failure
  2. Verify every property in the sort path exists on the class and is indexed (indexed: true)
  3. Retry the query; if persistent, check disk health and LSM segment files for the shard
  4. As a workaround, drop the sort clause from the vector search and sort client-side, or re-run as a filtered query without nearVector

Example fix

// before: sort over a non-indexed property
sort: [{path: "description"}]
// after: ensure the property is indexed in the collection schema
{"properties":[{"name":"description","indexFilterable":true,"indexSearchable":true}]}
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side: only send sort on properties known to be indexed
const prop = schema.classes.find(c=>c.class==='Article').properties.find(p=>p.name==='price');
if (!prop || prop.indexFilterable === false) throw new Error('sort property not indexed');

Try / catch

try {
  const res = await weaviate.graphql.get().withClassName('Article').withNearVector({vector}).withSort([{path:['price']}]).do();
} catch (e) {
  if (String(e).includes('sort objects with distances')) {
    // fallback: unsorted vector search, sort client-side
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/b0dca53ae836b9a3. Report an issue: GitHub.