The Temporal stage groups documents into time windows (hour, day, week, month, quarter, year) and computes aggregations per window. It can also detect drift between consecutive windows, flagging spikes or drops that exceed a threshold.
Stage Category : REDUCE (Groups results by time)Transformation : N documents → M time-window results (with optional drift detection)
When to Use
Use Case Description Trend analysis Track how metrics change over time Spike detection Flag windows where a metric jumps or drops significantly Content velocity Count new documents per day/week/month Temporal distribution Understand when content was created or modified
When NOT to Use
Scenario Recommended Alternative Simple counting aggregateFull time-series from database Aggregation API Grouping by non-time fields group_byLLM-based trend analysis summarize
Parameters
Parameter Type Default Description time_fieldstring Required Document field containing the timestamp windowstring Required Window granularity: hour, day, week, month, quarter, year aggregationsarray Required List of aggregation operations per window driftobject nullDrift detection configuration sort_orderstring "asc"Sort windows asc (oldest first) or desc (newest first) limitinteger nullMax number of windows to return include_documentsboolean falseInclude original documents in output
Aggregation Types
Type Field Required Description countNo Number of documents in window sumYes Sum of field values avgYes Average value minYes Minimum value maxYes Maximum value count_distinctYes Unique values count collect_distinctYes Gather unique values into list
Drift Detection
Drift detection compares a metric between consecutive windows and computes the percent change.
Parameter Type Default Description drift.enabledboolean falseEnable drift detection drift.metricstring Required if enabled Which aggregation alias to track drift.thresholdfloat nullPercent change to flag (e.g., 50.0 flags changes > 50%)
The stage parses timestamps automatically:
Format Example ISO 8601 "2026-04-01T10:30:00Z"ISO date "2026-04-01"Epoch seconds (int) 1743465600Epoch seconds (float) 1743465600.123
Documents with missing or unparseable timestamps are skipped (counted in num_documents_skipped).
Configuration Examples
Daily Trend Analysis
Spike Detection with Drift
Monthly Content Velocity
Quarterly Revenue Trends
Hourly Activity Monitoring
{
"stage_type" : "reduce" ,
"stage_id" : "temporal" ,
"parameters" : {
"time_field" : "created_at" ,
"window" : "day" ,
"aggregations" : [
{ "function" : "count" , "alias" : "posts_per_day" },
{ "function" : "avg" , "field" : "score" , "alias" : "avg_relevance" }
]
}
}
Output Schema
Window Results
{
"metadata" : {
"windows" : [
{
"window" : "2026-04-01" ,
"metrics" : {
"count" : 3 ,
"avg_score" : 0.85
}
},
{
"window" : "2026-04-02" ,
"metrics" : {
"count" : 1 ,
"avg_score" : 0.72
},
"drift" : {
"absolute_change" : -2 ,
"percent_change" : -66.67 ,
"flagged" : true
}
}
],
"num_windows" : 2 ,
"num_documents_in" : 4 ,
"num_documents_skipped" : 0 ,
"window_granularity" : "day"
}
}
Window Format Example hourYYYY-MM-DDTHH:00:002026-04-01T15:00:00dayYYYY-MM-DD2026-04-01weekYYYY-WNN2026-W14monthYYYY-MM2026-04quarterYYYY-QN2026-Q2yearYYYY2026
Metric Value Latency 5-50ms Memory O(windows x aggregations) Cost Free Scalability Efficient for large result sets
Common Pipeline Patterns
Search + Temporal Analysis
[
{
"stage_type" : "filter" ,
"stage_id" : "feature_search" ,
"parameters" : {
"searches" : [
{
"feature_uri" : "mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding" ,
"query" : "{{INPUT.query}}" ,
"top_k" : 500
}
],
"final_top_k" : 500
}
},
{
"stage_type" : "reduce" ,
"stage_id" : "temporal" ,
"parameters" : {
"time_field" : "created_at" ,
"window" : "day" ,
"aggregations" : [
{ "function" : "count" , "alias" : "matches_per_day" },
{ "function" : "avg" , "field" : "score" , "alias" : "avg_relevance" }
],
"drift" : {
"enabled" : true ,
"metric" : "matches_per_day" ,
"threshold" : 100.0
}
}
}
]
Brand Monitoring with Spike Detection
[
{
"stage_type" : "filter" ,
"stage_id" : "feature_search" ,
"parameters" : {
"searches" : [
{
"feature_uri" : "mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding" ,
"query" : "{{INPUT.brand_name}}" ,
"top_k" : 1000
}
],
"final_top_k" : 1000
}
},
{
"stage_type" : "enrich" ,
"stage_id" : "llm_enrich" ,
"parameters" : {
"provider" : "google" ,
"model_name" : "gemini-2.5-flash-lite" ,
"prompt" : "Classify sentiment as positive, neutral, or negative: {{DOC.content}}" ,
"output_field" : "sentiment"
}
},
{
"stage_type" : "reduce" ,
"stage_id" : "temporal" ,
"parameters" : {
"time_field" : "published_at" ,
"window" : "week" ,
"aggregations" : [
{ "function" : "count" , "alias" : "mentions" },
{ "function" : "count_distinct" , "field" : "sentiment" , "alias" : "sentiment_spread" }
],
"drift" : {
"enabled" : true ,
"metric" : "mentions" ,
"threshold" : 50.0
}
}
}
]
Error Handling
Error Behavior Missing timestamp field Document skipped Unparseable timestamp Document skipped Non-numeric field for sum/avg Document skipped for that aggregation Empty results 0 windows returned Unknown aggregation Returns null
Aggregate - Statistical aggregations without time grouping
Group By - Group documents by any field
Sample - Statistical sampling