Todos los productos
Search
Centro de documentos

:Aplicable a versiones de imagen v0.3.0 a v0.3.4

Última actualización: Sep 04, 2026

PAI-RAG ofrece un conjunto completo de operaciones de API para funciones como gestión de servicios, gestión de bases de conocimiento y chat. Este tema describe las operaciones de API y los métodos de invocación para los servicios RAG desplegados con versiones de imagen v0.3.0 a v0.3.4.

Límites

Este tema aplica únicamente a servicios RAG desplegados con versiones de imagen v0.3.0 a v0.3.4.

Vaya a la página de Elastic Algorithm Service (EAS), haga clic en el nombre del servicio RAG y luego busque la versión de la imagen en la sección Environment Information de la página Overview.

Obtención del endpoint y token del servicio

Antes de invocar un servicio RAG mediante una operación de API, debe obtener el endpoint y el token del servicio:

  1. Inicie sesión en la PAI console. Seleccione una región en la parte superior de la página. A continuación, seleccione el espacio de trabajo deseado y haga clic en Elastic Algorithm Service (EAS).

  2. Haga clic en el nombre del servicio objetivo. En la sección Basic Information, haga clic en View Endpoint Information.

  3. En la página Invocation Method, obtenga el endpoint del servicio (EAS_SERVICE_URL) y el token (EAS_Token).

    Importante
    • Elimine la barra diagonal (/) al final de EAS_SERVICE_URL.

    • Invocación del servicio mediante un endpoint público: El cliente debe tener acceso a Internet.

    • Invocación del servicio mediante un endpoint de VPC: El cliente debe estar en la misma nube privada virtual (VPC) que el servicio RAG.

API de chat

Puede invocar el servicio mediante la operación de API compatible con OpenAI. Antes de llamar al servicio, debe configurar las funciones requeridas en la WebUI del servicio RAG.

Funciones compatibles

  • web search: Realiza búsquedas en la web. Debe configurar los parámetros de búsqueda web en la WebUI del servicio RAG con antelación.

  • chat knowledgebase: Consulta una base de conocimiento. Debe cargar los archivos de la base de conocimiento previamente.

  • chat llm: Utiliza un modelo de lenguaje grande (LLM) para proporcionar respuestas. Debe configurar un servicio LLM con antelación.

  • chat agent: Invoca herramientas mediante el agente. Debe configurar el código relacionado con el agente en la WebUI del servicio RAG con antelación.

  • chat db: Consulta una base de datos o tabla. Debe configurar los ajustes de análisis de datos en la WebUI del servicio RAG con antelación.

Método de invocación

URL

{EAS_SERVICE_URL}/v1/chat/completions

Método de solicitud

POST

Encabezados de solicitud

Authorization: EAS_TOKEN (El token para la llamada a EAS)

Cuerpo HTTP

{
    "model": "default",  # The model name. Set this to default or a model name that is configured on the WebUI. 
    "messages": [
        {"role": "user", "content": "Hello"},
        {"role": "assistant", "content": "Hello, how can I help you?"},
        {"role": "user", "content": "What is the capital of Zhejiang?"},
        {"role": "assistant", "content": "Hangzhou is the capital of Zhejiang."},
        {"role": "user", "content": "What are some fun places to visit?"},
    ],
    "stream": true,  # Specifies whether to enable streaming output.
    "chat_knowledgebase": true,  # Specifies whether to query the local knowledge base.
    "search_web": false,  # Specifies whether to use web search.
    "chat_llm": false,  # Specifies whether to use only the LLM for chat.
    "chat_agent": false,  # Specifies whether to use the agent.
    "chat_db": false,  # Specifies whether to query the database.
    "index_name": "default",  # The index name for RAG scenarios. You can specify only one index name. If you do not specify an index name, the system uses the default index.
    "max_tokens": 1024,  # The maximum output length, such as 1024.
    "temperature": 0.1,  # Controls the randomness of the generated content. The value must be in the range of [0, 1]. A smaller value indicates more deterministic content. A larger value indicates more diverse content.
}
Importante
  • Si habilita varias funciones simultáneamente, el sistema las invoca según la siguiente prioridad, de mayor a menor: search_web, chat_knowledgebase, chat_agent, chat_db y chat_llm. Para cada función, el sistema realiza un reconocimiento de intención para determinar si debe invocar la función o utilizar directamente el LLM para generar una respuesta.

  • Si todos los indicadores de función se establecen en false o no se pasan, el servicio consulta la base de conocimiento local de forma predeterminada (es decir, "chat_knowledgebase": true).

