class_docstr: A component that routes documents to different connections based on the content of their fields.
class_docstr_tok: ["A","component","that","routes","documents","to","different","connections","based","on","the","content","of","their","fields","."]
docstr: Initialize the MetadataRouter.
  
  :param rules: A dictionary of rules that specify which edge to route a document to based on its metadata.
                The keys of the dictionary are the names of the output connections, and the values are dictionaries that
                follow the format 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"},
                      ],
                  },
                }
                ```
docstr_tok: ["Initialize","the","MetadataRouter",".",":","param","rules",":","A","dictionary","of","rules","that","specify","which","edge","to","route","a","document","to","based","on","its","metadata",".","The","keys","of","the","dictionary","are","the","names","of","the","output","connections",",","and","the","values","are","dictionaries","that","follow","the","format","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","''","}",",","]",",","}",",","}","``","`"]
code: def __init__(self, rules: Dict[str, Dict]):
      """
      Initialize the MetadataRouter.
  
      :param rules: A dictionary of rules that specify which edge to route a document to based on its metadata.
                    The keys of the dictionary are the names of the output connections, and the values are dictionaries that
                    follow the format 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"},
                          ],
                      },
                    }
                    ```
      """
      self.rules = rules
      component.set_output_types(
          self,
          unmatched=List[Document],
          **{edge: List[Document] for edge in rules},
      )
  
imports: from typing import Dict, List
  from haystack import component, Document
  from haystack.utils.filters import document_matches_filter, convert
label_desc: Use image node_id 1 to create a new MetadataRouter object  with example: obj = MetadataRouter(rules)