memoryscope.core.models.llama_index_rank_model

class memoryscope.core.models.llama_index_rank_model.LlamaIndexRankModel(*args, **kwargs)[源代码]

基类:BaseModel

The LlamaIndexRankModel class is designed to rerank documents according to their relevance to a provided query, utilizing the DashScope Rerank model. It transforms document lists and queries into a compatible format for ranking, manages the ranking process, and allocates rank scores to individual documents.

m_type: ModelEnum = 'rank_model'
__init__(*args, **kwargs)[源代码]
before_call(model_response: ModelResponse, **kwargs)[源代码]

Prepares necessary data before the ranking call by extracting the query and documents, ensuring they are valid, and initializing nodes with dummy scores.

参数:
  • model_response -- model response

  • **kwargs -- Keyword arguments containing 'query' and 'documents'.

after_call(model_response: ModelResponse, **kwargs) ModelResponse[源代码]

Processes the model response post-ranking, assigning calculated rank scores to each document based on their index in the original document list.

参数:
  • model_response (ModelResponse) -- The initial response from the ranking model.

  • **kwargs -- Additional keyword arguments (unused).

返回:

Updated response with rank scores assigned to documents.

返回类型:

ModelResponse

model_name: str
module_name: str
timeout: int
max_retries: int
retry_interval: float
kwargs_filter: bool
raise_exception: bool
context: MemoryscopeContext
kwargs: dict