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.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:
  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.
  • API: The API that you can call to perform the action.
  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.
  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.
    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.
    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.
  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.
  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dianjin:RunLibraryChatGeneration

none

*All Resource

*

NoneNone

Request syntax

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

Path Parameters

Parameter

Type

Required

Description

Example

workspaceId

string

Yes

The ID of the workspace.

llm-xxxx

Request parameters

Parameter

Type

Required

Description

Example

body

object

No

The request body.

docIdList

array

No

A list of document IDs.

string

No

A document ID.

1273827636xxx

enableFollowUp

boolean

No

Specifies whether to enable multi-turn enhancement.

false

enableMultiQuery

boolean

No

Specifies whether to enable query splitting.

false

enableOpenQa

boolean

No

Specifies whether to enable openQA.

false

followUpLlm

string

No

The Large Language Model (LLM) used for multi-turn query enhancement.

qwen-max

libraryId

string

Yes

The ID of the document library.

3akzl28vap

llmType

string

Yes

The type of the LLM.

qwen-max

multiQueryLlm

string

No

The LLM used for query splitting.

qwen-max

query

string

Yes

The query entered by the user.

How is the weather in Beijing these two days

queryCriteria

object

No

The property filter.

and

array<object>

No

The `and` expression, used to filter documents or document chunks.

object

No

The content of the `and` expression.

boost

number

No

The weight of the tag. A value less than 1 decreases the weight of the corresponding keyword. A value greater than 1 increases the weight.

0.5

key

string

No

The key of the tag.

city

operator

string

No

The operator for the tag. It specifies the relationship between the metadata key's stored value and your input value.

  • eq: Equal to.

  • lte: Less than or equal to.

  • gte: Greater than or equal to.

  • lt: Less than.

  • gt: Greater than.

eq

value

string

No

The value of the tag.

Beijing

or

array<object>

No

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

object

No

The content of the `or` expression.

boost

number

No

The weight of the tag. A value less than 1 decreases the weight of the corresponding keyword. A value greater than 1 increases the weight.

0.5

key

string

No

The key of the tag.

city

operator

string

No

The operator for the tag. It specifies the relationship between the metadata key's stored value and your input value.

  • eq: Equal to.

  • lte: Less than or equal to.

  • gte: Greater than or equal to.

  • lt: Less than.

  • gt: Greater than.

eq

value

string

No

The value of the tag.

Beijing

rerankType

string

No

The type of the sort policy. Valid values: `linear` and `model`. `linear`: rule-based sorting. `model`: model-based sorting (LLM).

linear

sessionId

string

No

The session ID.

null

stream

boolean

No

Specifies whether to use streaming or non-streaming mode.

false

subQueryList

array

No

A list of subqueries.

string

No

A subquery.

How is the recent temperature in Beijing?

textSearchParameter

object

No

Search engine parameters: text search parameters.

limit

integer

No

The number of rows to return.

10

searchAnalyzerType

string

No

The search tokenizer. Valid values: `Standard`, `IkMaxWord`, and `IkSmart`. Configure this parameter as needed. If left empty, the tokenizer attached to the document library is used.

IkMaxWord

topK

integer

No

The final number of retrieved corpus entries.

1

vectorSearchParameter

object

No

Search engine parameters: vector search parameters.

limit

integer

No

The number of rows to return.

10

withDocumentReference

boolean

No

Specifies whether to return document references.

false

Response elements

Element

Type

Description

Example

object

ResultCode

cost

integer

The time consumed.

null

data

any

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

dataType

string

The data type.

null

errCode

string

The error code.

0

message

string

The error message.

ok

requestId

string

The request ID.

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

success

boolean

Indicates whether the request was successful.

true

time

string

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",  // Start rewriting
        "data": "How is the performance"
    },
    "requestId": null,
    "cost": null
}

{
    "success": true,
    "dataType": "copilotStep",
    "time": "2024-08-26 11:28:10",
    "errCode": "0",
    "message": "ok",
    "data": {
        "stepName": "completed_followup_query", // Rewriting completed
        "data": "How is the performance"
    },
    "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",  // Start decomposition
        "data": "How is the performance"
    },
    "requestId": null,
    "cost": null
}

