Retrieval-augmented generation

更新时间:
复制 MD 格式

The search API now supports Q&A with large models based on retrieved search results.

URL

/v3/openapi/apps/$app_name/rag?fetch_fields=name&query=config=format:fulljson&&query=name:'opensearch'&&sort=id&&raw_query="opensearch"&&chat={"name":"chat_test","prompt_parameters":{"param":"value"}}

  • $app_name: The name of your application. The Premium and Standard editions support multiple applications and require an application name for access. This applies to applications that are in service. You can also use an offline application ID to access the offline search service.

    image

  • The preceding URL omits request headers, encoding, and other parameters.

  • The preceding URL omits the host address of the application.

  • For definitions, usage details, and examples of all query parameters in the URL, see the Query parameters section below.

Request protocol

Request method

Supported format

HTTP

JSON

Request parameters

For more information about the rules for concatenating query parameters, see the V3 API signature mechanism document.

This section describes the parameters that are specific to the Retrieval-Augmented Generation (RAG) API. All other parameters are the same as those for the Search processing API.

Parameter

Type

Required

Default value

Description

chat

String

Yes

The configurations for intelligent dialogue. The value must be in JSON format and URL-encoded. The configurations include the name of the intelligent dialogue configuration to use and the assignments for custom variables in the prompt template. For more information, see Prompt Management.

raw_query

String

Yes

This parameter is required for the RAG API. It is used as the built-in `{question}` variable in the prompt template, which represents the original query entered by the user.

fetch_fields

String

No

All displayable fields.

The fields to retrieve in the query. Separate multiple fields with a semicolon (;). Note: This parameter must include the input fields specified in the context parameters of the intelligent conversation configuration. You can omit this parameter if the default display fields already include the required fields.

Request example

http://host/v3/openapi/apps/$app_name/rag?fetch_fields=name&query=config=format:fulljson&&query=name:'opensearch'&&sort=id&&raw_query="opensearch"&&chat={"name":"chat_test","prompt_parameters":{"param":"value"}}

Result

The response is returned as a streaming output:

  1. The first response contains only the search results, similar to the response from the search API.

    {
      "status": "OK",
      "request_id": "c7e8c3fc1d3886050d7a58fee19964ca",
      "result": {
        "searchtime": 0.02588,
        "total": 1,
        "num": 1,
        "viewtotal": 1,
        "compute_cost": [
        ],
        "items": [{...}],
        "facet": []
      }
    }

  2. Intermediate responses contain only the conversation content. The `result` object is empty.

    {
      "status": "OK",
      "request_id": "c7e8c3fc1d3886050d7a58fee19964ca",
      "result": {},
      "chat": {
        "text": "",
      }
    }

  3. The final response contains all content, including the rendered `prompt`.

    {
      "status": "OK",
      "request_id": "c7e8c3fc1d3886050d7a58fee19964ca",
      "result": {
        "searchtime": 0.02588,
        "total": 1,
        "num": 1,
        "viewtotal": 1,
        "compute_cost": [
        ],
        "items": [{...}],
        "facet": []
      },
      "chat": {
        "text": "",
        "prompt": ""
      }
    }

Response parameters

Parameter

Type

Description

status

String

The execution result. `OK` indicates success. `FAIL` indicates failure. If the request fails, troubleshoot the issue based on the returned error code.

request_id

String

The ID of the query record. This is mainly used for troubleshooting.

result

JSON

The actual result, which includes the query time (`searchtime`), total results from the engine (`total`), number of results in this response (`num`), maximum results for the query (`viewtotal`), query results (`items`), and facet statistics (`facet`).

errors

List

The error code and the error message, which is specified in the `message` parameter. For more information about the `code` parameter, see Error Code Description.

chat

JSON

The result of the intelligent conversation.

chat.text

String

The content of the model's response.

Error codes

Error code

Description

6044

Invalid conversation parameters.

6045

A required conversation field is missing from the `fetch_fields` parameter.

6046

The `raw_query` parameter is missing.

6047

The conversation configuration does not exist.

2101

The workspace does not exist.

2102

The conversation configuration does not exist.

4031

The API key does not exist.

4032

The API key is disabled.

4040

Invalid request content. The request contains sensitive words.

6015

Request throttled.