Sort: Record<string, SortDirection> | {
    $vector: number[];
} | {
    $vectorize: string;
}

Specifies the sort criteria for selecting documents.

If you want stricter type-checking and full auto-complete, see StrictSort.

Can use 1/-1 for ascending/descending, or $vector for sorting by vector distance.

See SortDirection for all possible sort values.

NB. The order of the fields in the sort option is significant—fields are sorted in the order they are listed.

Type declaration

  • $vector: number[]

Type declaration

  • $vectorize: string

Example

// Sort by name in ascending order, then by age in descending order
const sort1: Sort = {
  name: 1,
  age: -1,
}

// Sort by vector distance
const sort2: Sort = {
  $vector: [0.23, 0.38, 0.27, 0.91, 0.21],
}

See

  • StrictSort
  • SortDirection