The Sort Relevance stage reorders documents based on their relevance scores from previous stages. This is useful when documents have been modified or filtered and need to be re-sorted by their original search scores.
Stage Category : SORT (Reorders documents)Transformation : N documents → N documents (reordered by relevance)
When to Use
Use Case Description Post-filter sorting Re-sort after structured_filter removes documents Score normalization Apply consistent sorting after multi-stage processing Restoring order Return to relevance order after other sort operations Combining scores Sort by combined scores from multiple sources
When NOT to Use
Scenario Recommended Alternative Sorting by metadata field sort_by_fieldNeural re-scoring rerankResults already sorted Skip this stage Diversifying results mmr
Parameters
Parameter Type Default Description score_fieldstring scoreField containing relevance score orderstring descSort order: desc (highest first) or asc normalizeboolean falseNormalize scores to 0-1 range
Configuration Examples
Basic Relevance Sort
Custom Score Field
Normalized Scores
Ascending Order
{
"stage_type" : "sort" ,
"stage_id" : "sort_relevance" ,
"parameters" : {
"order" : "desc"
}
}
How It Works
Extract Scores : Read the score field from each document
Sort : Order documents by score (descending by default)
Optionally Normalize : Scale scores to 0-1 range
Return : Documents in new order
Output Schema
{
"document_id" : "doc_123" ,
"content" : "Document content..." ,
"score" : 0.95 ,
"sort_relevance" : {
"original_position" : 3 ,
"new_position" : 1 ,
"normalized_score" : 1.0
}
}
Metric Value Latency < 5ms Memory O(N) Cost Free Complexity O(N log N)
Common Pipeline Patterns
Search + Filter + Re-sort
[
{
"stage_type" : "filter" ,
"stage_id" : "semantic_search" ,
"parameters" : {
"query" : "{{INPUT.query}}" ,
"vector_index" : "text_extractor_v1_embedding" ,
"top_k" : 100
}
},
{
"stage_type" : "filter" ,
"stage_id" : "structured_filter" ,
"parameters" : {
"conditions" : {
"field" : "metadata.status" ,
"operator" : "eq" ,
"value" : "published"
}
}
},
{
"stage_type" : "sort" ,
"stage_id" : "sort_relevance" ,
"parameters" : {
"order" : "desc"
}
}
]
Multi-Stage with Score Normalization
[
{
"stage_type" : "filter" ,
"stage_id" : "hybrid_search" ,
"parameters" : {
"query" : "{{INPUT.query}}" ,
"vector_index" : "text_extractor_v1_embedding" ,
"top_k" : 50
}
},
{
"stage_type" : "apply" ,
"stage_id" : "llm_enrichment" ,
"parameters" : {
"model" : "gpt-4o-mini" ,
"prompt" : "Extract key topics" ,
"output_field" : "topics"
}
},
{
"stage_type" : "sort" ,
"stage_id" : "sort_relevance" ,
"parameters" : {
"normalize" : true
}
}
]
Comparison with Other Sort Stages
Stage Purpose Score Source sort_relevanceRelevance scores Search/fusion scores sort_by_fieldMetadata values Any document field rerankNeural re-scoring Cross-encoder model mmrDiversity Relevance + diversity
Error Handling
Error Behavior Missing score field Use 0 as default Non-numeric score Move to end Empty input Return empty Equal scores Maintain original order