Skip to main content

RunLibraryChatGeneration

Generates a chat response from a document library. You can ask questions in natural language, and the system retrieves relevant information to provide a summarized answer.

Debug

You can run this API directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After the API is successfully run, OpenAPI Explorer can automatically generate SDK code examples. Debug

Authorization information

The following table describes the authorization information of this API. You can use it in the Action element of a RAM policy statement to grant a RAM user or RAM role the permission to call this API. Details:
  • Operation: refers to a specific permission point.
  • Access level: refers to the access level of each operation. Valid values: Write, Read, or List.
  • Resource type: refers to the resource types that support authorization for the operation. Details:
    • Required resource types are marked with a leading asterisk (*).
    • For operations that do not support resource-level authorization, 全部资源 is used.
  • Condition key: refers to the condition keys defined by the cloud product itself.
  • Dependent operation: refers to other permissions required to successfully perform the operation. The caller must also have the permissions of the dependent operations for the operation to succeed.
OperationAccess levelResource typeCondition keyDependent operation
dianjin:RunLibraryChatGenerationnone
*All resources
*
    None
None

Request syntax

POST /{workspaceId}/api/run/library/chat/generation HTTP/1.1

Request parameters

NameTypeRequiredDescriptionExample
workspaceIdstringYes

The workspace ID.

llm-xxxx
bodyobjectNo

The request body.

docIdListarrayNo

A list of document IDs.

docIdListstringNo

A document ID.

1273827636xxx
enableFollowUpbooleanNo

Specifies whether to enable multi-turn enhancement.

false
enableMultiQuerybooleanNo

Specifies whether to enable query splitting.

false
enableOpenQabooleanNo

Specifies whether to enable openQA.

false
followUpLlmstringNo

The LLM used for multi-turn query enhancement.

qwen-max
libraryIdstringYes

The document library ID.

3akzl28vap
llmTypestringYes

The type of the LLM.

qwen-max
multiQueryLlmstringNo

The LLM used for query splitting.

qwen-max
querystringYes

The query entered by the user.

How is the weather in Beijing these two days
queryCriteriaobjectNo

The property filter.

andarray<object>No

The and expression, used to filter documents/document chunks.

andobjectNo

The content of the and expression.

boostfloatNo

The weight of the tag. When the value is less than 1, the weight of the corresponding keyword is reduced; conversely, when the value is greater than 1, the weight is increased.

0.5
keystringNo

The key of the tag.

city
operatorstringNo

The operator of the tag: the relationship between the value stored in the document library metadata key and the value you enter

  • eq: The value stored in the document library metadata key = the value you enter
  • lte: The value stored in the document library metadata key <= the value you enter
  • gte: The value stored in the document library metadata key >= the value you enter
  • lt: The value stored in the document library metadata key < the value you enter
  • gt: The value stored in the document library metadata key > the value you enter
eq
valuestringNo

The value of the tag.

Beijing
orarray<object>No

The or expression, used to filter documents/document chunks.

orobjectNo

The content of the or expression.

boostfloatNo

The weight of the tag. When the value is less than 1, the weight of the corresponding keyword is reduced; conversely, when the value is greater than 1, the weight is increased.

0.5
keystringNo

The key of the tag.

city
operatorstringNo

The operator of the tag: the relationship between the value stored in the document library metadata key and the value you enter

  • eq: The value stored in the document library metadata key = the value you enter
  • lte: The value stored in the document library metadata key <= the value you enter
  • gte: The value stored in the document library metadata key >= the value you enter
  • lt: The value stored in the document library metadata key < the value you enter
  • gt: The value stored in the document library metadata key > the value you enter
eq
valuestringNo

The value of the tag.

Beijing
rerankTypestringNo

The sort policy type: linear/model (linear: rule-based sorting, model: model-based sorting, llm)

linear
sessionIdstringNo

sessionId

null
streambooleanNo

Streaming/non-streaming

false
subQueryListarrayNo

A list of subqueries.

subQueryListstringNo

A subquery.