Ejemplo de solicitud (haga clic para ver detalles)

Búsqueda web

from openai import OpenAI
##### API configuration #####
# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
openai_api_key = "<EAS_TOKEN>"
openai_api_base = "<EAS_SERVICE_URL>/v1"
client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)
#### Chat ######
def chat():
    stream = True
    chat_completion = client.chat.completions.create(
        model="default",
        stream=stream,
        messages=[
            {"role": "user", "content": "Hello"},
            {"role": "assistant", "content": "Hello, how can I help you?"},
            {"role": "user", "content": "What is the capital of Zhejiang?"},
            {"role": "assistant", "content": "Hangzhou is the capital of Zhejiang."},
            {"role": "user", "content": "What are some fun places to visit?"},
        ],
        extra_body={
            "search_web": True,
        },
    )
    if stream:
        for chunk in chat_completion:
            print(chunk.choices[0].delta.content, end="")
    else:
        result = chat_completion.choices[0].message.content
        print(result)
chat()

Consulta de una base de datos

from openai import OpenAI
##### API configuration #####
# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
openai_api_key = "<EAS_TOKEN>"
openai_api_base = "<EAS_SERVICE_URL>/v1"
client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)
#### Chat ####
def chat():
    stream = True
    chat_completion = client.chat.completions.create(
        model="default",
        stream=stream,
        messages=[
            {"role": "user", "content": "How many cats are there?"},
            {"role": "assistant", "content": "There are 2 cats."},
            {"role": "user", "content": "And dogs?"},
        ],
        extra_body={
            "chat_db": True,
        },
    )
    if stream:
        for chunk in chat_completion:
            print(chunk.choices[0].delta.content, end="")
    else:
        result = chat_completion.choices[0].message.content
        print(result)
chat()

API de base de conocimiento

Agregar una base de conocimiento

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN

  • Content-Type: application/json

Parámetros de solicitud

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with the name of your knowledge base. Update vector_store_config with your vector database configuration. 
curl -X 'POST' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name> \
-H 'Authorization: <EAS_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
      "name":"<name>",
      "vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"milvus",
          "is_image_store":false,
          "host":"c-exxx11f4c.milvus.aliyuncs.com",
          "port":19530,
          "user":"root",
          "password":"xxx",
          "database":"default",
          "collection_name":"test",
          "reranker_weights":[0.5,0.5]
      },
      "embedding_config":
      {
          "source":"huggingface",
          "model":"bge-m3",
          "embed_batch_size":10,
          "enable_sparse":false
      }
  }'

El código anterior muestra un ejemplo de uso de Milvus para el parámetro vector_store_config. Las siguientes secciones describen las configuraciones de vector_store_config para otras bases de datos vectoriales.

faiss

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"faiss",
          "is_image_store":false
      }

hologres

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"hologres",
          "is_image_store":false,
          "host":"xxx",
          "port":xxx,
          "user":"xxx",
          "password":"xxx",
          "database":"default",
          "table_name":"test",
          "pre_delete_table":"false"
      }

elasticsearch

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"elasticsearch",
          "is_image_store":false,
          "es_url":"xxx",
          "es_user":"xxx",
          "es_password":"xxx",
          "es_index":"xxx"
      }

opensearch

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"opensearch",
          "is_image_store":false,
          "endpoint":"xxx",
          "instance_id":"xxx",
          "username":"xxx",
          "password":"xxx",
          "table_name":"xxx"
      }

