ContextualRetrieval

Updated at:

Retrieves semantically similar documents for multi-turn conversation scenarios by processing message inputs that include conversation history. By deeply analyzing context information, this operation ensures that retrieval results are highly relevant to the current conversation, applies to complex interaction environments, and provides consistent and efficient information retrieval for multi-turn conversations.

Operation description

Precautions

  • Make sure that you fully understand the billing methods and pricing of Intelligent Media Management before you call this operation.

  • Before you call this operation, make sure that you have indexed files into a dataset by using the binding method (CreateBinding) or the active indexing method (IndexFileMeta or BatchIndexFileMeta).

  • The return results are for reference only. Depending on the workflow template configurations, the categories and content of the obtained file metadata may differ from the examples. If you have any questions, search for the DingTalk group number 21714099 in DingTalk to join the group and provide feedback.

Limits

  • The maximum length of the conversation history is 100, including user messages and assistant messages.

  • The length of each message cannot exceed 1,000 Chinese characters.

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 Action element 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 Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • 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

imm:ContextualRetrieval

none

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

ProjectName

string

Yes

The name of the project. For information about how to obtain the project name, see Create a project.

test-project

DatasetName

string

Yes

The dataset used for retrieval.

test-dataset

Messages

array

Yes

The conversation history and tool calling (invoke) history. The latest message is at the end (index n-1), and the legacy message is at the beginning (index 0). The messages must be in user-assistant pairs, with a total of 2*n+1 messages, and the length of the latest question cannot exceed 1,000 characters. The maximum length of the conversation history is 100.

ContextualMessage

No

The list of conversation messages.

RecallOnly

boolean

No

Specifies whether to enable only the recall process (embedding search). If this parameter is set to true, the returned data is not reranked, which allows you to customize the reranking process. Default value: false.

false

SmartClusterIds

array

No

The list of smart cluster IDs used to retrieve files within specific smart clusters.

string

No

The smart cluster ID.

SmartCluster-01686226-be59-4391-a1ac-b7b073455de3

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The request ID.

6E93D6C9-5AC0-49F9-914D-E02678D3****

Results

array

The list of retrieved files. The structural content related to the document is included in File.Elements.

File

The file information in the retrieval result.

Examples

Success response

JSON format

