Use AI models

Updated at:

In a Retrieval-Augmented Application (version 8.17), you can call AI models through the Inference API to enable features such as structured text extraction, intelligent document splitting, and text embedding. This topic describes how to activate and initialize the AI model service and how to call the models in Kibana.

Background information

  • AI Search Open Platform is a sub-product of OpenSearch. Focused on intelligent search and Retrieval-Augmented Generation (RAG) scenarios, it provides the algorithm services used in the AI search pipeline as modular components. Built-in services cover document parsing, document splitting, text embedding, query analysis, recall, ranking, performance evaluation, and large language model (LLM) services. You can select the component services that fit your needs to develop search applications.

  • In a Retrieval-Augmented Application (version 8.17), you can call model services through the Inference API to perform operations such as data processing, query rewrite, and text generation.

Billing

AI model services are billed by AI Search Open Platform based on the actual number of model calls. You are not charged if you do not use the service.

After charges are incurred, you can log on to the Expenses and Costs system to View bill details.

Prerequisites

Step 1: Activate and initialize AI models

Before you use AI models, activate the AI Search Open Platform service and complete the initialization. After this operation is performed, the system automatically generates the information required to call the models and creates the models in your application.

  1. Go to the application details page.

    1. Log on to the Elasticsearch Serverless console and switch to the desired region in the top navigation bar.

    2. In the left-side navigation pane, click Application Management. Then, click the name of the application that you created to go to the application details page.

  2. In the left-side navigation pane, click AI Service Center > Model Management to go to the Model Management page.

  3. Activate and initialize the AI model service:

    • If the currently logged-on account has not activated AI Search Open Platform, click Activate Service and Initialize Models on the Model Management page and follow the on-screen instructions to activate the AI model service. After activation, the system automatically performs the initialization: it generates the API key, model service namespace, and model service endpoint required to call the models, and registers this information with AI Search Open Platform. The system also creates the AI models supported by the Retrieval-Augmented Application (version 8.17), which you can call directly for data processing.

    • If the currently logged-on Alibaba Cloud account has already activated AI Search Open Platform, follow the on-screen instructions to initialize the models.

    • If the page indicates that some models were not created after the initialization is complete, find the corresponding models in the model list and click Create Model in the Actions column to create them.

    After the initialization is complete, the AI models supported by the Retrieval-Augmented Application (version 8.17) are displayed in the model list on the Model Management page.
Note

Activating AI Search Open Platform is free of charge. AI models are billed based on the number of calls. For more information, see .

Important

To make sure that the models can be called normally, do not delete or disable the generated model invocation information in AI Search Open Platform. Deleting this information makes the models in the Model List unavailable. For the AI models supported by the Retrieval-Augmented Application (version 8.17), see Model List.

Model invocation information

The model invocation information is described as follows:

  • Model Service Namespace: A namespace is used to isolate and manage data. After you activate AI Search Open Platform for the first time, the system automatically creates a default namespace named Default. You can also Create a workspace as needed.

    To use a custom namespace, switch to the namespace on the Model Management page and follow the on-screen instructions to initialize the models again. This makes sure that the system generates the API key required to call models in the current namespace and creates the AI models supported by the Retrieval-Augmented Application (version 8.17) in that namespace. You can use the models in a namespace only after model creation is complete.

  • Model Invocation API Key: When you call AI model-related APIs or software development kits (SDKs), you can use an API key for authentication to make sure that the calls are secure and reliable.

  • Model Service Endpoint: The Retrieval-Augmented Application (version 8.17) uses this private network address to access AI Search Open Platform and call the models. To call AI models over the public network, see Obtain a service endpoint.

    When the currently logged-on account activates AI Search Open Platform for the first time, the system automatically generates an API key and an endpoint. All applications under this account can use this API key and endpoint to call models.

Step 2: Call AI models in an application

After the models are initialized, you can call a suitable model for various scenarios, such as document content parsing, document splitting, and query analysis. This topic calls an AI model through Kibana to perform data inference operations.

Call an AI model

  1. On the Model Management page, click Access Kibana in the upper-right corner and follow the on-screen instructions to go to the Kibana interface.

  2. Click the image icon in the upper-left corner and choose Management > Dev Tools to go to the Kibana development page.

  3. Call an AI model. You can directly use the models created by the system in Kibana to perform data inference operations. The statement format for calling a model is as follows:

    POST _inference/<model_category_id>/<model_id>
    You can get the model category ID and the model ID from Model List.