analyticdb

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"analyticdb",
          "is_image_store":false,
          "ak":"xxx",
          "sk":"xxx",
          "region_id":"xxx",
          "instance_id":"xxx",
          "account":"xxx",
          "account_password":"xxx",
          "namespace":"xxx",
          "collection":"xxx"
      }

tablestore

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"tablestore",
          "is_image_store":false,
          "endpoint":"xxx",
          "instance_name":"xxx",
          "access_key_id":"xxx",
          "access_key_secret":"xxx",
          "table_name":"xxx"
      }

dashvector

"vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"dashvector",
          "is_image_store":false,
          "endpoint":"xxx",
          "api_key":"xxx",
          "collection_name":"xxx",
          "partition_name":"xxx"
      }

Ejemplo de respuesta (haga clic para ver detalles)

{ "msg": "Add knowledgebase 'xxx' successfully." }

Listar bases de conocimiento

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases

Método de solicitud

GET

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic para ver detalles)

{
  "knowledgebases": {
    "default": {
      "name": "default",
      "vector_store_config": {
        "persist_path": "./localdata/knowledgebase/default/.index/.faiss",
        "type": "milvus",
        "is_image_store": false,
        "host": "c-exxx1911f4c.milvus.aliyuncs.com",
        "port": 19530,
        "user": "root",
        "password": "xxx",
        "database": "default",
        "collection_name": "test",
        "reranker_weights": [0.5, 0.5]
      },
      "embedding_config": {
        "source": "huggingface",
        "model": "bge-m3",
        "embed_batch_size": 10,
        "enable_sparse": false
      },
      "knowledgebase_paths": {
        "base_path": "localdata/knowledgebase/default",
        "docs_path": "localdata/knowledgebase/default/docs",
        "index_path": "localdata/knowledgebase/default/.index",
        "logs_path": "localdata/knowledgebase/default/.logs",
        "parse_path": "localdata/knowledgebase/default/.index/parse",
        "split_path": "localdata/knowledgebase/default/.index/split",
        "embed_path": "localdata/knowledgebase/default/.index/embed",
        "faiss_index_path": "localdata/knowledgebase/default/.index/.faiss",
        "doc_ids_map_file": "localdata/knowledgebase/default/.index/file_to_docid_map.json"
      }
    },
    "my_milvus": {
      "name": "my_milvus",
      "vector_store_config": {
        "persist_path": "./localdata/knowledgebase/default/.index/.faiss",
        "type": "milvus",
        "is_image_store": false,
        "host": "c-e6xxx11f4c.milvus.aliyuncs.com",
        "port": 19530,
        "user": "root",
        "password": "xxx",
        "database": "default",
        "collection_name": "test",
        "reranker_weights": [0.5, 0.5]
      },
      "embedding_config": {
        "source": "huggingface",
        "model": "bge-m3",
        "embed_batch_size": 10,
        "enable_sparse": false
      },
      "knowledgebase_paths": {
        "base_path": "localdata/knowledgebase/my_milvus",
        "docs_path": "localdata/knowledgebase/my_milvus/docs",
        "index_path": "localdata/knowledgebase/my_milvus/.index",
        "logs_path": "localdata/knowledgebase/my_milvus/.logs",
        "parse_path": "localdata/knowledgebase/my_milvus/.index/parse",
        "split_path": "localdata/knowledgebase/my_milvus/.index/split",
        "embed_path": "localdata/knowledgebase/my_milvus/.index/embed",
        "faiss_index_path": "localdata/knowledgebase/my_milvus/.index/.faiss",
        "doc_ids_map_file": "localdata/knowledgebase/my_milvus/.index/file_to_docid_map.json"
      }
    }
  }
}

Cargar un archivo de base de conocimiento

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}/files

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: multipart/form-data

Parámetros de solicitud

  • files: El archivo.

  • name: El nombre de la base de conocimiento, por ejemplo, my_milvus.

