ai
Description
The command sends a request to an external language model.
The command requires a configured sm-ai service to work.
Syntax
... | ai [model="<model>"] [output="<field>[,<field>]"] [mode=summary|per_row] [preset=<preset>] [system_message="<text>"] [user_message="<text>"] [input="<field>[,<field>]"|"*"] [temperature=<number>] [max_tokens=<int>] [max_prompt_tokens=<int>] [timeout=<int>]
You can omit model and output if they are set in the preset specified by the preset argument. Otherwise, both arguments are required.
Optional Arguments
| Parameter | Syntax | Default Value | Description |
|---|---|---|---|
model | model="<model_name>" | From the selected preset | Name of the language model registered in the model registry. |
output | output="<field>[,<field>]" | From the selected preset | Result field name or comma-separated list of result field names. |
mode | mode=summary or mode=per_row | summary | Processing mode: summary reduces the entire context to one result row; per_row enriches each row with fields from output. |
preset | preset=<preset_name> | Name of a preset with predefined parameters. Explicit command arguments take precedence over preset values. | |
system_message | system_message="<text>" | Model system instruction. | |
user_message | user_message="<text>" | Model user instruction. | |
input | input="<field>[,<field>]" or input="*" | * | Row fields passed as context; * means all fields. |
temperature | temperature=<number> | Generation temperature. | |
max_tokens | max_tokens=<int> | Response token limit. | |
max_prompt_tokens | max_prompt_tokens=<int> | 60000 | Prompt token limit. |
timeout | timeout=<int> | Taken from sme.ai.timeout | Provider request timeout, ms. |
Presets are configured in the system interface. Preset parameters apply by default; explicit command arguments take precedence over them.
Processing Modes
summary (default)
Transforms the entire set of rows into one result row:
- One LLM call is executed for the entire context
- One result row is returned
- The result row contains only fields from
output - For multiple
outputfields, a JSON object is expected in the model response
per_row
Enriches each source row with fields from output:
- One LLM call is executed for all rows
- A response with results for each row is expected
- Source fields are preserved in the result rows and enriched with
outputfields - If
inputlimits the context, only the specified fields go into the prompt. The result rows are still based on the source rows and supplemented with fields fromoutput
System Settings
Settings are stored in _cluster/settings. The table lists the ai command settings and their default values.
| Name | Description | Default Value |
|---|---|---|
sme.ai.inference_server_url | Inference service base URL. | https://localhost |
sme.ai.inference_server_port | Inference service port. | 8010 |
sme.ai.timeout | Inference service request timeout, ms. | 300000 |
Query Examples
Example 1
Example of using summary to analyze a k8s trace.
source k8s_otel_traces
| search traceId="6955d7042d2182d3be9a840e15bbb3ee"
| ai model="gpt-oss-20b" user_message="What's wrong with this trace" output="summary"
Result (one row):
[
{"summary": "There is a connection error to adservice in the trace."}
]
Example 2
Example of using per_row with multiple result fields: semantic search with row enrichment.
source soc_events_prod
| semanticsearch
vector_field="event_embedding"
query="Signs of lateral movement via remote command execution and credential theft"
model_id="zXjJepwBnjnQtEv1MFtK"
| ai
model="gpt-oss-20b"
mode=per_row
input="host.name,user.name,message"
user_message="For each row return risk, type, reason"
output="risk,type,reason"
Result (rows enriched with new fields):
[
{
"host.name": "srv-1",
"user.name": "admin",
"message": "wmic remote process create",
"risk": "high",
"type": "lateral_movement",
"reason": "Remote process execution via WMI."
},
{
"host.name": "srv-2",
"user.name": "svc",
"message": "normal login",
"risk": "low",
"type": "benign_activity",
"reason": "No signs of attack detected."
}
]
Example 3
Example of using a preset while overriding user_message.
source soc_events_prod
| ai preset=my_preset output="summary" mode=summary user_message="How to fix the problem"
Example 4
Example with explicitly set limits.
source k8s_otel_traces
| ai model="gpt-oss-20b" output="summary" max_prompt_tokens=5000 max_tokens=700 timeout=600000