All Products
Search
Document Center

OpenSearch:Rich text

Last Updated:Mar 11, 2025

This topic describes how to configure the rich text feature of OpenSearch LLM-Based Conversational Search Edition and the effect of the feature.

In the online RAG process of OpenSearch, all rich text, including images, tables, and codes, is extracted during document slicing and saved in the format of rich text tags along with the body slice. If you enable the rich text feature, rich text in documents can be contained in answers returned by large language models (LLMs).

Enable the rich text feature

The rich_text_strategy parameter on the Other Parameters tab on the Q&A Test page of your OpenSearch instance is used to manage the rich text feature. If you configure this parameter, the feature is enabled. If you leave this parameter empty, the feature is disabled.

image

Parameter description:

The following parameter is added to the SearchKnowledge API operation.

options.chat.rich_text_strategy

String

No

The processing method of rich text. If this parameter does not exist or is left empty, rich text is not enabled, and the default processing method is used.

  • inside_response: The rich text tag in the answer is directly restored to the original text in the Markdown format. Note that a table is directly inserted into the Markdown file in the HTML format.

  • extend_response: The actual content of each rich text tag in the answer is returned by rich_text_ref. A picture is returned as a URL, a table is returned in the HTML format, and code is returned in the text format.

inside_response

Answers are returned in the Markdown format and may contain rich text such as tables, images, and code.

extend_response

Answers are returned in plain text and may contain rich text tags. You can click the tags to view detailed rich text that is not rendered.

Sample request

{
	"question": {
		"text": "How do I configure a sensitive data identification rule?",
		"type": "TEXT"
	},
	"options": {
		"chat": {
			"rich_text_strategy": "inside_response"
		}
	}
}

Response for extend_response

Rich text tags in data.rich_text_ref need to be automatically parsed, and logic for replacing the rich text tags in data.answer needs to be developed.

{
  "request_id": "0bb16ed4-6eec-4ae4-b1dd-0650289b45b3",
  "status": "OK",
  "latency": 11421.663139,
  "result": {
    "data": [
      {
        "answer": "To configure a sensitive data identification rule, perform the following steps: \n\n1. Go to the Sensitive Data Identification page. \n   - Log on to the DataWorks console and go to the data development page. \n   - Click the icon in the upper-left corner. Then, choose All Products > Data Governance > Data Security Guard. On the page that appears, click Try Now to go to the Data Security Guard page. \n   - In the left-side navigation pane, choose Rule Configuration > Sensitive Data Identification. \n\n2. Configure a category for a sensitive field type. \n   - If you use Data Security Guard for the first time, you can search for or add a category in the left-side section. \n   - If you are an existing user, you can create a category based on your business requirements. \n   - The name of a category must be unique. The name must be 1 to 30 characters in length and can contain letters and digits. \n\n3. Configure a sensitive data identification rule. \n   - On the Data Identification Rules tab, click \"+ Sensitive Field Type\" to add a sensitive field type. \n   - In the Basic Information step, configure the parameters, including Sensitive Field Type, Data Category, Sensitivity Level, and Description. [^Table-16134^]\n   - Click \"Next\". \n   - In the Rule Configuration step, configure a sensitive data identification rule based on the sensitive field type, configure the conditions based on which the rule is triggered, and then test the accuracy of the rule. [^Figure-19933^]\n   - Click \"Publish to Use\" to publish the sensitive data identification rule. \n\n4. Authorize a sensitive data identification task to identify sensitive data and start the task. \n   - In the upper-left corner of the Sensitive Data Identification page, click \"Run Task\" to authorize a sensitive data identification task to identify sensitive data. \n   - In the Enable sensitive data identification tasks panel, configure the sensitive data identification task, including the task type, scanning method, and scanning range. [^Figure-41464^]\n   - Click \"Run\" to start the task. \n\nTake note of the following items: \n- If you do not want to use the rule, you can click \"Save as Draft\" to save the rule. \n- If data in a column hits multiple sensitive data identification rules that are configured for different sensitive field types, the system identifies sensitive data in the column in the following order: sensitive field name identification, sensitive content identification, and sensitive comment identification. \n- If you want the new rule to take effect in real time, you must manually trigger the task to run. \n- If you modify the sensitive data identification rule, the new rule takes effect the next time the task is automatically run. \n\nIn addition, you can perform the following operations: \n- Copy a rule \n- Modify a rule \n- Delete a rule \n- Publish multiple rules at a time \n- Unpublish multiple rules at a time \n\n These operations can help you manage sensitive data identifications rules more flexibly.",
        "type": "TEXT",
        "reference": [
          {
            "tokenNum": 1814,
            "id": "8d89d16d8e73658ee12ea0b9e70a5ee2",
            "title": "Configure a sensitive data identification rule and run a sensitive data identification task_DataWorks-Alibaba Cloud Help Center",
            "url": "https://xxx.com"
          }
        ],
        "rich_text_ref": [
          {
            "id": "Table-16134",
            "content": "<table><tbody>\n <tr>\n  <td><b>Parameter</b></td>\n  <td><b>Description</b></td>\n </tr>\n <tr>\n  <td><b data-tag=\"uicontrol\" id=\"uicontrol-a5j-bxo-9a3\" class=\"uicontrol\">Sensitive Field Type</b></td>\n  <td>The name of the sensitive field type, such as name, ID number, or phone number. The name must be unique. </td>\n </tr>\n <tr>\n  <td><b data-tag=\"uicontrol\" id=\"uicontrol-80t-1ey-cbs\" class=\"uicontrol\">Data Category</b></td>\n  <td>The category to which the sensitive field type belongs. If the existing categories do not meet your business requirements, you can configure a category on the <b data-tag=\"uicontrol\" id=\"uicontrol-5sa-eit-jzt\" class=\"uicontrol\">Data Category and Sensitivity Level</b> page. For more information, see <a href=\"https://xxx.com" id=\"21566a9cceiv9\" title=\"\" class=\"xref\">Specify the category and sensitivity level of sensitive data</a>. </td>\n </tr>\n <tr>\n  <td><b data-tag=\"uicontrol\" id=\"uicontrol-o8f-oek-vx3\" class=\"uicontrol\">Sensitivity Level</b></td>\n  <td>The sensitivity level of the sensitive field type. A large number indicates a high sensitivity level. If the existing sensitivity levels do not meet your requirements, you can configure a sensitivity level on the <b data-tag=\"uicontrol\" id=\"3a552504f1aui\" class=\"uicontrol\">Data Category and Sensitivity Level</b> page. For more information, see <a href=\"https://xxx.com\" id=\"39588a781b9hn\" title=\"\" class=\"xref\">Specify the category and sensitivity level of sensitive data</a>. </td>\n </tr>\n</tbody></table>"
          },
          {
            "id": "Figure-19933",
            "content": "https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/9017816461/p339261.png"
          },
          {
            "id": "Figure-41464",
            "content": "https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5947660271/p819013.png"
          }
        ]
      },
      {
        "answer": "https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5947660271/p339229.png",
        "type": "IMAGE",
        "reference": [
          {
            "tokenNum": 179,
            "id": "8d89d16d8e73658ee12ea0b9e70a5ee2",
            "title": "Configure a sensitive data identification rule and run a sensitive data identification task_DataWorks-Alibaba Cloud Help Center",
            "url": "https://xxx.com"
          }
        ]
      }
    ]
  }
}