Ejemplo de solicitud cURL (haga clic para ver detalles)

  • Cargar un solo archivo (use -F 'files=@path' para cargar el archivo)

    # Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
    # Replace <name> with the name of your knowledge base. 
    # Replace the path after "-F 'files=@" with your knowledge base file path. 
    curl -X 'POST' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files \
    -H 'Authorization: <EAS_TOKEN>' \
    -H 'Content-Type: multipart/form-data' \
    -F 'files=@example_data/paul_graham/paul_graham_essay.txt'
  • Cargar varios archivos

    Utilice múltiples parámetros -F 'files=@path'. Cada parámetro corresponde a un archivo para cargar. Por ejemplo:

    # Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
    # Replace <name> with the name of your knowledge base. 
    # Replace the path after "-F 'files=@" with your knowledge base file path.
    curl -X 'POST' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files \
    -H 'Authorization: <EAS_TOKEN>' \
    -H 'Content-Type: multipart/form-data' \
    -F 'files=@example_data/paul_graham/paul_graham_essay.txt' \
    -F 'files=@example_data/another_file1.md' \
    -F 'files=@example_data/another_file2.pdf' \

Ejemplo de respuesta (haga clic para ver detalles)

{ "message": "Files have been successfully uploaded." }

Obtener el estado de carga

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1//knowledgebases/{name}/files/{file_name}

Método de solicitud

GET

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Parámetros de solicitud

  • file_name: El nombre del archivo.

  • name: El nombre de la base de conocimiento, por ejemplo, my_milvus.

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with your knowledge base name and <file_name> with your file name. 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files/<file_name> -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic para ver detalles)

{
  "task_id": "50fe181921a83edf63b5ecaa487e****",
  "operation": "UPDATE",
  "file_name": "localdata/knowledgebase/my_milvus/docs/paul_graham_essay.txt",
  "status": "done",
  "message": null,
  "last_modified_time": "2025-03-12 11:50:37"
}

Obtener el historial de cargas

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}/history

Método de solicitud

GET

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Parámetros de solicitud

name: El nombre de la base de conocimiento, por ejemplo, my_milvus.

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with the name of your knowledge base. 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/history -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic para ver detalles)

[
  {
    "task_id": "50fe181921a83edf63b5ecaa487e****",
    "operation": "UPDATE",
    "file_name": "localdata/knowledgebase/my_milvus/docs/paul_graham_essay.txt",
    "status": "done",
    "message": null,
    "last_modified_time": "2025-03-12 11:50:37"
  },
  {
    "task_id": "0162e61cbe605ddab865fff5f7d8****",
    "operation": "ADD",
    "file_name": "localdata/knowledgebase/my_milvus/docs/demo.pdf",
    "status": "failed",
    "message": "Error loading file",
    "last_modified_time": "2025-03-12 13:46:11"
  }
]

Listar archivos de la base de conocimiento

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}/files

Método de solicitud

GET

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Parámetros de solicitud

name: El nombre de la base de conocimiento, por ejemplo, my_milvus.

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with the name of your knowledge base. 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic para ver detalles)

[
  {
    "file_name": "localdata/knowledgebase/my_milvus/docs/paul_graham_essay.txt",
    "doc_id": "50fe181921a83edf63b5ecaa487e****",
    "last_modified_time": "2025-03-12 14:38:51"
  }
]

Eliminar un archivo de la base de conocimiento

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}/files/{file_name}

Método de solicitud

DELETE

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Parámetros de solicitud

  • file_name: El nombre del archivo.

  • name: El nombre de la base de conocimiento, por ejemplo, my_milvus.

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with your knowledge base name. Replace <file_name> with the name of the file to delete. 
curl -X 'DELETE' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files/<file_name> -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic para ver detalles)

{ "message": "File 'paul_graham_essay.txt' have been successfully removed." }

Obtener información sobre una base de conocimiento

Método de invocación

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}

Método de solicitud

GET

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Parámetros de solicitud

name: El nombre de la base de conocimiento, por ejemplo, my_milvus.

Ejemplo de solicitud cURL (haga clic para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with the name of your knowledge base. 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name> -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic para ver detalles)

