DashScopeCloudRetriever
DashScopeCloudRetriever is a software development kit (SDK) from Alibaba Cloud Model Studio. It lets you initialize a LlamaIndex retriever in the LlamaIndex framework.
Get started
Prerequisites
Log on to https://bailian.console.aliyun.com/cn-beijing/ and obtain your API key. To specify a workspace, obtain the workspace ID.
- An API key is created. For more information, see Get and configure an API key.
- A workspace is created. For more information, see Workspace management.
Then, install the DashScopeCloudIndex package, which requires Python versions 3.9 to 3.12.
pip install llama-index-core
pip install llama-index-indices-managed-dashscope
import os
from llama_index.indices.managed.dashscope.retriever import DashScopeCloudRetriever
os.environ["DASHSCOPE_API_KEY"] = "your_api_key_here"
os.environ["DASHSCOPE_WORKSPACE_ID"] = "your_workspace_here"
retriever = DashScopeCloudRetriever("your index name")
nodes = retriever.retrieve("test query")
print(nodes)
Parameter descriptions
Input parameters
Parameter | Type | Default value | Description |
|---|---|---|---|
index_name | str | None | The index name. |
dense_similarity_top_k | int | 100 | The number of items to retrieve from vector search. |
sparse_similarity_top_k | int | 100 | The number of items to retrieve from text search. |
enable_reranking | bool | True | Specifies whether to use a reranking model. |
rerank_model_name | str | gte-rerank-hybrid | The name of the reranking model. Supported models include the following:
|
rerank_min_score | float | 0.0 | The score threshold for filtering retriever nodes. The retriever returns only nodes with a score higher than rerank_min_score. This parameter takes effect only when enable_reranking is set to True. |
rerank_top_n | int | 5 | The number of nodes that the retriever returns. If the specified value exceeds the number of candidate nodes, all candidate nodes are returned. |
workspace_id | str | None | The ID of the DashScope workspace. You can set this using an environment variable or other methods. |
api_key | str | None | The DashScope API key. You can set this using an environment variable or other methods. |