Bug fix: added deterministic sorting for sortby - #1397
JasonLi314 wants to merge 3 commits into
Conversation
Signed-off-by: Jason Li <47095666+JasonLi314@users.noreply.github.com>
Signed-off-by: Jason Li <47095666+JasonLi314@users.noreply.github.com>
|
Reviewers for this PR
Assigned automatically to the least-assigned members of the reviewer pools in |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe change makes ChangesSORTBY ordering
Sequence Diagram(s)sequenceDiagram
participant Client
participant FTSEARCH
participant MaybeAddIndexedContent
participant ApplySorting
Client->>FTSEARCH: Execute FT.SEARCH with SORTBY
FTSEARCH->>MaybeAddIndexedContent: Resolve content for sort target
MaybeAddIndexedContent-->>FTSEARCH: Return stored-field or score content
FTSEARCH->>ApplySorting: Sort matching documents
ApplySorting-->>FTSEARCH: Return direction-aware ordered results
FTSEARCH-->>Client: Return full or limited reply
Priority: ➖ Normal Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No merge-blocking regression is identified in the changed SORTBY behavior. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Signed-off-by: Jason Li <47095666+JasonLi314@users.noreply.github.com>
| bool is_numeric = | ||
| index_result.ok() && | ||
| index_result.value()->GetIndexerType() == indexes::IndexerType::kNumeric; | ||
| // Tied neighbors order by key, following the sort direction, so the result |
There was a problem hiding this comment.
lets trim AI generated comments.
| parameters.sortby_parameter->field == | ||
| vmsdk::ToStringView(parameters.score_as.get()); | ||
| if (parameters.sortby_parameter && !sort_by_vec_score) { | ||
| return results; |
There was a problem hiding this comment.
Fix looks correct . but this might cause performance to degrade for sort by queries and would force a main-thread GetContent per neighbor where it used to be fully index-served. Wondering if adding the sortby fields to the attributes list is the more efficient choice here.
Fixes #1353 item 8.
FT.SEARCH SORTBY ties (documents with equal sort values) have no tie-break, so their relative order depends on incidental retrieval order rather than the data. Two consequences: repeating the same query can return ties in a different order, and because the full-result path uses std::stable_sort while the LIMIT path uses std::partial_sort, a LIMITed reply is not a prefix of the unlimited one — paginating over ties yields duplicate or missing rows.
This adds a direction-following tie-break on the document key, making the comparator a total order so the result is a pure function of the data and query, and a LIMITed reply is a true prefix of the unlimited one.
Not a Redis-compatibility fix: RediSearch breaks ties differently. This is a determinism improvement, so it is ungated.