全部產品
Search
文件中心

Platform For AI:適用於v0.3.0-v0.3.4版本鏡像

更新時間:Sep 27, 2025

PAI-RAG提供豐富的API介面,用於服務管理、知識庫管理員和對話等功能。本文將介紹使用v0.3.0-v0.3.4版本鏡像部署的RAG服務所支援的介面類型及調用方式。

使用限制

該文檔僅適用於使用v0.3.0-v0.3.4版本鏡像部署的RAG服務。

您可以前往模型線上服務(EAS)頁面,單擊RAG服務名稱,然後在概覽頁面的環境資訊地區,查看鏡像版本。image

擷取服務訪問地址和Token

通過API介面調用RAG服務前,您需擷取RAG服務的訪問地址和Token:

  1. 登入PAI控制台,在頁面上方選擇目標地區,並在右側選擇目標工作空間,然後單擊進入EAS

  2. 單擊目標服務名稱,然後在基本資料地區,單擊查看調用資訊

  3. 調用資訊頁面,擷取服務訪問地址(EAS_SERVICE_URL)Token(EAS_Token)

    重要
    • 請將EAS_SERVICE_URL末尾的斜杠(/)刪除。

    • 使用公網地址調用:調用用戶端支援訪問公網。

    • 使用VPC地址調用:調用用戶端必須與RAG服務位於同一個專用網路內。

    image

Chat API(對話介面)

通過OpenAI-Compatiable API調用服務。調用服務前,您需根據使用的功能,提前在RAG服務的WebUI頁面完成相應配置。

支援功能

  • web search:連網搜尋。需提前在RAG服務的WebUI頁面配置網路搜尋參數。

  • chat knowledgebase:知識庫查詢。需提前上傳知識庫檔案。

  • chat llm:使用LLM回答。需提前配置LLM服務

  • chat agent:智能體工具調用。需提前在RAG服務的WebUI頁面完成智能體相關代碼配置。

  • chat db:資料庫/表格式查詢。需提前在RAG服務的WebUI頁面完成資料分析相關配置。

調用方式

調用地址

{EAS_SERVICE_URL}/v1/chat/completions

請求方式

POST

請求HEADERS

Authorization: EAS_TOKEN(EAS調用Token)

HTTP Body

{
    "model": "default",  # 模型名稱,可以填default,也可以填寫在WebUI中配置好的模型名稱。 
    "messages": [
        {"role": "user", "content": "您好"},
        {"role": "assistant", "content": "您好,有什麼能幫到您?"},
        {"role": "user", "content": "浙江省會是哪裡"},
        {"role": "assistant", "content": "杭州是浙江的省會。"},
        {"role": "user", "content": "有哪些好玩的"},
    ],
    "stream": true,  # 是否流式
    "chat_knowledgebase": true,  # 是否查詢本地知識庫
    "search_web": false,  # 是否使用連網搜尋
    "chat_llm": false,  # 是否僅使用LLM聊天
    "chat_agent": false,  # 是否使用Agent
    "chat_db": false,  # 是否查詢資料庫
    "index_name": "default",  # 索引名稱用於RAG情境,僅支援配置1個索引名稱,若未指定,系統將使用預設索引
    "max_tokens": 1024,  # 最大輸出長度,如1024
    "temperature": 0.1,  # 控制產生內容隨機性,取值範圍[0,1],值越低確定性越高,值越高內容越多樣化
}
重要
  • 如果同時配置多個功能,系統會按照該優先順序進行調用,優先順序從高到低依次為search_web、chat_knowledgebase、chat_agent、chat_db、chat_llm。同時,在每個功能中,系統會進行前置意圖識別,以區分是否調用該功能,或直接使用大語言模型(LLM)產生回複。

  • 如果所有功能開關都為 false 或未傳遞,則預設查詢本地知識庫(即"chat_knowledgebase": true)。

請求樣本(單擊此處,查看詳情)

