MetadataRouter
Routes documents or byte streams to different connections based on their metadata fields.
Basic Information
- Type:
haystack_integrations.routers.metadata_router.MetadataRouter
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A list of documents to route. | |
| byte_streams | List[ByteStream] | A list of byte streams to route. |
Outputs
| Parameter | Type | Default | Description |
|---|
Overview
Bear with us while we're working on adding pipeline examples and most common components connections.
Routes documents or byte streams to different connections based on their metadata fields.
Specify the routing rules in the init method.
If a document or byte stream does not match any of the rules, it's routed to a connection named "unmatched".
The component can handle both Document objects and ByteStream objects. Use the output_type parameter to specify which type you want to route.
Usage Example
components:
MetadataRouter:
type: components.routers.metadata_router.MetadataRouter
init_parameters:
output_type: documents # or byte_streams
rules:
edge_1:
operator: AND
conditions:
- field: meta.created_at
operator: ">="
value: "2023-01-01"
- field: meta.created_at
operator: "<"
value: "2023-04-01"
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| rules | Dict[str, Dict] | A dictionary defining how to route documents or byte streams to output connections based on their metadata. Keys are output connection names, and values are dictionaries of filtering expressions in Haystack. For example: python { "edge_1": { "operator": "AND", "conditions": [ {"field": "meta.created_at", "operator": ">=", "value": "2023-01-01"}, {"field": "meta.created_at", "operator": "<", "value": "2023-04-01"}, ], }, "edge_2": { "operator": "AND", "conditions": [ {"field": "meta.created_at", "operator": ">=", "value": "2023-04-01"}, {"field": "meta.created_at", "operator": "<", "value": "2023-07-01"}, ], }, "edge_3": { "operator": "AND", "conditions": [ {"field": "meta.created_at", "operator": ">=", "value": "2023-07-01"}, {"field": "meta.created_at", "operator": "<", "value": "2023-10-01"}, ], }, "edge_4": { "operator": "AND", "conditions": [ {"field": "meta.created_at", "operator": ">=", "value": "2023-10-01"}, {"field": "meta.created_at", "operator": "<", "value": "2024-01-01"}, ], }, } | |
| output_type | Optional[str] | documents | The type of objects to route. Can be documents or byte_streams. If not specified, defaults to documents for backward compatibility. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A list of documents to route. | |
| byte_streams | List[ByteStream] | A list of byte streams to route. |
Was this page helpful?