{
  "name": "my_milvus",
  "vector_store_config": {
    "persist_path": "./localdata/knowledgebase/default/.index/.faiss",
    "type": "milvus",
    "is_image_store": false,
    "host": "c-exxx1****.milvus.aliyuncs.com",
    "port": 19530,
    "user": "root",
    "password": "xxx",
    "database": "default",
    "collection_name": "test",
    "reranker_weights": [0.5, 0.5]
  },
  "embedding_config": {
    "source": "huggingface",
    "model": "bge-m3",
    "embed_batch_size": 10,
    "enable_sparse": false
  },
  "knowledgebase_paths": {
    "base_path": "localdata/knowledgebase/my_milvus",
    "docs_path": "localdata/knowledgebase/my_milvus/docs",
    "index_path": "localdata/knowledgebase/my_milvus/.index",
    "logs_path": "localdata/knowledgebase/my_milvus/.logs",
    "parse_path": "localdata/knowledgebase/my_milvus/.index/parse",
    "split_path": "localdata/knowledgebase/my_milvus/.index/split",
    "embed_path": "localdata/knowledgebase/my_milvus/.index/embed",
    "faiss_index_path": "localdata/knowledgebase/my_milvus/.index/.faiss",
    "doc_ids_map_file": "localdata/knowledgebase/my_milvus/.index/file_to_docid_map.json"
  }
}

Actualizar una base de conocimiento

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}

Método de solicitud

PATCH

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: application/json

Parámetros de solicitud

  • name: El nombre de la base de conocimiento, por ejemplo, new_milvus.

  • vector_store_config: La configuración de la base de conocimiento.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with the name of your knowledge base. 
# Set vector_store_config to the configuration of the knowledge base that you want to update. 
curl -X 'PATCH' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name> \
-H 'Authorization: <EAS_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
      "name":"<name>",
      "vector_store_config":
      {
          "persist_path":"./localdata/knowledgebase/default/.index/.faiss",
          "type":"milvus",
          "is_image_store":true,
          "host":"c-exxx11f4c.milvus.aliyuncs.com",
          "port":19530,
          "user":"root",
          "password":"xxx",
          "database":"default",
          "collection_name":"test",
          "reranker_weights":[0.5,0.5]
      },
      "embedding_config":
      {
          "source":"huggingface",
          "model":"bge-m3",
          "embed_batch_size":10,
          "enable_sparse":false
      }
  }'

El código anterior muestra un ejemplo de uso de Milvus para el parámetro vector_store_config. Para obtener más información sobre las configuraciones de vector_store_config para otras bases de datos vectoriales, consulte Add a knowledge base.

Ejemplo de respuesta (haga clic en para ver detalles)

{ "msg": "Update knowledgebase 'new_milvus' successfully." }

Eliminar una base de conocimiento

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/knowledgebases/{name}

Método de solicitud

DELETE

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Parámetros de solicitud

name: El nombre de la base de conocimiento, por ejemplo, new_milvus.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace <name> with the name of your knowledge base. 
curl -X 'DELETE' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name> -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic en para ver detalles)

{ "msg": "Delete knowledgebase 'new_milvus' successfully." }

Recuperar datos de una base de conocimiento

v0.3.0-v0.3.3

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/query/retrieval

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: application/json

Parámetros de solicitud

  • question: La consulta del usuario.

  • index_name: El nombre de la base de conocimiento. El valor predeterminado es default.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Set question to the user's query. 
# Set index_name to the name of the knowledge base. 
  curl -X 'POST' '<EAS_SERVICE_URL>/api/v1/query/retrieval' \
  -H 'Authorization: <EAS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
      "question": "What can I do when the x13-auto-arima component reports an error?",
      "index_name": "default"
  }'

Ejemplo de respuesta (haga clic en para ver detalles)