Examples

Example 1: Query analysis

The following example calls the ops-query-analyze-001 model for query analysis.

POST _inference/query_analyze/ops-query-analyze-001

Example 2: Document analysis

Call the ops-document-analyze-001 model that the system automatically creates in Kibana to parse unstructured document data and convert it into structured data.

You can choose a synchronous call or an asynchronous call as needed. A synchronous call and an asynchronous call are the two execution modes of a document analysis task:

  • Synchronous call: After you submit a document analysis task, Elasticsearch Serverless immediately blocks the current request thread and waits for AI Search Open Platform to process the task. After the processing is complete, the result is returned directly to the client.

  • Asynchronous call: After you submit a document analysis task, Elasticsearch Serverless immediately returns a task ID without waiting for the processing result. The client must send a separate request to query the task status and the task result.

    The request template is as follows:
POST _inference/doc_analyze/ops-document-analyze-001
{
  "input": ["<document_url_or_content>"],
  "task_settings": {
    "document": {
      "input_type": "<url_or_content_or_task_id>",
      "file_name": "<optional_file_name>",
      "file_type": "<optional_file_type>"
    },
    "output": {
      "image_storage": "<base64_or_url>"
    },
    "is_async": "<true_or_false>"
  }
}

The following table describes the core parameters.

ParameterDescription
inputThe document to be parsed. The input can be a URL, content, or a task ID.
task_settingsThe task settings. All sub-parameters in task_settings are optional.
document.input_typeThe type of the document. Valid values: url (default): the web address of the document; the system retrieves the document information from this address. content: the content of the document. task_id: the ID that is used to query the result of a previous asynchronous task.
document.file_nameThe file name. If this parameter is left blank, the system infers the file name from the URL. If the URL is also blank, you must specify this parameter.
document.file_typeThe file type. If this parameter is left blank, the system infers the file type from the suffix of file_name. If the file type cannot be inferred, you must specify this parameter, such as .pdf, .doc, or .docx.
output.image_storageThe storage method of images. Valid values: base64 (default): converts an image into a Base64-encoded text string and embeds the string directly in the code. url: saves an image as an accessible URL; the URL is valid for 3 days.
is_asyncSpecifies whether this call is an asynchronous call. Valid values: true: an asynchronous call. false (default): a synchronous call.

Synchronous call example

After this operation is performed, the system directly returns the processing result.

POST _inference/doc_analyze/ops-document-analyze-001
{
  "input": ["http://opensearch-shanghai.oss-cn-shanghai.aliyuncs.com/chatos/rag/file-parser/samples/GB10767.pdf"]
}

The following is a sample response.

{
  "doc_analyze": {
    "data": {
      "content_type": "markdown",
      "page_num": 8,
      "content": "![IMAGE][IM0]\n\n# National Standard of the People's Republic of China\n\nGB 10767-2010\n\n# National Food Safety Standard for Older Infants and Young Children Formula\n\nNational food safety standard Older infants and young children formula\n\nIssued on 2010-03-26, implemented on 2011-04-01\n...\n"
    }
  }
}

Asynchronous call example

  1. Perform the call operation. The following is sample code:

    After this operation is performed, the system returns a task_id, which is the ID of the asynchronous task. You can use this ID to query the task result.

    POST _inference/doc_analyze/ops-document-analyze-001
    {
      "input": ["http://opensearch-shanghai.oss-cn-shanghai.aliyuncs.com/chatos/rag/file-parser/samples/GB10767.pdf"],
      "task_settings": {
        "document": {
          "input_type": "url"
        },
        "is_async": true
      }
    }

    {
      "doc_analyze": {
        "data": {},
        "task_id": "e0922ee0a6eba95b70e6f355fe8391bb"
      }
    }
  2. Get the asynchronous result. The input is the task_id returned in the previous step. The following is sample code:

    POST _inference/doc_analyze/ops-document-analyze-001
    {
      "input": ["e0922ee0a6eba95b70e6f355fe8391bb"],
      "task_settings": {
        "document": {
          "input_type": "task_id"
        },
        "is_async": true
      }
    }

    {
      "doc_analyze": {
        "data": {
          "content_type": "markdown",
          "page_num": 8,
          "content": "![IMAGE][IM0]\n\n# National Standard of the People's Republic of China\n\nGB 10767-2010\n\n# National Food Safety Standard for Older Infants and Young Children Formula\n\nNational food safety standard Older infants and young children formula\n\nIssued on 2010-03-26, implemented on 2011-04-01\n\n## Issued by the Ministry of Health of the People's Republic of China\n\n### Foreword\n\nThis standard corresponds to Codex Stan 156-1987 of the Codex Alimentarius Commission (CAC) ...\n...\n"
        }
      }
    }

