Overview
TheSource trait defines how candidate content is fetched from various retrieval systems. Sources run in parallel and their results are combined before continuing through the pipeline.
Trait Definition
Type Parameters
generic
The query type that contains request context and parametersConstraints:
Clone + Send + Sync + 'staticgeneric
The candidate type that represents a single content itemConstraints:
Clone + Send + Sync + 'staticMethods
enable
fn
get_candidates
async fn
name
fn
Returns a stable name for logging and metrics
&'static str
A short type name derived from the implementing struct. Default implementation uses reflection to extract the struct name.
Example Implementation
Here’s a real example from the X For You feed that retrieves candidates from the Phoenix recommendation system:Usage Notes
- Multiple sources can be configured to run in parallel
- Results from all enabled sources are combined before hydration
- Sources should return candidates quickly; expensive operations should be deferred to hydrators
- The
enablemethod allows dynamic source selection based on query parameters - Error messages should be descriptive for debugging and monitoring
See Also
- Hydrator - Enriches candidates with additional data
- Filter - Removes candidates based on criteria
- Candidate Pipeline Architecture - Overview of the pipeline stages