{
  "docs": [
    {
      "text": "2.PAl-Studio/Designer FAQ 2.1. FAQ about algorithm components : \nCharacters that cannot be transcoded are displayed as \"blob.\" Ignore this error, because nodes in the downstream can read and process the data.\nWhat can I do when the x13-auto-arima component reports an error?\nMake sure that up to 1,200 training data samples are imported into the x13-auto-arima component.\nWhat can I do when the Doc2Vec component reports the CallExecutorToParseTaskFail error?",
      "score": 0.83608,
      "metadata": {
        "file_path": "localdata/knowledgebase/default/docs/pai_document.md",
        "file_name": "pai_document.md",
        "file_size": 3794,
        "creation_date": "2025-03-20",
        "last_modified_date": "2025-03-20"
      },
      "image_url": null
    },
    {
      "text": "2.PAl-Studio/Designer FAQ 2.1. FAQ about algorithm components : \nThis topic describes the FAQ about algorit hm components.\nWhat can I do when the format conversion component reports an error? · What can I do when \"blob\" is displayed on the data present ation page of the PAl? · what canI do when the xl3-auto-arima component reports an error? · What can Ido when the Doc2Vec component reports the CallExecutorToParseTaskFail error?\nWhat can I do when the format conversion component reports an error?",
      "score": 0.797132,
      "metadata": {
        "file_path": "localdata/knowledgebase/default/docs/pai_document.md",
        "file_name": "pai_document.md",
        "file_size": 3794,
        "creation_date": "2025-03-20",
        "last_modified_date": "2025-03-20"
      },
      "image_url": null
    },
    {
      "text": "2.PAl-Studio/Designer FAQ 2.1. FAQ about algorithm components\n2.3. Preview Oss files in Machine Learning Studio : \n2.On the details page of the Oss bucket, choose Access Cont rol $>$ Cross-Origin Resource Sharing (CORS). In the Cross-Origin Resource Sharing (CORS) section, click Conf igure.\n3.Click Create Rule. In the Create Rule panel, set the following parameters.",
      "score": 0.714184,
      "metadata": {
        "file_path": "localdata/knowledgebase/default/docs/pai_document.md",
        "file_name": "pai_document.md",
        "file_size": 3794,
        "creation_date": "2025-03-20",
        "last_modified_date": "2025-03-20"
      },
      "image_url": null
    }
  ]
}

v0.3.4

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/retrieval

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: application/json

Parámetros de solicitud

  • query: La consulta de búsqueda del usuario.

  • knowledgebase_id: El nombre de la base de conocimiento. El valor predeterminado es default.

  • retrieval_settings: Los parámetros de recuperación. Se recomienda configurar estos parámetros en la WebUI. Para obtener más información sobre los parámetros, consulte la WebUI.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Set query to the user's search query. 
# Set knowledge_id to the name of the knowledge base. 
curl -X 'POST' '<EAS_SERVICE_URL>/api/v1/retrieval' \
  -H 'Authorization: <EAS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
      "query": "What can I do when the x13-auto-arima component reports an error?",
      "knowledgebase_id": "default",
      "retrieval_settings": {"similarity_top_k": 5}
  }'

Otras operaciones de API

Obtener la configuración del servicio RAG

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/config

Método de solicitud

