Skip to main content

DashScopeRerank

DashScopeRerank offers the GTE-Rerank series of text rerank models developed by Alibaba Tongyi Lab. You can integrate these models using the LlamaIndex framework to perform high-quality text retrieval and sorting.

Get started

Prerequisites

pip install llama-index-core
pip install llama-index-postprocessor-dashscope-rerank

Sample code

Set the API key.
export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
from llama_index.core.data_structs import Node
from llama_index.core.schema import NodeWithScore
from llama_index.postprocessor.dashscope_rerank import DashScopeRerank

nodes = [
    NodeWithScore(node=Node(text="text1"), score=0.7),
    NodeWithScore(node=Node(text="text2"), score=0.8),
]

dashscope_rerank = DashScopeRerank(top_n=5)
results = dashscope_rerank.postprocess_nodes(nodes, query_str="<user query>")
for res in results:
    print("Text: ", res.node.get_content(), "Score: ", res.score)
Sample code output
Text:  text1 Score:  0.25589250620997755
Text:  text2 Score:  0.18071043165292258

Parameters

Input parameters

  • The following are the parameters for DashScopeRerank.

Parameter

Type

Default value

Description

model

string

gte-rerank

Supported models:

  • gte-rerank

top_n

int

3

The number of top-ranked documents to return. If this parameter is not specified, or if its value is greater than the number of candidate documents, all documents are returned.

return_documents

bool

False

Specifies whether to include the original document text in the sorted results. The default value is `False`.

api_key

str

None

The DashScope API key. This can be set through an environment variable or other methods.

Managed Agent API
Flow Agent API
Sandbox API
RAG API
Long-term Memory
ParseX API
Security API