MetaFieldRanker
Ranks Documents based on the value of their specific meta field.
Basic Information
- Type:
haystack_integrations.rankers.meta_field.MetaFieldRanker
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | Documents to be ranked. | |
| top_k | Optional[int] | None | The maximum number of Documents to return per query. If not provided, the top_k provided at initialization time is used. |
| weight | Optional[float] | None | In range [0,1]. 0 disables ranking by a meta field. 0.5 ranking from previous component and based on meta field have the same weight. 1 ranking by a meta field only. If not provided, the weight provided at initialization time is used. |
| ranking_mode | Optional[Literal['reciprocal_rank_fusion', 'linear_score']] | None | (optional) The mode used to combine the Retriever's and Ranker's scores. Possible values are 'reciprocal_rank_fusion' (default) and 'linear_score'. Use the 'score' mode only with Retrievers or Rankers that return a score in range [0,1]. If not provided, the ranking_mode provided at initialization time is used. |
| sort_order | Optional[Literal['ascending', 'descending']] | None | Whether to sort the meta field by ascending or descending order. Possible values are descending (default) and ascending. If not provided, the sort_order provided at initialization time is used. |
| missing_meta | Optional[Literal['drop', 'top', 'bottom']] | None | What to do with documents that are missing the sorting metadata field. Possible values are: - 'drop' will drop the documents entirely. - 'top' will place the documents at the top of the metadata-sorted list (regardless of 'ascending' or 'descending'). - 'bottom' will place the documents at the bottom of metadata-sorted list (regardless of 'ascending' or 'descending'). If not provided, the missing_meta provided at initialization time is used. |
| meta_value_type | Optional[Literal['float', 'int', 'date']] | None | Parse the meta value into the data type specified before sorting. This will only work if all meta values stored under meta_field in the provided documents are strings. For example, if we specified meta_value_type="date" then for the meta value "date": "2015-02-01" we would parse the string into a datetime object and then sort the documents by date. The available options are: -'float' will parse the meta values into floats. -'int' will parse the meta values into integers. -'date' will parse the meta values into datetime objects. -'None' (default) will do no parsing. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A dictionary with the following keys: - documents: List of Documents sorted by the specified meta field. |
Overview
Work in Progress
Bear with us while we're working on adding pipeline examples and most common components connections.
Ranks Documents based on the value of their specific meta field.
The ranking can be performed in descending order or ascending order.
Usage example:
from haystack import Document
from haystack.components.rankers import MetaFieldRanker
ranker = MetaFieldRanker(meta_field="rating")
docs = [
Document(content="Paris", meta={"rating": 1.3}),
Document(content="Berlin", meta={"rating": 0.7}),
Document(content="Barcelona", meta={"rating": 2.1}),
]
output = ranker.run(documents=docs)
docs = output["documents"]
assert docs[0].content == "Barcelona"
Usage Example
components:
MetaFieldRanker:
type: components.rankers.meta_field.MetaFieldRanker
init_parameters:
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| meta_field | str | The name of the meta field to rank by. | |
| weight | float | 1 | In range [0,1]. 0 disables ranking by a meta field. 0.5 ranking from previous component and based on meta field have the same weight. 1 ranking by a meta field only. |
| top_k | Optional[int] | None | The maximum number of Documents to return per query. If not provided, the Ranker returns all documents it receives in the new ranking order. |
| ranking_mode | Literal['reciprocal_rank_fusion', 'linear_score'] | reciprocal_rank_fusion | The mode used to combine the Retriever's and Ranker's scores. Possible values are 'reciprocal_rank_fusion' (default) and 'linear_score'. Use the 'linear_score' mode only with Retrievers or Rankers that return a score in range [0,1]. |
| sort_order | Literal['ascending', 'descending'] | descending | Whether to sort the meta field by ascending or descending order. Possible values are descending (default) and ascending. |
| missing_meta | Literal['drop', 'top', 'bottom'] | bottom | What to do with documents that are missing the sorting metadata field. Possible values are: - 'drop' will drop the documents entirely. - 'top' will place the documents at the top of the metadata-sorted list (regardless of 'ascending' or 'descending'). - 'bottom' will place the documents at the bottom of metadata-sorted list (regardless of 'ascending' or 'descending'). |
| meta_value_type | Optional[Literal['float', 'int', 'date']] | None | Parse the meta value into the data type specified before sorting. This will only work if all meta values stored under meta_field in the provided documents are strings. For example, if we specified meta_value_type="date" then for the meta value "date": "2015-02-01" we would parse the string into a datetime object and then sort the documents by date. The available options are: - 'float' will parse the meta values into floats. - 'int' will parse the meta values into integers. - 'date' will parse the meta values into datetime objects. - 'None' (default) will do no parsing. |
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] | Documents to be ranked. | |
| top_k | Optional[int] | None | The maximum number of Documents to return per query. If not provided, the top_k provided at initialization time is used. |
| weight | Optional[float] | None | In range [0,1]. 0 disables ranking by a meta field. 0.5 ranking from previous component and based on meta field have the same weight. 1 ranking by a meta field only. If not provided, the weight provided at initialization time is used. |
| ranking_mode | Optional[Literal['reciprocal_rank_fusion', 'linear_score']] | None | (optional) The mode used to combine the Retriever's and Ranker's scores. Possible values are 'reciprocal_rank_fusion' (default) and 'linear_score'. Use the 'score' mode only with Retrievers or Rankers that return a score in range [0,1]. If not provided, the ranking_mode provided at initialization time is used. |
| sort_order | Optional[Literal['ascending', 'descending']] | None | Whether to sort the meta field by ascending or descending order. Possible values are descending (default) and ascending. If not provided, the sort_order provided at initialization time is used. |
| missing_meta | Optional[Literal['drop', 'top', 'bottom']] | None | What to do with documents that are missing the sorting metadata field. Possible values are: - 'drop' will drop the documents entirely. - 'top' will place the documents at the top of the metadata-sorted list (regardless of 'ascending' or 'descending'). - 'bottom' will place the documents at the bottom of metadata-sorted list (regardless of 'ascending' or 'descending'). If not provided, the missing_meta provided at initialization time is used. |
| meta_value_type | Optional[Literal['float', 'int', 'date']] | None | Parse the meta value into the data type specified before sorting. This will only work if all meta values stored under meta_field in the provided documents are strings. For example, if we specified meta_value_type="date" then for the meta value "date": "2015-02-01" we would parse the string into a datetime object and then sort the documents by date. The available options are: -'float' will parse the meta values into floats. -'int' will parse the meta values into integers. -'date' will parse the meta values into datetime objects. -'None' (default) will do no parsing. |
Was this page helpful?