Extract Key Phrases
从文本中抽取最重要的短语、术语和概念,并给出相关性评分。每个短语可选地归类为 topic、entity、concept 或 action。
让模型给出 text 中最重要的关键短语(各含相关度和类别),并连同首要短语一起返回。
工作原理
- 合并上游载荷与节点配置(以配置为准),读取
text(回退到input)。 - 发送系统提示词,要求以
language给出前max_phrases个短语(默认 10),include_scores不为false时附带评分,并以严格 JSON 返回;text作为用户消息;temperature: 0。 - 将回答解析为 JSON,
phrases必须是数组。top_phrase取模型给出的值,缺失时取第一个短语。从success输出。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-key-phrases",
"label": "Key phrases",
"operator_slug": "ai.keyphrases",
"operator_version": "1.0.0",
"config": {
"text": "{{ $json.body }}",
"max_phrases": 5,
"include_scores": true,
"language": "en",
"llm_provider_id": "wf-llm-provider-xxxx",
"invocation_mode": "sync"
}
}{
"ok": true,
"data": {
"phrases": [
{
"phrase": "late delivery",
"relevance": 0.95,
"category": "topic"
},
{
"phrase": "refund request",
"relevance": 0.88,
"category": "action"
},
{
"phrase": "Northwind Logistics",
"relevance": 0.7,
"category": "entity"
}
],
"top_phrase": "late delivery"
},
"port": "success"
}配置
-
llm_provider_idstring 可选 -
`LlmProviderModel` 记录的 `id`(例如 `wf-llm-provider-*`)。编排器将调用委托给后端:sync 模式调用 `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke`,stream 模式调用 `POST /chat/conversation/execute/stream-ephemeral`(SSE)。后端根据该记录解析 endpoint + api-key + deployment,并路由到相应的适配器。
-
invocation_modestring 可选 -
LLM 调用的传输方式。`sync` 会阻塞直到收到完整响应。`stream` 通过 SSE 逐步接收 token(长文本生成必须使用)。默认为 `sync`。
-
timeout_msinteger 可选 -
等待调用完成的最长时间(stream 模式下为分块之间的空闲超时)。sync 默认 30000,stream 默认 600000。
-
max_phrasesnumber 可选 -
最多抽取的关键短语数量。
-
include_scoresboolean 可选 -
为每个短语附带相关性评分。
-
languagestring 可选 -
输入文本的语言。
配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
max_phrases - 只写入提示词;代码不会截断列表,模型可能返回更多或更少的短语。
-
text - 不在配置 schema 中(位于输入契约中),但会先从配置读取,再从上游载荷读取。
-
timeout_ms - 仅限 stream 模式:片段之间的空闲超时,默认 600000。在 sync 模式下不会作用于请求。
-
execution - 已声明但被忽略:worker 和引擎都不会读取该块中的
retryOnFail、maxTries、waitBetweenTries、continueOnFail、alwaysOutputData或timeout_ms。
输出端口
success 默认 模型返回了 phrases 数组。
{
"phrases": [
{
"phrase": "late delivery",
"relevance": 0.95,
"category": "topic"
},
{
"phrase": "refund request",
"relevance": 0.88,
"category": "action"
},
{
"phrase": "Northwind Logistics",
"relevance": 0.7,
"category": "entity"
}
],
"top_phrase": "late delivery"
}error 模型调用失败或回答缺少 phrases 数组。
{
"error": "Model did not return valid key phrase extraction output."
}在表达式中
后续节点可通过 $("Extract Key Phrases").item.json.<路径> 读取此节点输出中的内容(请把 Extract Key Phrases 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 success 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Extract Key Phrases").item.json.phrases抽取出的短语,附带相关性评分和可选类别。 | ||
$("Extract Key Phrases").item.json.top_phrase最重要的短语。 |
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
Model did not return valid key phrase extraction output. | error | 回答不是 JSON 或 phrases 不是数组。 |
[AiKeyphrases] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). The legacy 'model_id' alias is no longer supported — update the node config to use 'llm_provider_id'. | error | llm_provider_id 为空或不是字符串。请选择具备 chat 能力的 LLM 提供方记录。 |
LLM Invocation Error: <backend message> | error | 后端拒绝了调用:提供方记录不存在或未激活、提供方报错、配额或内容过滤。请检查提供方记录和后端日志。 |
LLM Invocation Error: empty response from backend (<transport error>) | error | sync 模式:对后端的 HTTP 调用失败(网络错误、非 2xx 状态或超时)。长提示词常会触发请求超时,请改用 invocation_mode: "stream"。 |
RemoteApiService.stream: idle timeout after <timeout_ms>ms | error | stream 模式:在 timeout_ms 内未收到任何片段。若流式请求本身失败,消息为 RemoteApiService.stream: HTTP <status> — <body>。 |
输入契约
-
textstring 必填 -
要从中抽取关键短语的文本。
输出契约
-
phrasesarray 可选 -
抽取出的短语,附带相关性评分和可选类别。
-
top_phrasestring 可选 -
最重要的短语。
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "ai.keyphrases",
"name": "Extract Key Phrases",
"category": "ai",
"version": "1.0.0",
"description": "Extracts the most important phrases, terms, and concepts from text with relevance scoring. Each phrase is optionally categorized as topic, entity, concept, or action.",
"capabilities": [
"ai",
"nlp",
"keyphrases",
"extraction"
],
"config_schema": {
"type": "object",
"properties": {
"llm_provider_id": {
"type": "string",
"title": "LLM Provider",
"description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
"x-ui-widget": "llm-provider-picker",
"x-llm-provider-capabilities": [
"chat"
]
},
"invocation_mode": {
"type": "string",
"title": "Invocation Mode",
"description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
"enum": [
"sync",
"stream"
],
"default": "sync"
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
"minimum": 1000
},
"max_phrases": {
"type": "number",
"title": "Max Phrases",
"default": 10,
"description": "Maximum number of key phrases to extract."
},
"include_scores": {
"type": "boolean",
"title": "Include Scores",
"default": true,
"description": "Include relevance scores for each phrase."
},
"language": {
"type": "string",
"title": "Language",
"default": "en",
"description": "Language of the input text."
},
"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": {
"text": {
"type": "string",
"description": "Text to extract key phrases from."
}
},
"required": [
"text"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"phrases": {
"type": "array",
"description": "Extracted phrases with relevance score and optional category."
},
"top_phrase": {
"type": "string",
"description": "The most important phrase."
}
}
},
"ports": [
{
"port_id": "success",
"label": "Phrases Extracted",
"description": "Key phrases extracted successfully.",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Extraction failed.",
"is_default": false,
"supports_condition": false
}
],
"execution_mode": "async",
"tags": [
"ai",
"nlp",
"keyphrases",
"extraction",
"text-analysis"
],
"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": {
"llm_provider_id": {
"type": "string",
"title": "LLM Provider",
"description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
"x-ui-widget": "llm-provider-picker",
"x-llm-provider-capabilities": [
"chat"
]
},
"invocation_mode": {
"type": "string",
"title": "Invocation Mode",
"description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
"enum": [
"sync",
"stream"
],
"default": "sync"
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
"minimum": 1000
},
"max_phrases": {
"type": "number",
"title": "Max Phrases",
"default": 10,
"description": "Maximum number of key phrases to extract."
},
"include_scores": {
"type": "boolean",
"title": "Include Scores",
"default": true,
"description": "Include relevance scores for each phrase."
},
"language": {
"type": "string",
"title": "Language",
"default": "en",
"description": "Language of the input text."
},
"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": {
"text": {
"type": "string",
"description": "Text to extract key phrases from."
}
},
"required": [
"text"
]
}{
"type": "object",
"properties": {
"phrases": {
"type": "array",
"description": "Extracted phrases with relevance score and optional category."
},
"top_phrase": {
"type": "string",
"description": "The most important phrase."
}
}
}[
{
"port_id": "success",
"label": "Phrases Extracted",
"description": "Key phrases extracted successfully.",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Extraction failed.",
"is_default": false,
"supports_condition": false
}
]执行
- 执行方式
async- 有状态
- 否
- 重试(
retryOnFail) - 否
- 能力
ainlpkeyphrasesextraction- 标签
ainlpkeyphrasesextractiontext-analysis
说明与限制
- 当
text为空时,worker 会退而使用input,而运行时input始终是上游传入的完整对象。因此“缺少文本”的校验永远不会触发,该对象会被当作消息发送给模型。请始终显式映射text。 - 短语原样取自模型返回值,不校验其顺序、
relevance或category。 - 该 worker 在
data旁返回raw;引擎只把data存为节点输出,因此下游无法读取raw。 - 模型调用经由 Sommatic AI 后端完成,后端根据
llm_provider_id指定的提供方记录解析端点、凭据和部署;编排器从不持有提供方密钥。invocation_mode: "sync"(默认)等待完整回答;"stream"以 SSE 事件读取回答并拼接各片段。 timeout_ms仅在 stream 模式下生效,表示片段之间允许的最长空闲时间(默认 600000)。在 sync 模式下该值只写入日志,不会作用于 HTTP 请求,因此以平台默认请求超时为准。- 在 stream 模式下,后端端点不应用采样参数,因此固定的
temperature: 0仅在 sync 模式下生效。 - 不会自动重试:引擎不会为本节点执行
execution.retryOnFail、maxTries或waitBetweenTries;调用失败会直接从error输出。
已对照编排器代码核实 · 31e874b · 2026-11-26