Example 3: Document splitting

Call the ops-document-split-001 model that the system automatically creates in Kibana to split an input document.

The request template is as follows. input is the text content to be split.

Important

According to the JSON standard, if a String field contains the \\, \", \/, \b, \f, \n, \r, or \t character, the character must be escaped. JSON strings generated by common JSON libraries do not require manual escaping.

POST _inference/doc_split/ops-document-split-001
{
  "input":"<input>"
}

The following is an example call.

POST _inference/doc_split/ops-document-split-001
{
  "input":"Elasticsearch is an open-source search engine built on top of the Apache Lucene™ full-text search engine library. Lucene is arguably the most advanced, high-performance, and full-featured search engine library available today—whether open source or proprietary. But Lucene is just a library. To make full use of its features, you need to use Java and integrate Lucene directly into your application. Worse, you might need an information retrieval degree to understand how it works. Lucene is very complex. Elasticsearch is also written in Java and uses Lucene internally for indexing and searching, but its goal is to make full-text search simple by hiding the complexity of Lucene and providing a simple and consistent RESTful API instead. However, Elasticsearch is more than just Lucene, and it's more than just a full-text search engine. It can be accurately described as: a distributed, real-time document store where every field can be indexed and searched; a distributed, real-time analytics search engine; capable of scaling to hundreds of service nodes and supporting petabytes of structured or unstructured data. Elasticsearch packages all its features into a single service, so you can communicate with it through its simple RESTful API. You can use your favorite programming language as a web client, or even use the command line. With Elasticsearch, getting started is easy. For beginners, it provides sensible defaults and hides complex search theory. It works out of the box. Just a little understanding is needed to quickly become productive. As your knowledge grows, you can leverage more of Elasticsearch's advanced features. Its entire engine is configurable and flexible. You can pick and choose from its many advanced features to tailor Elasticsearch to solve your specific problems. You can download, use, and modify Elasticsearch for free. It is released under the Apache 2 license, one of the most flexible open-source licenses. The source code for Elasticsearch is hosted on Github at github.com/elastic/elasticsearch. If you want to join our amazing community of contributors, see Contributing to Elasticsearch. If you have any questions about Elasticsearch, including specific features, language clients, or plugins, you can join the discussion at discuss.elastic.co."
}

The following is a sample response.

{
  "doc_split": {
    "rich_texts": [],
    "nodes": [
      {
        "parent_id": "cfe3181f03344e208a6e63efd4a674ff",
        "id": "cfe3181f03344e208a6e63efd4a674ff",
        "type": "root"
      },
      {
        "parent_id": "cfe3181f03344e208a6e63efd4a674ff",
        "id": "7574e031dd8c4880b42975f601783305",
        "type": "sentence_node"
      },
      {
        "parent_id": "cfe3181f03344e208a6e63efd4a674ff",
        "id": "8ca382cf6d8f4cb38f4a2f6433de47af",
        "type": "sentence_node"
      }
    ],
    "chunks": [
      {
        "meta": {
          "parent_id": "cfe3181f03344e208a6e63efd4a674ff",
          "hierarchy": [],
          "id": "7574e031dd8c4880b42975f601783305",
          "type": "text",
          "token": 298
        },
        "content": "Elasticsearch is an open-source search engine built on top of the Apache Lucene™ full-text search engine library. Lucene is arguably the most advanced, high-performance, and full-featured search engine library available today—whether open source or proprietary. But Lucene is just a library. To make full use of its features, you need to use Java and integrate Lucene directly into your application. Worse, you might need an information retrieval degree to understand how it works. Lucene is very complex. Elasticsearch is also written in Java and uses Lucene internally for indexing and searching, but its goal is to make full-text search simple by hiding the complexity of Lucene and providing a simple and consistent RESTful API instead. However, Elasticsearch is more than just Lucene, and it's more than just a full-text search engine. It can be accurately described as: a distributed, real-time document store where every field can be indexed and searched; a distributed, real-time analytics search engine; capable of scaling to hundreds of service nodes and supporting petabytes of structured or unstructured data. Elasticsearch packages all its features into a single service, so you can communicate with it through its simple RESTful API. You can use your favorite programming language as a web client, or even use the command line. With Elasticsearch, getting started is easy. For beginners, it provides sensible defaults and hides complex search theory. It works out of the box."
      },
      {
        "meta": {
          "parent_id": "cfe3181f03344e208a6e63efd4a674ff",
          "hierarchy": [],
          "id": "8ca382cf6d8f4cb38f4a2f6433de47af",
          "type": "text",
          "token": 160
        },
        "content": "Just a little understanding is needed to quickly become productive. As your knowledge grows, you can leverage more of Elasticsearch's advanced features. Its entire engine is configurable and flexible. You can pick and choose from its many advanced features to tailor Elasticsearch to solve your specific problems. You can download, use, and modify Elasticsearch for free. It is released under the Apache 2 license, one of the most flexible open-source licenses. The source code for Elasticsearch is hosted on Github at github.com/elastic/elasticsearch. If you want to join our amazing community of contributors, see Contributing to Elasticsearch. If you have any questions about Elasticsearch, including specific features, language clients, or plugins, you can join the discussion at discuss.elastic.co."
      }
    ],
    "sentences": []
  }
}

