memoryscope.core.models.llama_index_rank_model

class memoryscope.core.models.llama_index_rank_model.LlamaIndexRankModel(*args, **kwargs)[source]

Bases: 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)[source]
before_call(model_response: ModelResponse, **kwargs)[source]

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

Parameters:
  • model_response – model response

  • **kwargs – Keyword arguments containing ‘query’ and ‘documents’.

after_call(model_response: ModelResponse, **kwargs) ModelResponse[source]

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

Parameters:
  • model_response (ModelResponse) – The initial response from the ranking model.

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

Returns:

Updated response with rank scores assigned to documents.

Return type:

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