Custom models

更新时间:
复制 MD 格式

OpenSearch Vector Search Edition supports custom models. On this page, you can add, view, edit, debug, disable, and restore your custom models.

Create a model

Navigate to Model Management > Custom Models and click Create Model.

In the dialog box that appears, use the JSON editor to fill in the configuration template. The main fields include modelName, request (which contains header, parameters, and method), response, modelType, and url. After you configure the model, click OK.

Custom model format

{
  "modelName": "custom_model",
  "modelType": "text_embedding",
  "dimension": 1536,
  "url": "http://xxx/api/v2/services/embeddings",
  "method": "POST",
  "request": {
    "header": {
      "Authorization": "fj42091fjlgnlsvu023nva",
      "Content-Type": "application/json"
    },
    "urlParams": {
      "build": {},
      "search": {}
    },
    "requestBody": "{\"input\": [\"%{input}\"], \"input_type\": \"${input_type}\"}",
    "parameters": {
      "build": {
        "input_type": "document"
      },
      "search": {
        "input_type": "query"
      }
    }
  },
  "response": {
    "embeddings": "$.result.embeddings[*].embedding"
  }
}

Parameters

Parameter

Description

modelName

The name of the model.

modelType

The type of the model. You can set this parameter to one of the following values:

  • text_embedding: A dense text model.

  • text_sparse_embedding: A sparse text model.

  • image_embedding: An image vector model.

  • image_analyze: An image content analysis model.

dimension

The dimension of the vectors generated by the model. This parameter is required when modelType is set to text_embedding or image_embedding.

url

The model service endpoint.

method

The HTTP method for accessing the model service. Supported methods are POST and PUT.

request

Defines the request sent to the model service.

request.header

The HTTP request headers. These headers are passed to the model service unchanged.

request.urlParams

The parameters to include in the URL. Some model services require parameters to be passed in the URL, such as ?abc=123.

request.urlParams.build

Parameters passed during the index creation phase.

request.urlParams.search

Parameters passed during the query phase.

request.requestBody

A template string for the request body.

  • Template variable format:

    %{parameter_name}. For example: {"input": "%{input}"}

  • Built-in variables:

    • %{input}: Represents the input text.

    • %{modal}: Represents the modality. Use this variable with a multimodal model to specify the modality in your query.

request.parameters

Defines phase-specific request body parameters. Use this if you need different parameters for the index creation and query phases.

  • build: Parameters for the index creation phase.

  • search: Parameters for the query phase.

response

Specifies how to parse the model service response using a JSONPath expression.

JSONPath

Operators

Operator

Description

$

Represents the root element. A path must start with $.

*

A wildcard that matches any value. It can be used in place of a property name or an array index.

.<name>

Selects an object property.

[<number>]

Selects an array element by its index.

Example

{
  "store": {
    "books": [
      {
        "title": "java",
        "price": 56
      },
      {
        "title": "c++",
        "price": 99
      }
    ]
  }
}
  • To extract the titles of all books:

    • JSONPath: $.store.books[*].title

    • Result: ["java", "c++"]

  • To extract the title of the first book:

    • JSONPath: $.store.books[0].title

    • Result: ["java"]

Model management

  • Debug: On the Models > Custom Models page, click Debug in the Actions column to test your model.

  • Disable: Disabling a model prevents tables that use it from processing data and queries. Proceed with caution.

  • Delete: You can only delete models that are disabled.

  • Restore: You can restore a disabled model.

Calling models

When you configure a table, click Configure for the field that requires data preprocessing. You can then select your custom model from the Model list.

In the Model drop-down list, built-in models are listed at the top. Your custom models appear at the bottom of the list and are prefixed with Custom, for example, "Custom test1".