連網搜尋

from openai import OpenAI

##### API 配置 #####

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
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": "您好"},
            {"role": "assistant", "content": "您好,有什麼能幫到您?"},
            {"role": "user", "content": "浙江省會是哪裡"},
            {"role": "assistant", "content": "杭州是浙江的省會。"},
            {"role": "user", "content": "有哪些好玩的"},
        ],
        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()

查詢資料庫

from openai import OpenAI

##### API 配置 #####
# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。

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": "有多少只貓"},
            {"role": "assistant", "content": "有2隻貓"},
            {"role": "user", "content": "狗呢"},
        ],
        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()

Knowledgebase API(知識庫管理員介面)

新增知識庫

調用方式

調用地址

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

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN

  • Content-Type: application/json

請求參數

  • name:新知識庫名稱,例如new_milvus。

  • vector_store_config:新知識庫配置

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 vector_store_config需更新為您的向量檢索庫配置。 
 
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
      }
  }'

上述代碼中vector_store_config配置以milvus為例,其他向量資料庫vector_store_config配置說明如下:

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"
      }

返回樣本(單擊此處,查看詳情)

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

查詢知識庫列表

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/knowledgebases

請求方式

GET

請求HEADERS

Authorization: EAS_TOKEN # Eas調用token

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

{
  "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"
      }
    }
  }
}

上傳知識庫檔案

調用方式

調用地址

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

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: multipart/form-data

請求參數

  • files:檔案。

  • name:知識庫名稱,例如my_milvus。

cURL請求樣本(單擊此處,查看詳情)

  • 上傳單個檔案(使用-F 'files=@path上傳)

    # <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
    # <name>需替換為您的知識庫名稱。 
    # “-F 'files=@”後的路徑需替換為您的知識庫檔案路徑。 
    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=@path'參數,每個參數對應一個要上傳的檔案,樣本如下:

    # <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
    # <name>需替換為您的知識庫名稱。 
    # # “-F 'files=@”後的路徑需替換為您的知識庫檔案路徑。
    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' \

返回樣本(單擊此處,查看詳情)

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

查詢上傳狀態

調用方式

調用地址

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

請求方式

GET

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

請求參數

  • file_name:檔案名稱。

  • name:知識庫名稱,例如my_milvus。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱;<file_name>替換為您的檔案名稱。 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files/<file_name> -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

{
  "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"
}

查詢上傳歷史

調用方式

調用地址

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

請求方式

GET

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

請求參數

name:知識庫名稱,例如my_milvus。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/history -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

[
  {
    "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"
  }
]

查詢知識庫檔案清單

調用方式

調用地址

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

請求方式

GET

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

請求參數

name:知識庫名稱,例如my_milvus。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

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

刪除知識庫檔案

調用方式

調用地址

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

請求方式

DELETE

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

請求參數

  • file_name:檔案名稱

  • name:知識庫名稱,例如my_milvus。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 <file_name>需替換為待刪除的檔案名稱。 
curl -X 'DELETE' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name>/files/<file_name> -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

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

查詢指定知識庫資訊

調用方式

調用地址

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

請求方式

GET

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

請求參數

name:知識庫名稱,例如my_milvus。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 
curl -X 'GET' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name> -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

{
  "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"
  }
}

更新指定知識庫

調用方式

調用地址

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

請求方式

PATCH

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: application/json

請求參數

  • name:知識庫名稱,例如new_milvus。

  • vector_store_config:知識庫配置。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 
# vector_store_config需配置為您要更新的知識庫配置。 
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
      }
  }'

上述代碼中vector_store_config配置以milvus為例,其他向量資料庫vector_store_config配置說明,請參見新增知識庫

返回樣本(單擊此處,查看詳情)

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

刪除指定知識庫

調用方式

調用地址

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

請求方式

DELETE

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

請求參數

