Retrieves relevant text chunks from a knowledge base using vector and keyword search.
Operation description
-
How to call: This page describes the OpenAPI Retrieve operation
POST /{WorkspaceId}/index/retrieve. You can call it through the latest Alibaba Cloud Model Studio SDK with an Alibaba Cloud AccessKey. Spring AI Alibaba uses an Alibaba Cloud Model Studio API Key and a separate DashScope Pipeline Retrieve path, and does not use the OpenAPI request syntax described on this page. -
Required permissions:
- RAM user (sub-account): A RAM user must first obtain the API permissions for Alibaba Cloud Model Studio (you can use the
AliyunBailianDataFullAccesspolicy, which includes the sfm:Retrieve permission required by this operation) and join a workspace before calling this operation. - Alibaba Cloud account (primary account): This account has the required permissions by default and can call the operation directly.
- RAM user (sub-account): A RAM user must first obtain the API permissions for Alibaba Cloud Model Studio (you can use the
- Response latency: Because the operation involves complex retrieval and matching, the response time can be long. We recommend that you set appropriate timeout and retry strategies for requests.
- Idempotency: This operation is idempotent.
Try it now
You can run this operation directly in OpenAPI Explorer, which saves you the trouble of calculating signatures. After the operation runs successfully, OpenAPI Explorer can automatically generate SDK code examples.
RAM authorization
The following table lists the authorization information for the API. You can use it in the Action element of a RAM permission policy statement to grant RAM users or RAM roles the permission to call this API. Details:
- Action: the specific permission point.
- Access level: the access level of each action. Valid values: Write, Read, or List.
-
Resource type: the resource types that the operation supports for authorization. Details:
- Required resource types are marked with a leading *.
- For operations that do not support resource-level authorization,
All Resourcesis used.
- Condition key: the condition keys defined by the cloud service itself.
- Dependent action: the other permissions required to successfully run the operation. The caller must also have the permissions for the dependent actions for the operation to succeed.
Action | Access level | Resource type | Condition key | Dependent action |
|---|---|---|---|---|
sfm:Retrieve | none | *All Resources
| None | None |
Request syntax
Path parameters
Name | Type | Required | Description | Example value |
|---|---|---|---|---|
| WorkspaceId | string | Yes | The ID of the workspace to which the knowledge base belongs. For more information, see how to use workspaces. | llm-3shx2gu255oqxxxx |
Request parameters
Name | Type | Required | Description | Example value |
|---|---|---|---|---|
| Query | string | No | The input text (the original input prompt). The length and characters of Query are not limited. | Introduction to Alibaba Cloud Model Studio |
| DenseSimilarityTopK | integer | No | Vector retrieval Top K. The system generates a vector for the input text and retrieves the K text chunks whose vector representations are most similar to it from the knowledge base. Valid range of K: [0-100]. The sum of Default value: 100. | 100 |
| EnableReranking | boolean | No | Specifies whether to enable reranking. For more information, see Knowledge base. Valid values:
Default value: true. Valid values:
| true |
| EnableRewrite | boolean | No | Specifies whether to enable conversational query rewriting. Valid values:
Default value: false. Valid values:
| false |
| Rerank | array<object> | No | The reranking configuration. | |
object | No | The reranking configuration object. | ||
| ModelName | string | No | The reranking model to use. The specified value overrides the reranking model selected when the knowledge base was created. Valid values:
Default value: empty, which means the reranking model selected when the knowledge base was created is used. If you only need semantic ranking, you can use
Valid values:
| gte-rerank-hybrid |
| RerankMode | string | No | Specifies the instruction mode of the reranking model, which determines its scoring preference. Valid values:
Valid values:
| qa |
| RerankInstruct | string | No | Provides a natural language instruction to fine-tune the behavior of the reranking model. This parameter takes effect only when rerank_mode is set to "custom". | |
| RerankMinScore | number | No | The similarity threshold. It specifies the minimum similarity score of text chunks that can be recalled, and is used to filter the text chunks returned by the Rank model. That is, only text chunks with a score higher than this value are recalled. Valid range: [0.01-1.00]. This parameter takes precedence over the similarity threshold configured for the knowledge base. If no specific value is specified, the similarity threshold configured for the knowledge base is used by default. | 0.20 |
| RerankTopN | integer | No | The top N results returned after reranking. Valid range: [1-20]. Default value: 5. | 5 |
| Rewrite | array<object> | No | The configuration for conversational query rewriting. | |
object | No | The configuration object for conversational query rewriting. | ||
| ModelName | string | No | The name of the model for conversational query rewriting. It automatically adjusts the original input prompt (user question) based on the conversation context to improve retrieval. Valid values:
Default value: empty, in which case the conv-rewrite-qwen-1.8b model is used. Valid values:
| conv-rewrite-qwen-1.8b |
| SparseSimilarityTopK | integer | No | Keyword retrieval Top K, that is, retrieving chunks from the knowledge base whose keywords exactly match those of the input text. It helps you filter out irrelevant text chunks and provides more accurate results. Valid range: [0-100]. The sum of Default value: 100. | 100 |
| IndexId | string | Yes | The knowledge base ID, that is, the
| 5pwe0mxxxx |
| SaveRetrieverHistory | boolean | No | Specifies whether to save the test data of historical text chunk recall. Valid values:
Default value: false. | false |
| SearchFilters | array<object> | No | You can use SearchFilters to set personalized retrieval conditions (such as tags) to filter the semantic retrieval results and exclude information irrelevant to the query. Condition objects in the array are combined with AND. Multiple retrieval fields within the same object use AND by default; place | |
object | No | The search condition object. | ||
string | No | |||
| Images | array | No | You can pass image URLs in the query. | |
string | No | When you retrieve from an image Q&A knowledge base, you can pass image URLs. If the knowledge base contains an image index, the system converts the input image into a vector and retrieves relevant records; if no image index exists, the input image is not used for retrieval. This field is not supported for document search, data query, or audio/video search knowledge bases (passing it in has no effect). 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 | Conversational query rewriting lets you pass in the conversation history that you manage. It takes effect only when EnableRewrite=true (otherwise it has no effect even if passed in). | |
object | No | |||
| role | string | No | The role. Valid values:
| user |
| content | string | No | The question or answer content corresponding to the role. | Represents a piece of text. |
| Extra | object | No | ||
| uniqueId | string | No |
SearchFilters filters chunks whose document name is 长上下文Qwen-Long or whose chunk title is 返回结果. Replace the fields and values with the fields and values that are actually searchable in the knowledge base:
SearchFilters and do not support nested _conditions. If you pass in a nested structure, the request may still return a successful response, but it does not filter by the nested conditions. To set multiple OR conditions for the same field, use a RAG API JSON request body, or call through the /api/v1/indices/pipeline/{pipeline_id}/retrieve path of the Spring AI Alibaba DashScope SDK. Both invocation methods support _operator and nested _conditions. For syntax and examples, see SearchFilters for a knowledge base.Response elements
Name | Type | Description | Example value |
|---|---|---|---|
object | |||
| Code | string | The error code. | Index.InvalidParameter |
| Data | object | The business data fields of the operation. | |
| Nodes | array<object> | The list of matched text chunks. | |
object | The text chunk object. | ||
| Metadata | any | The metadata map of the text chunk. For document search knowledge bases, the When you retrieve from a document search knowledge base, if a text chunk contains an image, the image is exposed through the When you retrieve from an audio/video search knowledge base, if a text chunk contains audio, the audio is exposed through the When you retrieve from an audio/video search knowledge base, if a text chunk contains video, the video is exposed through the | { "parent": "", "file_path": "https://***", "image_url": [ "http://***" ], "nid": "***", "title": "Alibaba Cloud Model Studio documentation", "doc_id": "doc_***", "content": "Alibaba Cloud Model Studio is a one-stop large model development platform built on Tongyi large models, industry large models, and third-party large models. It provides enterprise customers and individual developers with complete model service tools and full-link application development suites, pre-configured rich capability plugins, and convenient integration methods such as APIs and SDKs to efficiently build large model applications", "workspace_id": "ws_***", "hier_title": "Alibaba Cloud Model Studio documentation", "doc_name": "Introduction to Alibaba Cloud Model Studio documentation.pdf", "pipeline_id": "rhd***", "_id": "ws_***" } |
| Score | number | The similarity score of the text chunk. Valid range: [0-1]. | 0.3 |
| Text | string | The content of the text chunk. | Alibaba Cloud Model Studio is a one-stop large model development platform built on Tongyi large models, industry large models, and third-party large models. It provides enterprise customers and individual developers with complete model service tools and full-link application development suites, pre-configured rich capability plugins, and convenient integration methods such as APIs and SDKs to efficiently build large model applications. |
| 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 status code returned by the operation. | 200 |
| Success | boolean | Indicates whether the operation call is successful. Valid values:
| true |
Examples
Success response
JSON format