Example 4: Text embedding

Call the ops-text-embedding-001 model that the system automatically creates in Kibana to convert input text into numerical vectors. The output vectors capture the semantic information of the text, which is useful for downstream tasks such as similarity calculation, clustering, and classification.

The request template is as follows. input is the input text content.

Each request supports a maximum of 32 texts. Each text can be up to 300 tokens long, and empty strings are not supported. The text length supported by different text embedding models varies. For more information, see Model List.

POST _inference/text_embedding/ops-text-embedding-001
{
  "input":[<input>]
}

The following is an example call.

POST _inference/text_embedding/ops-text-embedding-001
{
  "input":["Science and technology are the primary productive force",
        "Elasticsearch product documentation"]
}

The following is a sample response.

{
  "text_embedding": [
    {
      "embedding": [
        -0.029408421,
        0.061318535,
        ... 
        ]
    },
    {
      "embedding": [
        0.01568979,
        0.065073475,
        ...
        ]
    }
  ]
}

Appendix 1: Supported Inference APIs

The following table lists the Inference APIs supported by the Retrieval-Augmented Application (version 8.17).

APIDescription
DOCUMENT ANALYZE (document content parsing)Extracts logical hierarchy structures such as titles and paragraphs, as well as text, tables, and images, from unstructured documents, and outputs the information in a structured format.
IMAGE ANALYZE (image content extraction)Provides an image content analysis service that parses image content and recognizes text based on a multimodal large model. Also provides an image content optical character recognition (OCR) service that recognizes and extracts text from images based on OCR capabilities.
SPLIT_DOC (document chunking)Provides a general-purpose text splitting strategy. It splits structured data in HTML, Markdown, or TXT format based on document paragraph formatting, text semantics, or specified rules. It also supports extracting code, images, and tables from rich text.
TEXT_EMBEDDING (text embedding)Converts text data into dense vector representations, which can be used in scenarios such as information retrieval, text classification, and similarity comparison.
SPARSE_EMBEDDING (sparse text embedding)Converts text data into sparse vector representations. Sparse vectors require less storage space and are commonly used to express keyword and term frequency information. They can be paired with dense vectors for hybrid retrieval to improve retrieval performance.
QUERY ANALYZE (query analysis)Provides a query content analysis service. Based on large language models and NLP capabilities, it performs intent recognition, similar question expansion, and natural language to SQL (NL2SQL) processing on your input queries, which effectively improves retrieval and question answering in RAG scenarios.
RERANK (re-ranking service)Provides a general-purpose document scoring capability. It sorts documents in descending order of score based on the relevance between the query and the document content, and outputs the corresponding scoring results.
COMPLETION (content generation service)Calls a RAG-dedicated large model service that is fine-tuned on Alibaba's self-developed model foundation. It can be combined with document processing and retrieval services, and is widely used in RAG scenarios to improve answer accuracy and reduce the hallucination rate.

Appendix 2: Model list

The following table lists the AI models integrated into the Retrieval-Augmented Application (version 8.17).