How is the recent temperature in Beijing?
textSearchParameterobjectNo

Search engine parameters--text search parameters

limitintegerNo

The number of rows to return.

10
searchAnalyzerTypestringNo

The search tokenizer (Standard, IkMaxWord, IkSmart). Configure it flexibly based on business needs. If left empty, the search tokenizer bound to the document library is used.

IkMaxWord
topKintegerNo

The final number of retrieved corpus entries.

1
vectorSearchParameterobjectNo

Search engine parameters--vector search parameters

limitintegerNo

The number of rows to return.

10
withDocumentReferencebooleanNo

Specifies whether to return document references.

false

Response parameters

NameTypeDescriptionExample
object

ResultCode

costlong

The time consumed.

null
dataany

The response data (non-streaming).

{ "finish":true, "text":"Yes, the validity period of a registered prepaid card must be no less than 3 years.", "message": "Yes, the validity period of a registered prepaid card must be no less than 3 years.", "queryResult":{ "errCode": "0", //Error code at the API protocol level. Normally 0. Changes when unauthorized, parameter error, or server exception occurs. Can be ignored. "message": "ok", //Message at the API protocol level "data":{ "success": true, //true if there is an answer, false if not "answer": null, //Answer generated by the LLM "embeddingElapsedMs": 127, "vectorSearchElapsedMs": 2745, "llmElapsedMs": 7911, "totalElapsedMs": 10820, "chunks": [ //Retrieved chunk information, generally top5 or top10. Contact us to tune the effect. { "chunkId": "470182177892469799", //Chunk information number "docId": "22666332", //Document number associated with the chunk "chunkText": "Profits plummeted in the first quarter, can't you bear it? In fact, previous rounds of price cuts have indeed had a certain impact on Tesla's financial data. Tesla has just released its financial report for the first quarter of this year. The data shows that in Q1 2023, Tesla achieved revenue of 23.33 billion US dollars, an increase of 24% over the previous year; Tesla delivered more than 422,000 electric vehicles worldwide in the first quarter, an increase of 36% over the previous year", //Original news content "chunkMeta": { // Other metadata in the demo data "language": "en", "unique_id": "news_22666332_13", "content_type": "news", "stock_id_list": [] } }], "documents": [{ "docId": "1686637056086872065", //Document number "gmtCreate": "2023-08-02 15:16:25", //Document creation time "libraryId": "a1b2c3", //Knowledge base number associated with the document "title": "2023 ICBC Credit Card WeChat and JD Card-Binding Consumption Accumulated Points Activity", //Document title "url": null //Document link, if any }] //Document associated with the chunk text }, "success": true //Success/failure status at the API protocol level. true means errCode is 0 } }
dataTypestring

The data type.

null
errCodestring

The error code.

0
messagestring

The error message.

ok
requestIdstring

The request ID.

5E3FBAF1-17AF-53B7-AF0A-CDCEEB6DE658
successboolean

Indicates whether the request is successful.

true
timestring

The timestamp.

2024-04-24 11:54:34

Streaming response description

Result rewritten based on conversation history

{
    "success": true,
    "dataType": "copilotStep",
    "time": "2024-08-26 11:28:10",
    "errCode": "0",
    "message": "ok",
    "data": {
        "stepName": "start_followup_query",  // 开始改写
        "data": "业绩表现如何"
    },
    "requestId": null,
    "cost": null
}

{
    "success": true,
    "dataType": "copilotStep",
    "time": "2024-08-26 11:28:10",
    "errCode": "0",
    "message": "ok",
    "data": {
        "stepName": "completed_followup_query", // 完成改写
        "data": "业绩表现如何"
    },
    "requestId": null,
    "cost": null
}

Query decomposition

{
    "success": true,
    "dataType": "copilotStep",
    "time": "2024-08-26 11:28:10",
    "errCode": "0",
    "message": "ok",
    "data": {
        "stepName": "start_understand_query",  // 开始拆分
        "data": "业绩表现如何"
    },
    "requestId": null,
    "cost": null
}

{
    "success": true,
    "dataType": "copilotStep",
    "time": "2024-08-26 11:28:12",
    "errCode": "0",
    "message": "ok",
    "data": {
        "stepName": "completed_understand_query",  // 完成拆分
        "data": [
            "业绩表现的具体时间段是什么?",
            "是指哪一行业的业绩表现,或者哪个公司的业绩表现?",
            "业绩表现的数据指标有哪些?例如营收、利润、市场份额等。"
        ]
    },
    "requestId": null,
    "cost": null
}

Retrieval results

{
    "success": true,
    "dataType": "queryResult",
    "time": "2023-09-20 16:36:04",
    "errCode": "0",
    "message": "retriever completed",
    "data": {
        "success": true,
        "answer": null,
        "prompt": "请使用以下上下文来回答最后的问题。\n 以下是上下文内容:\n 回,本办法另有规定的除外。不记名预付卡有效期不得低于 3 年。\n 预付卡不得具有透支功能。\n 发卡机构发行销售预付卡时,应向持卡人告知预付卡的有效 期及计算方法。超过有效期尚有资金余额的预付卡,发卡机构应 当提供延期、激活、换卡等服务,保障持卡人继续使用。\n 第九条预付卡卡面应当记载预付卡名称、发卡机构名称、 是否记名、卡号、有效期限或有效期截止日、持卡人注意事项、 客户服务电话等要素。\n 第十条个人或单位购买记名预付卡或一次性购买不记名预 付卡 1 万元以上的,应当使用实名并提供有效身份证件。\n 发卡机构应当识别购卡人、单位经办人的身份,\n\n 息。\n 对于记名预付卡,发卡机构还应当在预付卡核心业务处理系 统中记载持卡人的有效身份证件信息、预付卡卡号、金额等信息。\n 第十二条单位一次性购买预付卡 5000 元以上,个人一次性购 买预付卡 5 万元以上的,应当通过银行转账等非现金结算方式购 买,不得使用现金。\n 购卡人不得使用信用卡购买预付卡。\n 第十三条采用银行转账等非现金结算方式购买预付卡的, 付款人银行账户名称和购卡人名称应当一致。\n 发卡机构应当核对账户信息和身份信息的一致性,在预付卡 核心业务处理系统中记载付款人银行账户名称和账号、收款人银 行账户名称和账号、转账金额等信息。\n 第十四\n\n\n\n 基于上下文理解作出回答,保持回答尽可能简洁。如果你不知道答案,直接回答我不知道。\n 问题:记名预付卡有效期不得低于 3 年吗?\n 答案:",
        "embeddingElapsedMs": 1423,
        "vectorSearchElapsedMs": 115,
        "textSearchElapsedMs": 0,
        "llmElapsedMs": null,
        "totalElapsedMs": 1626,
        "reRankElapsedMs": 8,
        "chunks": [
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": "富滇银行测试知识库",
                "title": "《支付机构预付卡业务管理办法》(中国人民银行公告〔2012〕第 12 号)",
                "chunkId": "478245189908103170",
                "docId": "1701838553380655106",
                "chunkText": "回,本办法另有规定的除外。不记名预付卡有效期不得低于 3 年。\n 预付卡不得具有透支功能。\n 发卡机构发行销售预付卡时,应向持卡人告知预付卡的有效 期及计算方法。超过有效期尚有资金余额的预付卡,发卡机构应 当提供延期、激活、换卡等服务,保障持卡人继续使用。\n 第九条预付卡卡面应当记载预付卡名称、发卡机构名称、 是否记名、卡号、有效期限或有效期截止日、持卡人注意事项、 客户服务电话等要素。\n 第十条个人或单位购买记名预付卡或一次性购买不记名预 付卡 1 万元以上的,应当使用实名并提供有效身份证件。\n 发卡机构应当识别购卡人、单位经办人的身份,",
                "fileType": "pdf",
                "chunkMeta": {},
                "score": 0.92747295
            },
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": "富滇银行测试知识库",
                "title": "《支付机构预付卡业务管理办法》(中国人民银行公告〔2012〕第 12 号)",
                "chunkId": "478245189908234242",
                "docId": "1701838553380655106",
                "chunkText": "息。\n 对于记名预付卡,发卡机构还应当在预付卡核心业务处理系 统中记载持卡人的有效身份证件信息、预付卡卡号、金额等信息。\n 第十二条单位一次性购买预付卡 5000 元以上,个人一次性购 买预付卡 5 万元以上的,应当通过银行转账等非现金结算方式购 买,不得使用现金。\n 购卡人不得使用信用卡购买预付卡。\n 第十三条采用银行转账等非现金结算方式购买预付卡的, 付款人银行账户名称和购卡人名称应当一致。\n 发卡机构应当核对账户信息和身份信息的一致性,在预付卡 核心业务处理系统中记载付款人银行账户名称和账号、收款人银 行账户名称和账号、转账金额等信息。\n 第十四",
                "fileType": "pdf",
                "chunkMeta": {},
                "score": 0.8335201
            }
        ],
        "vectorChunks": [
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": null,
                "title": null,
                "chunkId": "478245189908103170",
                "docId": "1701838553380655106",
                "chunkText": "回,本办法另有规定的除外。不记名预付卡有效期不得低于 3 年。\n 预付卡不得具有透支功能。\n 发卡机构发行销售预付卡时,应向持卡人告知预付卡的有效 期及计算方法。超过有效期尚有资金余额的预付卡,发卡机构应 当提供延期、激活、换卡等服务,保障持卡人继续使用。\n 第九条预付卡卡面应当记载预付卡名称、发卡机构名称、 是否记名、卡号、有效期限或有效期截止日、持卡人注意事项、 客户服务电话等要素。\n 第十条个人或单位购买记名预付卡或一次性购买不记名预 付卡 1 万元以上的,应当使用实名并提供有效身份证件。\n 发卡机构应当识别购卡人、单位经办人的身份,",
                "fileType": null,
                "chunkMeta": {},
                "score": 0.85494584
            },
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": null,
                "title": null,
                "chunkId": "478245189908234242",
                "docId": "1701838553380655106",
                "chunkText": "息。\n 对于记名预付卡,发卡机构还应当在预付卡核心业务处理系 统中记载持卡人的有效身份证件信息、预付卡卡号、金额等信息。\n 第十二条单位一次性购买预付卡 5000 元以上,个人一次性购 买预付卡 5 万元以上的,应当通过银行转账等非现金结算方式购 买,不得使用现金。\n 购卡人不得使用信用卡购买预付卡。\n 第十三条采用银行转账等非现金结算方式购买预付卡的, 付款人银行账户名称和购卡人名称应当一致。\n 发卡机构应当核对账户信息和身份信息的一致性,在预付卡 核心业务处理系统中记载付款人银行账户名称和账号、收款人银 行账户名称和账号、转账金额等信息。\n 第十四",
                "fileType": null,
                "chunkMeta": {},
                "score": 0.6670402
            }
        ],
        "textChunks": [],
        "chunkParts": [],
        "chunkTextList": [
            "回,本办法另有规定的除外。不记名预付卡有效期不得低于 3 年。\n 预付卡不得具有透支功能。\n 发卡机构发行销售预付卡时,应向持卡人告知预付卡的有效 期及计算方法。超过有效期尚有资金余额的预付卡,发卡机构应 当提供延期、激活、换卡等服务,保障持卡人继续使用。\n 第九条预付卡卡面应当记载预付卡名称、发卡机构名称、 是否记名、卡号、有效期限或有效期截止日、持卡人注意事项、 客户服务电话等要素。\n 第十条个人或单位购买记名预付卡或一次性购买不记名预 付卡 1 万元以上的,应当使用实名并提供有效身份证件。\n 发卡机构应当识别购卡人、单位经办人的身份,",
            "息。\n 对于记名预付卡,发卡机构还应当在预付卡核心业务处理系 统中记载持卡人的有效身份证件信息、预付卡卡号、金额等信息。\n 第十二条单位一次性购买预付卡 5000 元以上,个人一次性购 买预付卡 5 万元以上的,应当通过银行转账等非现金结算方式购 买,不得使用现金。\n 购卡人不得使用信用卡购买预付卡。\n 第十三条采用银行转账等非现金结算方式购买预付卡的, 付款人银行账户名称和购卡人名称应当一致。\n 发卡机构应当核对账户信息和身份信息的一致性,在预付卡 核心业务处理系统中记载付款人银行账户名称和账号、收款人银 行账户名称和账号、转账金额等信息。\n 第十四"
        ],
        "documents": [
            {
                "docId": "1701838553380655106",
                "gmtCreate": "2023-09-13 14:01:44",
                "libraryId": null,
                "title": "《支付机构预付卡业务管理办法》(中国人民银行公告〔2012〕第 12 号)",
                "url": null,
                "fileType": "pdf"
            }
        ]
    },
    "cost": null
}