Response for inside_response

The data.answer field is parsed in the Markdown format, regardless of the rich_text_ref field.

{
  "request_id": "b1f59cc0-daad-45e2-bc41-f01e1c2ff5d7",
  "status": "OK",
  "latency": 9828.389664,
  "result": {
    "data": [
      {
        "answer": "To configure a sensitive data identification rule, perform the following steps: \n\n1. Go to the Sensitive Data Identification page. \n   - Log on to the DataWorks console and go to the Data Development page. \n   - On the Data Development page, select a workspace from the drop-down list and click Go to Data Development. \n   - On the page that appears, click the icon in the upper-left corner and choose \"All Products > Data Governance > Data Security Guard\" to go to the Data Security Guard page. On the page, click Try Now. \n   - In the left-side navigation pane, choose \"Rule Configuration > Sensitive Data Identification\". \n\n2. Configure a category for a sensitive field type. \n   - If you use Data Security Guard for the first time, you can search for or add a category in the left-side section. \n   - If you are an existing user, you can create a category based on your business requirements. \n   - The name of a category must be unique. The name must be 1 to 30 characters in length and can contain letters and digits. \n\n3. Configure a sensitive data identification rule. \n   - On the Data Identification Rules tab, click \"+ Sensitive Field Type\" to add a sensitive field type. \n   - In the Basic Information step, configure the basic information about the sensitive field type. \n     - Enter a value in the Sensitive Field Type field. \n     - Select a value from the Data Category drop-down list. \n     - Select a value from the Sensitivity Level drop-down list. \n     - Enter a value in the Description field. \n   - Click \"Next\". \n   - In the Rule Configuration step, configure a sensitive data identification rule based on the sensitive field type, configure the conditions based on which the rule is triggered, and then test the accuracy of the rule. ![](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/9017816461/p339261.png)\n   - Click \"Publish to Use\" to publish the sensitive data identification rule. \n\n4. Authorize a sensitive data identification task to identify sensitive data and start the task. \n   - In the upper-left corner of the Sensitive Data Identification page, click \"Run Task\" to authorize a sensitive data identification task to identify sensitive data. \n   - Start the sensitive data identification task. \n     - Configure the sensitive data identification task, including the task type, scanning method, and scanning range. ![](https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5947660271/p819013.png)\n     - Click \"Run Task\" to start the task. \n\n5. Manage sensitive data identification rules. \n   - Copy, modify, or delete a rule. \n   - Publish or unpublish multiple rules at a time. \n\nYou can use the rule in a sensitive data identification task to identify sensitive data only after the rule is published. If a large number of rules are available, you can publish or unpublish the rules at a time.",
        "type": "TEXT_MARKDOWN",
        "reference": [
          {
            "tokenNum": 1814,
            "id": "8d89d16d8e73658ee12ea0b9e70a5ee2",
            "title": "Configure a sensitive data identification rule and run a sensitive data identification task_DataWorks-Alibaba Cloud Help Center",
            "url": "https://xxx.com"
          }
        ],
        "rich_text_ref": [
          {
            "id": "Figure-3873",
            "content": "https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/9017816461/p339261.png"
          },
          {
            "id": "Figure-19511",
            "content": "https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5947660271/p819013.png"
          }
        ]
      },
      {
        "answer": "https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/5947660271/p339229.png",
        "type": "IMAGE",
        "reference": [
          {
            "tokenNum": 179,
            "id": "8d89d16d8e73658ee12ea0b9e70a5ee2",
            "title": "Configure a sensitive data identification rule and run a sensitive data identification task_DataWorks-Alibaba Cloud Help Center",
            "url": "https://xxx/user-guide/identify-sensitive-data"
          }
        ]
      }
    ]
  }
}

Usage notes

In the returned data list, the "type": "IMAGE" item indicates the result of some images in the retrieval phase. The images are irrelevant to the rich text feature. The correlation of images generated by the rich text feature is better than that of images generated in the retrieval phase.