{
  "RequestId": "6E93D6C9-5AC0-49F9-914D-E02678D3****",
  "Results": [
    {
      "AccessControlAllowOrigin": "https://aliyundoc.com",
      "AccessControlRequestMethod": "PUT",
      "Addresses": [
        {
          "AddressLine": "",
          "City": "",
          "Country": "",
          "District": "",
          "Language": "zh-Hans",
          "Province": "",
          "Township": ""
        }
      ],
      "Album": "FirstAlbum",
      "AlbumArtist": "Jane",
      "Artist": "Jane",
      "AudioCovers": [
        {
          "CroppingSuggestions": [
            {
              "AspectRatio": "2:3",
              "Boundary": {
                "Height": 300,
                "Left": 10,
                "Polygon": [
                  {
                    "X": 10,
                    "Y": 10
                  }
                ],
                "Top": 30,
                "Width": 200
              },
              "Confidence": 0.742
            }
          ],
          "EXIF": "{\"FileSize\":{\"value\":\"29304\"},\"Format\":{\"value\":\"jpg\"}}",
          "ImageHeight": 820,
          "ImageScore": {
            "OverallQualityScore": 0.736
          },
          "ImageWidth": 500,
          "OCRContents": [
            {
              "Boundary": {
                "Height": 300,
                "Left": 10,
                "Polygon": [
                  {
                    "X": 10,
                    "Y": 10
                  }
                ],
                "Top": 30,
                "Width": 200
              },
              "Confidence": 0.8254936695098877,
              "Contents": "",
              "Language": "zh-hans"
            }
          ]
        }
      ],
      "AudioStreams": [
        {
          "Bitrate": 320087,
          "ChannelLayout": "stereo",
          "Channels": 2,
          "CodecLongName": "AAC (Advanced Audio Coding)",
          "CodecName": "aac",
          "CodecTag": "0x6134706d",
          "CodecTagString": "mp4a",
          "CodecTimeBase": "1/44100",
          "Duration": 3.690667,
          "FrameCount": 173,
          "Index": 1,
          "Language": "en",
          "Lyric": "test",
          "SampleFormat": "fltp",
          "SampleRate": 48000,
          "StartTime": 0.0235,
          "TimeBase": "1/48000"
        }
      ],
      "Bitrate": 13091201,
      "CacheControl": "no-cache",
      "Composer": "Jane",
      "ContentDisposition": "attachment; filename =test.jpg",
      "ContentEncoding": "UTF-8",
      "ContentLanguage": "zh-CN",
      "ContentMd5": "HZwoCnxPZ/fvhz4oRJ2+Fw==",
      "ContentType": "image/jpeg",
      "CreateTime": "2021-06-29T14:50:13.011643661+08:00",
      "CroppingSuggestions": [
        {
          "AspectRatio": "2:3",
          "Boundary": {
            "Height": 300,
            "Left": 10,
            "Polygon": [
              {
                "X": 10,
                "Y": 10
              }
            ],
            "Top": 30,
            "Width": 200
          },
          "Confidence": 0.742
        }
      ],
      "CustomId": "\t\nmember-image-id-0001",
      "CustomLabels": {
        "MemberName": "Tim",
        "Enabled": "True",
        "ItemCount": "10"
      },
      "DatasetName": "test-dataset",
      "Duration": 15.263,
      "ETag": "\"1D9C280A7C4F67F7EF873E28449****\"",
      "EXIF": "{\"Compression\":{\"value\":\"6\"},\"DateTime\":{\"value\":\"2020:08:19 17:11:11\"}}",
      "Elements": [
        {
          "ElementContents": [
            {
              "Content": "文本片段",
              "TimeRange": [
                500
              ],
              "Type": "text",
              "URL": "http://aliyun.com"
            }
          ],
          "ElementRelations": [
            {
              "ObjectId": "id1",
              "Type": "child,parent"
            }
          ],
          "ElementType": "title - 标题; image - 图片 ; table - 表格 ; narrative-text - 正文",
          "ObjectId": "id1",
          "SemanticSimilarity": 0.8
        }
      ],
      "FigureCount": 10,
      "Figures": [
        {
          "Age": 29,
          "AgeSD": 5,
          "Attractive": 0.96,
          "Beard": "none",
          "BeardConfidence": 1,
          "Emotion": "happiness",
          "EmotionConfidence": 0.70784568786621,
          "FaceQuality": 0.960875928401947,
          "FigureClusterConfidence": 1,
          "FigureClusterId": "Cluster-dbe72fec-b84c-4ab6-885b-3678e64****",
          "FigureConfidence": 1,
          "FigureId": "868a9e74-cde5-4c7a-9013-28bb984****",
          "FigureType": "face",
          "Gender": "female",
          "GenderConfidence": 1,
          "Glasses": "none",
          "GlassesConfidence": 0.8,
          "Hat": "none",
          "HatConfidence": 1,
          "HeadPose": {
            "Pitch": 18.385589599609375,
            "Roll": 4.204030513763428,
            "Yaw": 2.4945924282073975
          },
          "Mask": "none",
          "MaskConfidence": 1,
          "Mouth": "close",
          "MouthConfidence": 1,
          "Sharpness": 0.7
        }
      ],
      "FileAccessTime": "2021-06-29T14:50:13.011643661+08:00",
      "FileCreateTime": "2021-06-29T14:50:13.011643661+08:00",
      "FileHash": "1d9c280a7c4f67f7ef873e28449dbe17",
      "FileModifiedTime": "2021-06-29T14:50:13.011643661+08:00",
      "Filename": "sampleobject.jpg",
      "FormatLongName": "QuickTime / MOV",
      "FormatName": "mov",
      "ImageHeight": 500,
      "ImageScore": {
        "OverallQualityScore": 0.736
      },
      "ImageWidth": 270,
      "Insights": {
        "Image": {
          "Caption": "An orange tabby cat lying on the living room sofa with sunlight streaming in through the window",
          "Description": "The image shows a person wearing a dark suit jacket over a white shirt. The background features a gradient from light blue to gray",
          "MultilingualContent": {
            "key": {
              "Caption": "No personnel activity at the office desk",
              "Description": "This is a close-up shot of an office desk setup. In the left foreground stands a tall, cylindrical, off-white insulated tumbler. A rectangular black mousepad occupies the center of the desk, holding a black backlit mechanical keyboard. Directly behind the keyboard sits a computer monitor with its screen illuminated, displaying the operating system's application dock at the bottom. To the front right of the monitor stands a red metal beverage can, surrounded by a tangle of white data cables and a charging adapter. A small, silver, rectangular device (possibly a USB drive or an adapter) rests in the gap behind the left side of the keyboard, and a tiny pink decorative object is faintly visible on the desk surface. The scene is devoid of human activity; all objects remain motionless."
            }
          }
        },
        "Video": {
          "Caption": "The video shows two different scenes: one features a stationary white plate, a black bottle, and a transparent glass, and the other shows a hand holding a shampoo bottle labeled \"YEZOLU\" moving slowly upward in a bathroom",
          "Description": "The scene shows a slightly chubby orange cat lying on a light gray fabric sofa with its body slightly curled up",
          "MultilingualContent": {
            "key": {
              "Caption": "No personnel activity at the office desk",
              "Description": "This is a close-up shot of an office desk setup. In the left foreground stands a tall, cylindrical, off-white insulated tumbler. A rectangular black mousepad occupies the center of the desk, holding a black backlit mechanical keyboard. Directly behind the keyboard sits a computer monitor with its screen illuminated, displaying the operating system's application dock at the bottom. To the front right of the monitor stands a red metal beverage can, surrounded by a tangle of white data cables and a charging adapter. A small, silver, rectangular device (possibly a USB drive or an adapter) rests in the gap behind the left side of the keyboard, and a tiny pink decorative object is faintly visible on the desk surface. The scene is devoid of human activity; all objects remain motionless."
            }
          }
        }
      },
      "Labels": [
        {
          "CentricScore": 0.7319999933242798,
          "Clips": [
            {
              "TimeRange": [
                100
              ]
            }
          ],
          "LabelAlias": "座椅",
          "LabelConfidence": 0.9891784601980591,
          "LabelLevel": 1,
          "LabelName": "椅子",
          "Language": "zh-Hans",
          "ParentLabelName": "家具"
        }
      ],
      "Language": "eng",
      "LatLong": "30.134390,120.074997",
      "MediaType": "image",
      "OCRContents": [
        {
          "Confidence": 0.8254936695098877,
          "Contents": "",
          "Language": "zh-hans"
        }
      ],
      "OCRTexts": "阿里云IMM",
      "OSSCRC64": "559890638950338001",
      "OSSDeleteMarker": "CAEQMhiBgIDXiaaB0BYiIGQzYmRkZGUxMTM1ZDRjOTZhNjk4YjRjMTAyZjhl****",
      "OSSExpiration": "2120-01-01T12:00:00.000Z",
      "OSSObjectType": "Normal",
      "OSSStorageClass": "Standard",
      "OSSTagging": {
        "key": "val"
      },
      "OSSTaggingCount": 2,
      "OSSURI": "oss://examplebucket/sampleobject.jpg",
      "OSSUserMeta": {
        "key": "val"
      },
      "OSSVersionId": "CAEQNhiBgMDJgZCA0BYiIDc4MGZjZGI2OTBjOTRmNTE5NmU5NmFhZjhjYmY0****",
      "ObjectACL": "default",
      "ObjectId": "75d5de2c50754e3dadd5c35dbca5f9949369e37eb342a73821f690c94c36c7f7",
      "ObjectStatus": "Indexed",
      "ObjectType": "file",
      "Orientation": 0,
      "OwnerId": "102321002467****",
      "PageCount": 5,
      "Performer": "Jane",
      "ProduceTime": "2021-06-29T14:50:13.011643661+08:00",
      "ProgramCount": 1,
      "ProjectName": "test-project",
      "Reason": "[InternalError] The request has been failed due to some unknown error. status: 500, requestId: CC5ACFBD-BB7A-496D-A9D6-****",
      "SceneElements": [
        {
          "FrameTimes": [
            30
          ],
          "Labels": [
            {
              "CentricScore": 0.7319999933242798,
              "Clips": [
                {
                  "TimeRange": [
                    100
                  ]
                }
              ],
              "LabelAlias": "座椅",
              "LabelConfidence": 0.9891784601980591,
              "LabelLevel": 1,
              "LabelName": "椅子",
              "Language": "zh-Hans",
              "ParentLabelName": "家具"
            }
          ],
          "TimeRange": [
            100
          ],
          "VideoStreamIndex": 0
        }
      ],
      "SemanticTypes": [
        "content"
      ],
      "ServerSideDataEncryption": "SM4",
      "ServerSideEncryption": "AES256",
      "ServerSideEncryptionCustomerAlgorithm": "SM4",
      "ServerSideEncryptionKeyId": "9468da86-3509-4f8d-a61e-6eab1eac****",
      "Size": 1000,
      "StartTime": 0,
      "StreamCount": 1,
      "Subtitles": [
        {
          "Bitrate": 74,
          "CodecLongName": "MOV text",
          "CodecName": "mov_text",
          "CodecTag": "0x67337874",
          "CodecTagString": "tx3g",
          "Content": "",
          "Duration": 71.378,
          "Height": 30,
          "Index": 2,
          "Language": "en",
          "StartTime": 0,
          "Width": 600
        }
      ],
      "Timezone": "\"\"",
      "Title": "test",
      "TravelClusterId": "-",
      "URI": "oss://test-bucket/test-object.jpg",
      "UpdateTime": "2021-06-29T14:50:13.011643661+08:00",
      "VideoHeight": 1920,
      "VideoStreams": [
        {
          "AverageFrameRate": "25/1",
          "BitDepth": 8,
          "Bitrate": 5407765,
          "CodecLongName": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
          "CodecName": "h264",
          "CodecTag": "0x31637661",
          "CodecTagString": "avc1",
          "CodecTimeBase": "1373627/83160000",
          "ColorPrimaries": "bt709",
          "ColorRange": "tv",
          "ColorSpace": "bt709",
          "ColorTransfer": "bt709",
          "DisplayAspectRatio": "16:9",
          "Duration": 22.88,
          "FrameCount": 572,
          "FrameRate": "25/1",
          "HasBFrames": 2,
          "Height": 720,
          "Index": 0,
          "Language": "en",
          "Level": 40,
          "PixelFormat": "yuv420p",
          "Profile": "High",
          "Rotate": "90",
          "SampleAspectRatio": "1:1",
          "StartTime": 0,
          "TimeBase": "1/12800",
          "Width": 1280
        }
      ],
      "VideoWidth": 1080
    }
  ]
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.