{
    "success": true,
    "dataType": "copilotStep",
    "time": "2024-08-26 11:28:12",
    "errCode": "0",
    "message": "ok",
    "data": {
        "stepName": "completed_understand_query",  // Decomposition completed
        "data": [
            "What is the specific time period for the performance?",
            "Which industry's or company's performance are you referring to?",
            "What are the data metrics for performance? For example, revenue, profit, market share, etc."
        ]
    },
    "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": "Please use the following context to answer the final question.\n The following is the context:\n ... unless otherwise specified in these measures. The validity period of a non-registered prepaid card must not be less than 3 years.\n Prepaid cards must not have an overdraft function.\n When issuing and selling prepaid cards, the issuing institution must inform the cardholder of the card's validity period and its calculation method. For prepaid cards that still have a balance after the expiration date, the issuing institution must provide services such as extension, activation, or card replacement to ensure the cardholder can continue to use the funds.\n Article 9: The face of the prepaid card must display elements such as the prepaid card name, the name of the issuing institution, whether it is registered, the card number, the validity period or expiration date, notes for the cardholder, and the customer service phone number.\n Article 10: Individuals or entities purchasing a registered prepaid card or making a one-time purchase of non-registered prepaid cards worth CNY 10,000 or more must use their real names and provide valid identification.\n The issuing institution must verify the identity of the purchaser and the entity's handler,\n\n ... information.\n For registered prepaid cards, the issuing institution must also record the cardholder's valid identification information, prepaid card number, amount, and other information in the core prepaid card business processing system.\n Article 12: For one-time purchases of prepaid cards worth CNY 5,000 or more by an entity, or CNY 50,000 or more by an individual, the purchase must be made through non-cash settlement methods such as bank transfer. Cash must not be used.\n The purchaser must not use a credit card to buy a prepaid card.\n Article 13: When purchasing prepaid cards using non-cash settlement methods such as bank transfer, the payer's bank account name and the purchaser's name must be the same.\n The issuing institution must verify the consistency of the account information and identity information, and record information such as the payer's bank account name and number, the payee's bank account name and number, and the transfer amount in the core prepaid card business processing system.\n Article 14\n\n\n\n Based on your understanding of the context, provide an answer. Keep the answer as concise as possible. If you do not know the answer, just say 'I don't know'.\n Question: Must the validity period of a registered prepaid card be no less than 3 years?\n Answer:",
        "embeddingElapsedMs": 1423,
        "vectorSearchElapsedMs": 115,
        "textSearchElapsedMs": 0,
        "llmElapsedMs": null,
        "totalElapsedMs": 1626,
        "reRankElapsedMs": 8,
        "chunks": [
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": "Fudian Bank Test Knowledge Base",
                "title": "Measures for the Administration of Prepaid Card Business of Payment Institutions (Announcement [2012] No. 12 of the People's Bank of China)",
                "chunkId": "478245189908103170",
                "docId": "1701838553380655106",
                "chunkText": "... unless otherwise specified in these measures. The validity period of a non-registered prepaid card must not be less than 3 years.\n Prepaid cards must not have an overdraft function.\n When issuing and selling prepaid cards, the issuing institution must inform the cardholder of the card's validity period and its calculation method. For prepaid cards that still have a balance after the expiration date, the issuing institution must provide services such as extension, activation, or card replacement to ensure the cardholder can continue to use the funds.\n Article 9: The face of the prepaid card must display elements such as the prepaid card name, the name of the issuing institution, whether it is registered, the card number, the validity period or expiration date, notes for the cardholder, and the customer service phone number.\n Article 10: Individuals or entities purchasing a registered prepaid card or making a one-time purchase of non-registered prepaid cards worth CNY 10,000 or more must use their real names and provide valid identification.\n The issuing institution must verify the identity of the purchaser and the entity's handler,",
                "fileType": "pdf",
                "chunkMeta": {},
                "score": 0.92747295
            },
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": "Fudian Bank Test Knowledge Base",
                "title": "Measures for the Administration of Prepaid Card Business of Payment Institutions (Announcement [2012] No. 12 of the People's Bank of China)",
                "chunkId": "478245189908234242",
                "docId": "1701838553380655106",
                "chunkText": "... information.\n For registered prepaid cards, the issuing institution must also record the cardholder's valid identification information, prepaid card number, amount, and other information in the core prepaid card business processing system.\n Article 12: For one-time purchases of prepaid cards worth CNY 5,000 or more by an entity, or CNY 50,000 or more by an individual, the purchase must be made through non-cash settlement methods such as bank transfer. Cash must not be used.\n The purchaser must not use a credit card to buy a prepaid card.\n Article 13: When purchasing prepaid cards using non-cash settlement methods such as bank transfer, the payer's bank account name and the purchaser's name must be the same.\n The issuing institution must verify the consistency of the account information and identity information, and record information such as the payer's bank account name and number, the payee's bank account name and number, and the transfer amount in the core prepaid card business processing system.\n Article 14",
                "fileType": "pdf",
                "chunkMeta": {},
                "score": 0.8335201
            }
        ],
        "vectorChunks": [
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": null,
                "title": null,
                "chunkId": "478245189908103170",
                "docId": "1701838553380655106",
                "chunkText": "... unless otherwise specified in these measures. The validity period of a non-registered prepaid card must not be less than 3 years.\n Prepaid cards must not have an overdraft function.\n When issuing and selling prepaid cards, the issuing institution must inform the cardholder of the card's validity period and its calculation method. For prepaid cards that still have a balance after the expiration date, the issuing institution must provide services such as extension, activation, or card replacement to ensure the cardholder can continue to use the funds.\n Article 9: The face of the prepaid card must display elements such as the prepaid card name, the name of the issuing institution, whether it is registered, the card number, the validity period or expiration date, notes for the cardholder, and the customer service phone number.\n Article 10: Individuals or entities purchasing a registered prepaid card or making a one-time purchase of non-registered prepaid cards worth CNY 10,000 or more must use their real names and provide valid identification.\n The issuing institution must verify the identity of the purchaser and the entity's handler,",
                "fileType": null,
                "chunkMeta": {},
                "score": 0.85494584
            },
            {
                "libraryId": "5rdxr3dxmk",
                "libraryName": null,
                "title": null,
                "chunkId": "478245189908234242",
                "docId": "1701838553380655106",
                "chunkText": "... information.\n For registered prepaid cards, the issuing institution must also record the cardholder's valid identification information, prepaid card number, amount, and other information in the core prepaid card business processing system.\n Article 12: For one-time purchases of prepaid cards worth CNY 5,000 or more by an entity, or CNY 50,000 or more by an individual, the purchase must be made through non-cash settlement methods such as bank transfer. Cash must not be used.\n The purchaser must not use a credit card to buy a prepaid card.\n Article 13: When purchasing prepaid cards using non-cash settlement methods such as bank transfer, the payer's bank account name and the purchaser's name must be the same.\n The issuing institution must verify the consistency of the account information and identity information, and record information such as the payer's bank account name and number, the payee's bank account name and number, and the transfer amount in the core prepaid card business processing system.\n Article 14",
                "fileType": null,
                "chunkMeta": {},
                "score": 0.6670402
            }
        ],
        "textChunks": [],
        "chunkParts": [],
        "chunkTextList": [
            "... unless otherwise specified in these measures. The validity period of a non-registered prepaid card must not be less than 3 years.\n Prepaid cards must not have an overdraft function.\n When issuing and selling prepaid cards, the issuing institution must inform the cardholder of the card's validity period and its calculation method. For prepaid cards that still have a balance after the expiration date, the issuing institution must provide services such as extension, activation, or card replacement to ensure the cardholder can continue to use the funds.\n Article 9: The face of the prepaid card must display elements such as the prepaid card name, the name of the issuing institution, whether it is registered, the card number, the validity period or expiration date, notes for the cardholder, and the customer service phone number.\n Article 10: Individuals or entities purchasing a registered prepaid card or making a one-time purchase of non-registered prepaid cards worth CNY 10,000 or more must use their real names and provide valid identification.\n The issuing institution must verify the identity of the purchaser and the entity's handler,",
            "... information.\n For registered prepaid cards, the issuing institution must also record the cardholder's valid identification information, prepaid card number, amount, and other information in the core prepaid card business processing system.\n Article 12: For one-time purchases of prepaid cards worth CNY 5,000 or more by an entity, or CNY 50,000 or more by an individual, the purchase must be made through non-cash settlement methods such as bank transfer. Cash must not be used.\n The purchaser must not use a credit card to buy a prepaid card.\n Article 13: When purchasing prepaid cards using non-cash settlement methods such as bank transfer, the payer's bank account name and the purchaser's name must be the same.\n The issuing institution must verify the consistency of the account information and identity information, and record information such as the payer's bank account name and number, the payee's bank account name and number, and the transfer amount in the core prepaid card business processing system.\n Article 14"
        ],
        "documents": [
            {
                "docId": "1701838553380655106",
                "gmtCreate": "2023-09-13 14:01:44",
                "libraryId": null,
                "title": "Measures for the Administration of Prepaid Card Business of Payment Institutions (Announcement [2012] No. 12 of the People's Bank of China)",
                "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": "Yes, ",// Incremental answer
        "text": "Yes, ", // Cumulative answer
        "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

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.
Token Plan
Model Playground
  • 3D model generation
  • Audio generation
Fine-tuning
Model Compression
Statistics and Monitoring
Support
RunLibraryChatGeneration - 阿里云百炼