Model summary result

{
    "success": true,
    "dataType": "message",
    "time": "2023-09-20 16:36:05",
    "errCode": "0",
    "message": "ok",
    "data": {
        "message": "是的,",// 增量答案
        "text": "是的,", // 累计答案
        "finish": false
    },
    "cost": null
}

Examples

Success response JSON format
{
  "cost": 0,
  "data": "{\n    \"finish\":true,\n    \"text\":\"是的,记名预付卡的有效期不得低于3年。\",\n    \"message\": \"是的,记名预付卡的有效期不得低于3年。\",\n    \"queryResult\":{\n      \"errCode\": \"0\",\t//接口协议层面的错误码,正常为0,未授权,参数错误,服务器异常时会发生变化,可以忽略不处理\n      \"message\": \"ok\",\t//接口协议层面的消息\n      \"data\":{\n        \"success\": true,\t//有回答true 无回答false\n        \"answer\": null,\t//大模型生成的回答结果\n        \"embeddingElapsedMs\": 127,\n        \"vectorSearchElapsedMs\": 2745,\n        \"llmElapsedMs\": 7911,\n        \"totalElapsedMs\": 10820,\n        \"chunks\": [\t//召回的分块信息,一般为top5或top10,可联系我们调整效果\n          {\n            \"chunkId\": \"470182177892469799\",\t//分块信息的编号\n            \"docId\": \"22666332\",\t//分块关联的文档编号\n            \"chunkText\": \"Profits plummeted in the first quarter, can't you bear it? In fact, previous rounds of price cuts have indeed had a certain impact on Tesla's financial data. Tesla has just released its financial report for the first quarter of this year. The data shows that in Q1 2023, Tesla achieved revenue of 23.33 billion US dollars, an increase of 24% over the previous year; Tesla delivered more than 422,000 electric vehicles worldwide in the first quarter, an increase of 36% over the previous year\",\t//新闻原始内容\n            \"chunkMeta\": {\t// demo数据中的其他metadata\n              \"language\": \"en\",\n              \"unique_id\": \"news_22666332_13\",\n              \"content_type\": \"news\",\n              \"stock_id_list\": []\n            }\n          }],\n        \"documents\": [{\n          \"docId\": \"1686637056086872065\",\t//文档编号\n          \"gmtCreate\": \"2023-08-02 15:16:25\",\t//文档的创建时间\n          \"libraryId\": \"a1b2c3\",\t//文档关联的知识库编号\n          \"title\": \"2023年工银信用卡微信、京东绑卡消费累计积分活动\",\t//文档标题\n          \"url\": null\t//文档连接,如有\n        }]\t//块文本关联的文档\n      },\n      \"success\": true\t//接口协议层面的成功/失败状态 true就是errCode为0\n    }\n  }",
  "dataType": null,
  "errCode": 0,
  "message": "ok",
  "requestId": "5E3FBAF1-17AF-53B7-AF0A-CDCEEB6DE658",
  "success": true,
  "time": "2024-04-24 11:54:34"
}

Error codes

Visit the Error Center to view more error codes.