RAG Compose Prompt
将查询与检索到的上下文组合,构建 RAG(检索增强生成)提示词。
实验性桩实现。它通过 out 返回固定的 { message, timestamp } 对象,不会构建任何提示词:query、context、template 和 max_context_tokens 均被忽略。
该算子将检索到的文档列表格式化为上下文块,并注入“根据上下文作答”的提示词模板。
适用场景:
- 针对内部文档的问答。
- 汇总搜索结果。
- 让 LLM 的回答以事实数据为依据。
工作原理
- 解析节点配置:配置键中的表达式会基于本次运行求值;传入条目按原样使用。
- 返回不带端口的
{ message: "Executed ai.rag.compose", timestamp },因此引擎将其路由到out。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-rag-compose",
"label": "Compose RAG prompt",
"operator_slug": "ai.rag.compose",
"operator_version": "1.0.0",
"config": {
"max_context_tokens": 4000
}
}{
"ok": true,
"port": "out",
"data": {
"message": "Executed ai.rag.compose",
"timestamp": "2026-11-26T15:04:05.000Z"
}
}配置
-
templatestring 可选 -
必须包含 {{context}} 和 {{query}} 占位符。
-
max_context_tokensnumber 可选 -
限制上下文大小以适配模型窗口。
配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
template / max_context_tokens - 已声明但被忽略。
输出端口
out 默认 每次运行。
{
"message": "Executed ai.rag.compose",
"timestamp": "2026-11-26T15:04:05.000Z"
}error 代码从不输出此端口。
在表达式中
后续节点可通过 $("RAG Compose Prompt").item.json.<路径> 读取此节点输出中的内容(请把 RAG Compose Prompt 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("RAG Compose Prompt").item.json.prompt可直接用于生成的最终提示词。 | — | |
$("RAG Compose Prompt").item.json.message | — | |
$("RAG Compose Prompt").item.json.timestamp | — |
— Editor: 编辑器会提示它,但 worker 并不返回:读取结果为 undefined。
— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。
输入契约
-
querystring 必填 -
用户的问题。
-
contextarray | string 必填 -
文本分块列表或已拼接好的字符串。
输出契约
-
promptstring 可选 -
可直接用于生成的最终提示词。
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "ai.rag.compose",
"name": "RAG Compose Prompt",
"category": "ai",
"version": "1.0.0",
"description": "Constructs a RAG (Retrieval-Augmented Generation) prompt by combining a query with retrieved context.\n\n This operator formats a list of retrieved documents into a context block and injects it into a \"Answer with context\" prompt template.\n\n **Use Cases:**\n - Q&A over internal documentation.\n - Summarizing search results.\n - Grounding LLM responses in factual data.",
"capabilities": [
"rag",
"prompt-engineering",
"context-window"
],
"config_schema": {
"type": "object",
"properties": {
"template": {
"type": "string",
"title": "RAG Template",
"format": "textarea",
"default": "Context:\n{{context}}\n\nQuery:\n{{query}}\n\nAnswer using only the context above:",
"description": "Must contain {{context}} and {{query}} placeholders."
},
"max_context_tokens": {
"type": "number",
"default": 4000,
"title": "Max Context Tokens",
"description": "Limit context size to fit model window."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
},
"input_contract_schema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The user question."
},
"context": {
"type": [
"array",
"string"
],
"description": "List of text chunks or already joined string."
}
},
"required": [
"query",
"context"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The final prompt ready for generation."
}
}
},
"ports": [
{
"port_id": "out",
"label": "Composed",
"is_default": true
},
{
"port_id": "error",
"label": "Error"
}
],
"execution_mode": "sync",
"tags": [
"rag",
"prompt",
"compose"
],
"is_stateful": false,
"publisher": {
"identity": "org_sommatic_ai",
"profile": {
"name": "Sommatic AI",
"verified": true,
"url": "https://me.veripass.com/sommatic",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"template": {
"type": "string",
"title": "RAG Template",
"format": "textarea",
"default": "Context:\n{{context}}\n\nQuery:\n{{query}}\n\nAnswer using only the context above:",
"description": "Must contain {{context}} and {{query}} placeholders."
},
"max_context_tokens": {
"type": "number",
"default": 4000,
"title": "Max Context Tokens",
"description": "Limit context size to fit model window."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
}{
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The user question."
},
"context": {
"type": [
"array",
"string"
],
"description": "List of text chunks or already joined string."
}
},
"required": [
"query",
"context"
]
}{
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The final prompt ready for generation."
}
}
}[
{
"port_id": "out",
"label": "Composed",
"is_default": true
},
{
"port_id": "error",
"label": "Error"
}
]执行
- 执行方式
sync- 有状态
- 否
- 重试(
retryOnFail) - 否
- 能力
ragprompt-engineeringcontext-window- 标签
ragpromptcompose
说明与限制
- 尚未实现:占位符替换、上下文拼接和上下文大小限制。如需现在构建 RAG 提示词,请使用
data.template或ai.generate搭配自定义模板。
已对照编排器代码核实 · 31e874b · 2026-11-26