GET

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Ejemplo de solicitud cURL (haga clic en para ver detalles)

 # Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
 curl -X 'GET' '<EAS_SERVICE_URL>/api/v1/config' -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic en para ver detalles)

  {
    "system": {
      "default_web_search": false,
      "query_type": "websearch"
    },
    "data_reader": {
      "concat_csv_rows": false,
      "enable_mandatory_ocr": false,
      "format_sheet_data_to_json": false,
      "sheet_column_filters": null,
      "number_workers": 4
    },
    "node_parser": {
      "type": "Sentence",
      "chunk_size": 500,
      "chunk_overlap": 10,
      "enable_multimodal": true,
      "paragraph_separator": "\n\n\n",
      "sentence_window_size": 3,
      "sentence_chunk_overlap": 200,
      "breakpoint_percentile_threshold": 95,
      "buffer_size": 1
    },
    "index": {
      "vector_store": {
        "persist_path": "./localdata/knowledgebase/default/.index/.faiss",
        "type": "faiss",
        "is_image_store": false
      },
      "enable_multimodal": true,
      "persist_path": "localdata/storage"
    },
    "embedding": {
      "source": "huggingface",
      "model": "bge-m3",
      "embed_batch_size": 10,
      "enable_sparse": false
    },
    "multimodal_embedding": {
      "source": "cnclip",
      "model": "ViT-L-14",
      "embed_batch_size": 10,
      "enable_sparse": false
    },
    "llm": {
      "source": "openai_compatible",
      "temperature": 0.1,
      "system_prompt": null,
      "max_tokens": 4000,
      "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
      "api_key": "sk-xxx",
      "model": "qwen-max"
    },
    "multimodal_llm": {
      "source": "openai_compatible",
      "temperature": 0.1,
      "system_prompt": null,
      "max_tokens": 4000,
      "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
      "api_key": "sk-xxx",
      "model": ""
    },
    "functioncalling_llm": null,
    "agent": {
      "system_prompt": "You are a travel assistant, xxx",
      "python_scripts": "xxx",
      "function_definition": "xxx",
      "api_definition": "xxx"
    },
    "chat_store": {
      "type": "local",
      "persist_path": "localdata/storage"
    },
    "data_analysis": {
      "type": "mysql",
      "nl2sql_prompt": "Given an input question, xxx",
      "synthesizer_prompt": "Given an input question, xxx",
      "database": "my_pets",
      "tables": [],
      "descriptions": {},
      "enable_enhanced_description": false,
      "enable_db_history": true,
      "enable_db_embedding": true,
      "max_col_num": 100,
      "max_val_num": 1000,
      "enable_query_preprocessor": true,
      "enable_db_preretriever": true,
      "enable_db_selector": true,
      "user": "root",
      "password": "xxx",
      "host": "127.0.0.1",
      "port": 3306
    },
    "intent": {
      "descriptions": {
        "rag": "\nThis tool can help you get more specific information from the knowledge base.\n",
        "tool": "\nThis tool can help you get travel information about time, weather, flights, train and hotels.\n"
      }
    },
    "node_enhancement": {
      "tree_depth": 3,
      "max_clusters": 52,
      "proba_threshold": 0.1
    },
    "oss_store": {
      "bucket": "",
      "endpoint": "oss-cn-hangzhou.aliyuncs.com",
      "ak": null,
      "sk": null
    },
    "postprocessor": {
      "reranker_type": "no-reranker",
      "similarity_threshold": 0.5
    },
    "retriever": {
      "vector_store_query_mode": "default",
      "similarity_top_k": 3,
      "image_similarity_top_k": 2,
      "search_image": false,
      "hybrid_fusion_weights": [0.7, 0.3]
    },
    "search": {
      "source": "google",
      "search_count": 10,
      "serpapi_key": "142xxx",
      "search_lang": "zh-CN"
    },
    "synthesizer": {
      "use_multimodal_llm": false,
      "system_role_template": "You are xxx",
      "custom_prompt_template": "Your goal is to provide accurate, useful, and easy-to-understand information. xxx"
    },
    "query_rewrite": {
      "enabled": true,
      "rewrite_prompt_template": "# Role\nYou are a professional information retrieval expert, xxx",
      "llm": {
        "source": "openai_compatible",
        "temperature": 0.1,
        "system_prompt": null,
        "max_tokens": 4000,
        "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
        "api_key": null,
        "model": ""
      }
    },
    "guardrail": {
      "endpoint": null,
      "region": null,
      "access_key_id": null,
      "access_key_secret": null,
      "custom_advice": null
    }
  }

Actualizar la configuración del servicio RAG

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/config

Método de solicitud

