Retrieves relevant text chunks from a knowledge base using vector and keyword search.
Operation description
- How to call: Use the latest Alibaba Cloud Model Studio SDK to call this API. The SDK handles signature calculation automatically.
-
Required permissions:
- RAM user (sub-account): A RAM user must have API permissions for Model Studio and join a workspace. The
AliyunBailianDataFullAccesspolicy includes the requiredsfm:Retrievepermission. - Alibaba Cloud account (main account): This account has the required permissions by default and can call the API directly.
- RAM user (sub-account): A RAM user must have API permissions for Model Studio and join a workspace. The
- Response latency: Retrieval operations may have longer response times. Configure appropriate timeouts and retry strategies.
- Idempotency: This API is idempotent.
Try it now
Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.
Test
RAM authorization
The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:
-
Action: The actions can be used in the
Actionelement of RAM permission policy statements to grant permissions to perform the operation. - API: The API that you can call to perform the action.
- Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.
-
Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.
- For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the
Resourceelement of the policy. - For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the
Resourceelement of the policy.
- For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the
- Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.
- Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.
Action | Access level | Resource type | Condition key | Dependent action |
|---|---|---|---|---|
sfm:Retrieve | none | *All Resource
| None | None |
Request syntax
Path Parameters
Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
WorkspaceId | string | Yes | The workspace ID. How to use workspaces. | llm-3shx2gu255oqxxxx |
Request parameters
Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
Query | string | No | The input query (original user prompt). No length limit. | 阿里云百炼平台介绍 |
DenseSimilarityTopK | integer | No | Number of text chunks to retrieve using vector search. Valid values: 0 to 100. The sum of Default value: 100. | 100 |
EnableReranking | boolean | No | Enables reranking (Knowledge base). Valid values:
Default value: Valid values:
| true |
EnableRewrite | boolean | No | Enables conversational query rewriting. Valid values:
Default value: Valid values:
| false |
Rerank | array<object> | No | The reranking configurations. | |
object | No | An object containing reranking configurations. | ||
ModelName | string | No | The reranking model. Overrides the default model configured for the knowledge base. Valid values:
Default: the model configured for the knowledge base. Use Valid values:
| gte-rerank-hybrid |
RerankMode | string | No | This parameter is not yet available. Do not specify a value for it. Valid values:
| qa |
RerankInstruct | string | No | This parameter is not yet available. Do not specify a value for it. | |
RerankMinScore | number | No | Minimum similarity score for reranking results. Valid values: 0.01 to 1.00. Overrides the threshold configured for the knowledge base. Default: the threshold configured for the knowledge base. | 0.20 |
RerankTopN | integer | No | Number of top-ranked text chunks to return after reranking. Valid values: 1 to 20. Default: 5. | 5 |
Rewrite | array<object> | No | Configuration for conversational query rewriting. | |
object | No | An object containing configurations for conversational query rewriting. | ||
ModelName | string | No | The model for conversational query rewriting. Rewrites the query based on conversation context to improve retrieval. Valid value:
Default: Valid values:
| conv-rewrite-qwen-1.8b |
SparseSimilarityTopK | integer | No | Number of text chunks to retrieve using keyword matching. Valid values: 0 to 100. The sum of Default value: 100. | 100 |
IndexId | string | Yes | The knowledge base ID, returned as
| 5pwe0mxxxx |
SaveRetrieverHistory | boolean | No | Saves retrieval history for testing. Valid values:
Default value: | false |
SearchFilters | array<object> | No | Custom retrieval conditions (such as tags) to filter results. Applies only when | |
object | No | A search condition object. | ||
string | No | |||
Images | array | No | The URLs of images to include in the query. | |
string | No | For image-based Q&A knowledge bases, provide image URLs. The system vectorizes the input image for retrieval if an image index exists. Otherwise, the input image is ignored. This field is not supported for knowledge bases of the document search or data query type. This field has no effect if specified. Make sure that the link is publicly accessible and points to a valid image file. Example: https://example.com/downloads/pic.jpg | ||
QueryHistory | array<object> | No | Conversation history for conversational query rewriting. Takes effect only when | |
object | No | |||
role | string | No | The message sender's role. Valid values:
| user |
content | string | No | The content of the message for the specified | What is Alibaba Cloud Model Studio? |
Response elements
Element | Type | Description | Example |
|---|---|---|---|
object | |||
Code | string | The error code. | Index.InvalidParameter |
Data | object | The data returned by the API. | |
Nodes | array<object> | An array of retrieved text chunks. | |
object | A text chunk object. | ||
Metadata | any | A map of metadata for the text chunk. For document search knowledge bases, the When you retrieve data from a document search knowledge base, if a text chunk contains an image, its URL is returned in the | { "parent": "", "file_path": "https://***", "image_url": [ "http://***" ], "nid": "***", "title": "阿里云百炼文档", "doc_id": "doc_***", "content": "阿里云百炼是基于通义大模型、行业大模型以及三方大模型的一站式大模型开发平台。面向企业客户和个人开发者,提供完整的模型服务工具和全链路应用开发套件,预置丰富的能力插件,提供API及SDK等便捷的集成方式,高效完成大模型应用构建", "workspace_id": "ws_***", "hier_title": "阿里云百炼文档", "doc_name": "阿里云百炼文档介绍.pdpf", "pipeline_id": "rhd***", "_id": "ws_***" } |
Score | number | The similarity score of the text chunk, ranging from 0 to 1. | 0.3 |
Text | string | The content of the text chunk. | 阿里云百炼是基于通义大模型、行业大模型以及三方大模型的一站式大模型开发平台。面向企业客户和个人开发者,提供完整的模型服务工具和全链路应用开发套件,预置丰富的能力插件,提供API及SDK等便捷的集成方式,高效完成大模型应用构建。 |
Message | string | The error message. | Required parameter(%s) missing or invalid, please check the request parameters. |
RequestId | string | The request ID. | 17204B98-7734-4F9A-8464-2446A84821CA |
Status | string | The HTTP status code of the response. | 200 |
Success | boolean | Whether the API call succeeded. Valid values:
| true |
Examples
Success response
JSON format