OpenSearch LLM-Based Conversational Search Edition allows you to upload documents that contain image information. This way, OpenSearch can return structured results that contain images.
Upload documents
You can upload documents by calling an API operation or uploading files in the OpenSearch console. In this example, documents are uploaded by calling an API operation.
Click Import API to view the endpoint of the OpenSearch API in your region and the demo code for importing data.

Endpoint of the OpenSearch API
http://opensearch-cn-shanghai.aliyuncs.com. In this example, the endpoint in the China (Shanghai) region is used.Demo code
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.opensearch.OpenSearchClient;
import com.aliyun.opensearch.sdk.generated.OpenSearch;
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchException;
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchResult;
/**
* Demo code for pushing documents
*/
public class testPushDemo {
private static String appName = "The name of the OpenSearch application to which you want to push documents";
private static String accesskey = "The AccessKey ID of your Alibaba Cloud account";
private static String secret = "The AccessKey secret of your Alibaba Cloud account";
private static String host = "The endpoint of the OpenSearch API in your region";
private static String path = "/apps/%s/actions/knowledge-bulk";
public static void main(String[] args) {
String appPath = String.format(path, appName);
// Create an OpenSearch object.
OpenSearch openSearch = new OpenSearch(accesskey, secret, host);
// Use the OpenSearch object as a parameter to create an OpenSearchClient object.
OpenSearchClient openSearchClient = new OpenSearchClient(openSearch);
// Create a JSON object for adding a single document.
JSONObject oneRequest = new JSONObject();
oneRequest.put("cmd", "ADD");
JSONObject fields = new JSONObject();
fields.put("id", "The ID of the test document");
fields.put("title", "The title of the test document");
fields.put("url", "The URL of the test document");
fields.put("content", "<h2>Alibaba travel front-end technology past and present</h2><br /><p><img src="http://gw.alicdn.com/tps/TB1fhZbJFXXXXbhaXXXXXXXXXXX-864-176.png" width=300></p>");
fields.put("category", "The category of the test document");
oneRequest.put("fields", fields);
// Create a JSON array. You can use the JSON array to add multiple documents at a time.
JSONArray request = new JSONArray();
request.add(oneRequest);
Map<String, String> params = new HashMap<String, String>() {{
put("format", "full_json");
put("_POST_BODY", request.toJSONString());
}};
try {
OpenSearchResult openSearchResult = openSearchClient.callAndDecodeResult(appPath, params, "POST");
// Display the return result.
System.out.println(openSearchResult.getResult());
} catch (OpenSearchException e) {
e.printStackTrace();
} catch (OpenSearchClientException e) {
e.printStackTrace();
}
}
}You must add the URLs of images to the content field. Make sure that the URLs can be accessed through a browser.
OpenSearch searches for images based on the titles of documents and the values of tags.
Tags: <h1></h1>, <h2></h2>, <h3></h3>, <h4></h4>, and <h5></h5>
Sample image: <h2>Alibaba travel front-end technology past and present</h2><br /><p><img src="http://gw.alicdn.com/tps/TB1fhZbJFXXXXbhaXXXXXXXXXXX-864-176.png" width=300></p>
Run a Q&A test
1. Log on to the OpenSearch console and switch to LLM-Based Conversational Search Edition in the upper-left corner. On the page that appears, click Instance Management in the left-side navigation pane, find the instance in which you want to run a Q&A test, and then click Manage in the Actions column to go to the instance details page. On the instance details page, click Q&A Test in the left-side pane.


2. On the page that appears, enter your question and click Send.

3. View the result of the Q&A test.

Usage notes
You can upload Markdown or HTML documents that contain image information.
An img tag is used to embed an image in the Markdown or HTML document that you upload. The img tag must have an src attribute to specify the image URL.
An image URL must start with http or https and end with. jpg, .jpeg, or .png.
The images must be in the JPG, JPEG, or PNG format.