name:知識庫名稱,例如new_milvus。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# <name>需替換為您的知識庫名稱。 
curl -X 'DELETE' <EAS_SERVICE_URL>/api/v1/knowledgebases/<name> -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

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

知識庫檢索

v0.3.0-v0.3.3

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/query/retrieval

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: application/json

請求參數

  • question:使用者檢索問題

  • index_name:知識庫名稱(預設default)

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# question:配置為使用者檢索問題。 
# index_name:配置為知識庫名稱。 
  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"
  }'

返回樣本(單擊此處,查看詳情)

{
  "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

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/retrieval

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: application/json

請求參數

  • query:使用者檢索問題

  • knowledgebase_id:知識庫名稱(預設default)

  • retrieval_settings:檢索參數,建議在WebUI介面配置好,配置參數參見頁面。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# query:配置為使用者檢索問題。 
# knowledge_id:配置為知識庫名稱。 
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}
  }'

Other API

擷取RAG服務配置

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/config

請求方式

GET

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

cURL請求樣本(單擊此處,查看詳情)

 # <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
 curl -X 'GET' '<EAS_SERVICE_URL>/api/v1/config' -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

  {
    "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": "你是一個旅遊小助手,xxx",
      "python_scripts": "xxx",
      "function_definition": "xxx",
      "api_definition": "xxx"
    },
    "chat_store": {
      "type": "local",
      "persist_path": "localdata/storage"
    },
    "data_analysis": {
      "type": "mysql",
      "nl2sql_prompt": "給定一個輸入問題,xxx",
      "synthesizer_prompt": "給定一個輸入問題,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": "你是xxx",
      "custom_prompt_template": "你的目標是提供準確、有用且易於理解的資訊。xxx"
    },
    "query_rewrite": {
      "enabled": true,
      "rewrite_prompt_template": "# 角色\n你是一位專業的資訊檢索專家,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
    }
  }

更新RAG服務配置

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/config

請求方式

PATCH

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: application/json

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
    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
        },
        ...
    }' # (更多配置資訊可參考擷取RAG配置的返回樣本)

返回樣本(單擊此處,查看詳情)

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

CHAT_DB資訊載入

上傳Excel/CSV檔案用於Chat_DB的表格內容查詢

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/upload_datasheet

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: multipart/form-data

請求參數

file:Excel或CSV檔案。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# "-F 'file=@"後的路徑需替換為檔案路徑。 
  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'

返回樣本(單擊此處,查看詳情)

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

上傳JSON檔案用於Chat_DB的資料庫資訊補充-問答對

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/upload_db_history

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: multipart/form-data

請求參數

  • file:JSON檔案。

  • db_name:資料庫名稱。

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
# “ -F 'file=@”後的路徑需替換為JSON檔案路徑。db_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'

返回樣本(單擊此處,查看詳情)

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

上傳CSV檔案用於Chat_DB的資料庫資訊補充-列描述

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/upload_db_description

請求方式

POST

請求HEADERS

  • Authorization: EAS_TOKEN # EAS調用Token

  • Content-Type: multipart/form-data

請求參數

  • files:CSV檔案

  • db_name:資料庫名稱

cURL請求樣本(單擊此處,查看詳情)

 # <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。 
 # “-F 'files=@”後的路徑需替換為您的CSV檔案路徑。db_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'

返回樣本(單擊此處,查看詳情)

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

載入資料庫資訊

調用方式

調用地址

{EAS_SERVICE_URL}/api/v1/query/load_db_info

請求方式

POST

請求HEADERS

Authorization: EAS_TOKEN # EAS調用Token

cURL請求樣本(單擊此處,查看詳情)

# <EAS_TOKEN>和<EAS_SERVICE_URL>需分別替換為服務Token和訪問地址。
curl -X 'POST' <EAS_SERVICE_URL>/api/v1/query/load_db_info -H 'Authorization: <EAS_TOKEN>'

返回樣本(單擊此處,查看詳情)

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