PATCH

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: application/json

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
    curl -X 'PATCH' '<EAS_SERVICE_URL>/api/v1/config' \
    -H 'Authorization: <EAS_TOKEN>' \
    -H 'Content-Type: application/json' \
    -d '{
        "system": {
          "default_web_search": false,
          "query_type": "websearch"
        },
        "data_reader": {
          "concat_csv_rows": false,
          "enable_mandatory_ocr": false,
          "format_sheet_data_to_json": false,
          "sheet_column_filters": null,
          "number_workers": 4
        },
        "node_parser": {
          "type": "Sentence",
          "chunk_size": 500,
          "chunk_overlap": 10,
          "enable_multimodal": true,
          "paragraph_separator": "\n\n\n",
          "sentence_window_size": 3,
          "sentence_chunk_overlap": 200,
          "breakpoint_percentile_threshold": 95,
          "buffer_size": 1
        },
        ...
    }' # (For more configuration information, see the response example for getting the RAG service configuration.)

Ejemplo de respuesta (haga clic en para ver detalles)

  { "msg": "Update RAG configuration successfully." }

Cargar información de CHAT_DB

Cargar un archivo Excel o CSV para consultas de contenido de tablas en Chat_DB

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/upload_datasheet

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: multipart/form-data

Parámetros de solicitud

file: El archivo Excel o CSV.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace the path after "-F 'file=@" with the file path. 
  curl -X 'POST' <EAS_SERVICE_URL>/api/v1/upload_datasheet \
  -H 'Authorization: <EAS_TOKEN>' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@example_data/titanic_train.csv'

Ejemplo de respuesta (haga clic en para ver detalles)

  {
    "task_id": "3b12cf5fabee4a99a32895d2f693****",
    "destination_path": "./localdata/data_analysis/titanic_train.csv",
    "data_preview": "xxx"
  }

Cargar un archivo JSON para complementar la información de la base de datos de Chat_DB con pares de preguntas y respuestas

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/upload_db_history

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: multipart/form-data

Parámetros de solicitud

  • file: El archivo JSON.

  • db_name: El nombre de la base de datos.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
# Replace the path after " -F 'file=@" with the JSON file path. Set db_name to your database name. 
  curl -X 'POST' <EAS_SERVICE_URL>/api/v1/upload_db_history \
  -H 'Authorization: <EAS_TOKEN>' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@example_data/db_query_history.json' \
  -F 'db_name=my_pets'

Ejemplo de respuesta (haga clic en para ver detalles)

  {
    "task_id": "204191f946384a54a48b13ec00fd****",
    "destination_path": "./localdata/data_analysis/text2sql/history/my_pets_db_query_history.json"
  }

Cargar un archivo CSV para complementar la información de la base de datos de Chat_DB con descripciones de columnas

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/upload_db_description

Método de solicitud

POST

Encabezados de solicitud

  • Authorization: EAS_TOKEN # El token para la llamada a EAS

  • Content-Type: multipart/form-data

Parámetros de solicitud

  • files: El archivo CSV.

  • db_name: El nombre de la base de datos.

Ejemplo de solicitud cURL (haga clic en para ver detalles)

 # Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively. 
 # Replace the path after "-F 'files=@" with your CSV file path. Set db_name to the database name. 
  curl -X 'POST' <EAS_SERVICE_URL>/api/v1/upload_db_description \
  -H 'Authorization: <EAS_TOKEN>' \
  -H 'Content-Type: multipart/form-data' \
  -F 'files=@example_data/database_description/schools.csv' \
  -F 'db_name=california_schools'

Ejemplo de respuesta (haga clic en para ver detalles)

  {
    "task_id": "f417e436cf8b4c329f7b48a7f3c4****",
    "destination_path": "./localdata/data_analysis/text2sql/input_description"
  }

Cargar información de la base de datos

Método de llamada

URL

{EAS_SERVICE_URL}/api/v1/query/load_db_info

Método de solicitud

POST

Encabezados de solicitud

Authorization: EAS_TOKEN # El token para la llamada a EAS

Ejemplo de solicitud cURL (haga clic en para ver detalles)

# Replace <EAS_TOKEN> and <EAS_SERVICE_URL> with the service token and endpoint, respectively.
curl -X 'POST' <EAS_SERVICE_URL>/api/v1/query/load_db_info -H 'Authorization: <EAS_TOKEN>'

Ejemplo de respuesta (haga clic en para ver detalles)

  { "task_id": "2389f546af2b6c359d7b19c8b5c3****" }