Model categoryModel category IDModel IDModel description
Large model servicecompletiondeepseek-r1A large language model focused on complex reasoning tasks. It performs well in understanding complex instructions and in result accuracy.
deepseek-r1-distill-qwen-14bA model generated by applying knowledge distillation and using the training samples generated by DeepSeek-R1 to fine-tune Qwen-14B.
deepseek-r1-distill-qwen-7bA model generated by applying knowledge distillation and using the training samples generated by DeepSeek-R1 to fine-tune Qwen-7B.
deepseek-v3A Mixture-of-Experts (MoE) model that performs well on long text, code, mathematics, encyclopedic knowledge, and Chinese.
ops-qwen-turboUses the Qwen-Turbo large language model as its foundation and applies supervised fine-tuning to strengthen retrieval capabilities and reduce harmfulness.
qwen-maxQwen 2.0, a large language model with hundreds of billions of parameters. It supports input in different languages, such as Chinese and English.
qwen-plusAn enhanced version of the Qwen large language model. It supports input in different languages, such as Chinese and English.
qwen-turboThe Qwen large language model. It supports input in different languages, such as Chinese and English.
Multimodal embeddingmulti_modal_embeddingops-gme-qwen2-vl-2b-instructA multimodal embedding service trained on the Qwen2-VL multimodal large language models (MLLMs). It supports single-modal and multimodal combined input, and efficiently processes text, images, and combined data types.
ops-m2-encoderA bilingual (Chinese and English) multimodal service. It is trained on BM-6B with 6 billion image-text pairs (3 billion pairs for each language). The model supports cross-modal image-text retrieval (including text-to-image search and image-to-text search) and image classification tasks.
ops-m2-encoder-largeA bilingual (Chinese and English) multimodal service. Compared with the ops-m2-encoder model, it has a larger number of parameters, reaching 1B (1 billion parameters), which provides stronger expressive power and better performance in multimodal task processing.
Rerankingrerankops-bge-reranker-largerProvides a document scoring service based on the BGE model. It sorts documents (Doc) in descending order of score based on the relevance between the query (Query) and the document content, and outputs the corresponding scoring results. Supports Chinese and English. The maximum supported input token length is 512 tokens (the length of Query + Doc).
ops-text-reranker-001A reranking model developed by OpenSearch. It is trained on datasets from multiple industries to provide a high-standard reranking service, and sorts documents in descending order based on the semantic relevance between the query (Query) and the documents (Doc). Supports Chinese and English. The maximum supported input token length is 1,024 tokens (the length of Query + Doc).
Document content analysisdoc_analyzeops-document-analyze-001Provides a general-purpose document parsing service. It extracts logical hierarchy structures such as titles and paragraphs, as well as text, tables, and images, from unstructured documents, and outputs the information in a structured format.
Document splittingdoc_splitops-document-split-001Provides a general-purpose text splitting strategy. It splits structured data in HTML, Markdown, or TXT format based on document paragraph formatting, text semantics, or specified rules. It also supports extracting code, images, and tables from rich text.
Image content analysisimg_analyzeops-image-analyze-ocr-001Provides an image content optical character recognition (OCR) service. It recognizes and extracts text from images based on OCR capabilities, for use in scenarios such as image retrieval and question answering.
ops-image-analyze-vlm-001Provides an image content analysis service. It parses image content and recognizes text based on a multimodal large model. The parsed text can be used in scenarios such as image retrieval and question answering.
Query analysisquery_analyzeops-query-analyze-001Provides a general-purpose query analysis service. Based on a large language model, it performs intention recognition and similar question expansion on your input query.
Text embeddingtext_embeddingops-text-embedding-001Provides text embedding services for more than 40 languages. The maximum input text length is 300 tokens, and the output vector dimensions are 1536.
ops-text-embedding-002Provides text embedding services for more than 100 languages. The maximum input text length is 8192 tokens, and the output vector dimensions are 1024.
ops-text-embedding-en-001Provides an English text embedding service. The maximum input text length is 512 tokens, and the output vector dimensions are 768.
ops-text-embedding-zh-001Provides a Chinese text embedding service. The maximum input text length is 1024 tokens, and the output vector dimensions are 768.
Text sparse embeddingsparse_embeddingops-text-sparse-embedding-001Provides text embedding services for more than 100 languages. The maximum input text length is 8192 tokens.

References

For more information about AI search and its scenario-based applications, see: