class_docstr: Ranks Documents based on their similarity to the query.
  It uses a pre-trained cross-encoder model (from the Hugging Face Hub) to embed the query and the Documents.
  
  Usage example:
  ```
  from haystack import Document
  from haystack.components.rankers import TransformersSimilarityRanker
  
  ranker = TransformersSimilarityRanker()
  docs = [Document(content="Paris"), Document(content="Berlin")]
  query = "City in Germany"
  output = ranker.run(query=query, documents=docs)
  docs = output["documents"]
  assert len(docs) == 2
  assert docs[0].content == "Berlin"
  ```
class_docstr_tok: ["Ranks","Documents","based","on","their","similarity","to","the","query",".","It","uses","a","pre-trained","cross-encoder","model","(","from","the","Hugging","Face","Hub",")","to","embed","the","query","and","the","Documents",".","Usage","example",":","``","`","from","haystack","import","Document","from","haystack.components.rankers","import","TransformersSimilarityRanker","ranker","=","TransformersSimilarityRanker","(",")","docs","=","[","Document","(","content=","''","Paris","''",")",",","Document","(","content=","''","Berlin","''",")","]","query","=","``","City","in","Germany","''","output","=","ranker.run","(","query=query",",","documents=docs",")","docs","=","output","[","``","documents","''","]","assert","len","(","docs",")","==","2","assert","docs","[","0","]",".content","==","``","Berlin","''","``","`"]
docstr: Creates an instance of TransformersSimilarityRanker.
  
  :param model: The name or path of a pre-trained cross-encoder model
      from the Hugging Face Hub.
  :param device: The torch device (for example, cuda:0, cpu, mps) to which you want to limit model inference.
  :param token: The API token used to download private models from Hugging Face.
      If this parameter is set to `True`, the token generated when running
      `transformers-cli login` (stored in ~/.huggingface) is used.
  :param top_k: The maximum number of Documents to return per query.
  :param meta_fields_to_embed: List of meta fields that should be embedded along with the Document content.
  :param embedding_separator: Separator used to concatenate the meta fields to the Document content.
  :param scale_score: Whether the raw logit predictions will be scaled using a Sigmoid activation function.
      Set this to False if you do not want any scaling of the raw logit predictions.
  :param calibration_factor: Factor used for calibrating probabilities calculated by
      `sigmoid(logits * calibration_factor)`. This is only used if `scale_score` is set to True.
  :param score_threshold: If provided only returns documents with a score above this threshold.
  :param model_kwargs: Additional keyword arguments passed to `AutoModelForSequenceClassification.from_pretrained`
      when loading the model specified in `model`. For details on what kwargs you can pass,
      see the model's documentation.
docstr_tok: ["Creates","an","instance","of","TransformersSimilarityRanker",".",":","param","model",":","The","name","or","path","of","a","pre-trained","cross-encoder","model","from","the","Hugging","Face","Hub",".",":","param","device",":","The","torch","device","(","for","example",",","cuda:0",",","cpu",",","mps",")","to","which","you","want","to","limit","model","inference",".",":","param","token",":","The","API","token","used","to","download","private","models","from","Hugging","Face",".","If","this","parameter","is","set","to","`","True","`",",","the","token","generated","when","running","`","transformers-cli","login","`","(","stored","in","~\/.huggingface",")","is","used",".",":","param","top_k",":","The","maximum","number","of","Documents","to","return","per","query",".",":","param","meta_fields_to_embed",":","List","of","meta","fields","that","should","be","embedded","along","with","the","Document","content",".",":","param","embedding_separator",":","Separator","used","to","concatenate","the","meta","fields","to","the","Document","content",".",":","param","scale_score",":","Whether","the","raw","logit","predictions","will","be","scaled","using","a","Sigmoid","activation","function",".","Set","this","to","False","if","you","do","not","want","any","scaling","of","the","raw","logit","predictions",".",":","param","calibration_factor",":","Factor","used","for","calibrating","probabilities","calculated","by","`","sigmoid","(","logits","*","calibration_factor",")","`",".","This","is","only","used","if","`","scale_score","`","is","set","to","True",".",":","param","score_threshold",":","If","provided","only","returns","documents","with","a","score","above","this","threshold",".",":","param","model_kwargs",":","Additional","keyword","arguments","passed","to","`","AutoModelForSequenceClassification.from_pretrained","`","when","loading","the","model","specified","in","`","model","`",".","For","details","on","what","kwargs","you","can","pass",",","see","the","model","'s","documentation","."]
code: def __init__(
      self,
      model: Union[str, Path] = "cross-encoder/ms-marco-MiniLM-L-6-v2",
      device: Optional[str] = "cpu",
      token: Union[bool, str, None] = None,
      top_k: int = 10,
      meta_fields_to_embed: Optional[List[str]] = None,
      embedding_separator: str = "\n",
      scale_score: bool = True,
      calibration_factor: Optional[float] = 1.0,
      score_threshold: Optional[float] = None,
      model_kwargs: Optional[Dict[str, Any]] = None,
  ):
      """
      Creates an instance of TransformersSimilarityRanker.
  
      :param model: The name or path of a pre-trained cross-encoder model
          from the Hugging Face Hub.
      :param device: The torch device (for example, cuda:0, cpu, mps) to which you want to limit model inference.
      :param token: The API token used to download private models from Hugging Face.
          If this parameter is set to `True`, the token generated when running
          `transformers-cli login` (stored in ~/.huggingface) is used.
      :param top_k: The maximum number of Documents to return per query.
      :param meta_fields_to_embed: List of meta fields that should be embedded along with the Document content.
      :param embedding_separator: Separator used to concatenate the meta fields to the Document content.
      :param scale_score: Whether the raw logit predictions will be scaled using a Sigmoid activation function.
          Set this to False if you do not want any scaling of the raw logit predictions.
      :param calibration_factor: Factor used for calibrating probabilities calculated by
          `sigmoid(logits * calibration_factor)`. This is only used if `scale_score` is set to True.
      :param score_threshold: If provided only returns documents with a score above this threshold.
      :param model_kwargs: Additional keyword arguments passed to `AutoModelForSequenceClassification.from_pretrained`
          when loading the model specified in `model`. For details on what kwargs you can pass,
          see the model's documentation.
      """
      torch_and_transformers_import.check()
  
      self.model = model
      if top_k <= 0:
          raise ValueError(f"top_k must be > 0, but got {top_k}")
      self.top_k = top_k
      self.device = device
      self.token = token
      self._model = None
      self.tokenizer = None
      self.meta_fields_to_embed = meta_fields_to_embed or []
      self.embedding_separator = embedding_separator
      self.scale_score = scale_score
      self.calibration_factor = calibration_factor
      if self.scale_score and self.calibration_factor is None:
          raise ValueError(
              f"scale_score is True so calibration_factor must be provided, but got {calibration_factor}"
          )
      self.score_threshold = score_threshold
      self.model_kwargs = model_kwargs or {}
  
file_path: haystack/haystack/components/rankers/transformers_similarity.py
imports: import logging
  from pathlib import Path
  from typing import List, Union, Dict, Any, Optional
  from haystack import ComponentError, Document, component, default_to_dict, default_from_dict
  from haystack.lazy_imports import LazyImport
  from haystack.utils import get_device
label_desc: Use image node_id 1 to create a new TransformersSimilarityRanker object  with example: obj = TransformersSimilarityRanker(model, device, token, top_k, meta_fields_to_embed, embedding_separator, scale_score, calibration_factor, score_threshold, model_kwargs)