# Ask files

> Tell Curva what to look for in a Markdown file you can read and edit: a heading and a sentence per rule. It works for any camera, call or document, and edits apply while a stream runs.

Source: https://docs.tarkova.com/curva/guides/ask-files/

## How it works, step by step

1. **Plain words** (/v1/ask-file, One model call, Saved as .md, Optional): You can skip this and write the file yourself. If you pass plain words, the server's model writes them as an ask file once, and the SDK saves it next to your script. Later runs read that file, with no model call, so read what it wrote and edit it. In the example: tell me when a parcel is left at the door took 2.3 s and came back with 3 rules, more than we asked for. We replaced them with one rule of our own, Parcel left.
2. **Parse** (## rule, Bullets, No model call, 32 KB, 64 rules): Each ## heading starts a rule, the sentences under it say what to look for, and bullets change its settings. This is plain text work, so the same file always gives the same result, and a mistake names the line to fix. In the example: Heading ## Parcel left, one sentence, - not: a doormat, - alert: 90% sure. The server read it at cost 0.0.
3. **Questions** (Yes or no, Choice, Score, Text, if speed_kmh): Each rule becomes one typed question, named from its heading. It is yes or no unless a bullet says otherwise, and - not: adds what does not count. The server then runs the same questions as if you had written them in JSON. In the example: parcel_left, yes or no: A parcel or package is on the ground at the door. This does not count: a doormat.
4. **Triggers** (80% sure, 2 of 3 frames, 95% one frame, Destinations): A yes-or-no rule alerts on yes unless told otherwise, while a choice or score rule alerts only when told, and a text rule never does. On video the default is at least 80% sure on 2 of the last 3 judged frames, or one frame at 95%. In the example: The rule became {"if": {"@parcel_left": true}, "min_p": 0.9}.
5. **Sent as text** (decide, listen, watch, Read at start): The SDK reads the file and sends its text, because the server can't read your files. The server reads it once when a stream starts, never per frame, so a frame costs the same as with JSON questions. In the example: curva.watch(frames, ask="rules.md") sent door camera frames to Qwen3-VL on Bedrock.
6. **Alert fires** (Judged frame, action event, Once until stops): Each judged frame answers the rules, and the trigger checks the answers. By default an alert fires once and can fire again only after the rule has stopped holding. In the example: The first frame with a parcel answered yes, 0.999997, in 554 ms. That passed 95%, so parcel_left fired on that one frame.
7. **Save while running** (Every 0.25 s, Checked first, New stream, reloaded): While you watch, the SDK checks the file's time and size every 0.25 s. On a change it asks the server to check the file, opens a new stream under the same stream id with the new text, and closes the old one. In the example: We added ## Door open. The reloaded event came 0.21 s after the save, switch_ms 7.3, and the first answer to the new rule 2.1 s after it, with frames 1.2 s apart.
8. **A bad edit** (Line number, Old rules stay, ask_file_error): If the saved file has a mistake, nothing changes on the stream. You get an error event that names the line and what to change, and the rules you had keep running. In the example: We saved - colour: red. The error said Line 2, Curva does not know the setting, and the next parcel frame still fired parcel_left.

Write what Curva should look for in a plain Markdown file, one heading and one sentence per rule:

```markdown
## Smoke
Smoke or flames are visible anywhere in the picture.

## Someone fell
A person is lying on the floor.
```

```python

for event in curva.watch("rtsp://cam", ask="rules.md"):
    print(event)
```

```ts

for await (const event of new Curva().watch("rtsp://cam", { ask: "rules.md" })) console.log(String(event));
```

Each rule is a yes-or-no question. On `watch` it alerts when the answer is yes, at least 80% sure,
on 2 of the last 3 judged frames (or one frame at 95%). Save the file while the stream runs and the
new rules apply from the next frames.

## Plain words instead of a file

```python
for event in curva.watch("rtsp://cam", ask="tell me when smoke appears or someone falls"):
    print(event)
```

The first run sends the words to the server's model once, which writes them as an ask file. The
SDK saves it next to your script (here `tell-me-when-smoke-appears-or-someone-falls.md`) and says
where. Later runs read that file and make no model call, so edit it like any other ask file.

## Settings

A bullet under a rule changes one thing. Leave them out and the defaults above apply.

```markdown
# Building site

## No hard hat
A person on the site is not wearing a hard hat.
- not: a person inside a closed vehicle cab
- alert: 3 of 5 frames, 90% sure
- webhook: https://example.com/curva

## Position
How is the person positioned?
- choice: standing, sitting, on the floor
- alert: when on the floor

## Shelf
How full is the front shelf?
- score: empty, half full, full
- alert: when empty

## Plate
The number plate of the nearest car, as written.
- text

## Speeding van
A delivery van is in the frame.
- if speed_kmh > 20
```

| Bullet | What it does |
|---|---|
| `- not: ...` | Adds "This does not count: ..." to the rule. Use it for look-alikes. |
| `- choice: a, b, c` | The answer is one of these (plus `none_of_these`). |
| `- score: low, medium, high` | The answer is a level, lowest first. |
| `- text` | The answer is written out. A text rule never alerts. |
| `- alert: when <answer>` | Which answer alerts. Yes-or-no rules alert on yes unless told otherwise; choice and score rules alert only when told. |
| `- alert: 3 of 5 frames` | Alert when the rule holds on 3 of the last 5 judged frames (at most 30). |
| `- alert: 90% sure` | Alert only at this certainty or above (50% to 100%). |
| `- alert: every time` | Alert each time it holds, instead of once until it stops. |
| `- alert: never` | Answer the rule on every frame, with no alert. |
| `- webhook: https://...` | Post the alert there, signed with the project's webhook secret. |
| `- slack:`, `- teams:`, `- discord:`, `- telegram:` | Also post a readable line to that chat (see [Actions](/curva/guides/actions/)). |
| `- if speed_kmh > 20` | Ask the rule only when a reading in `state` matches: `>`, `>=`, `<`, `<=`, `=`, `is` or `contains`. |

The heading names the rule: `## No hard hat` becomes `no_hard_hat` in answers and alerts. A line
starting with a single `#` names the file. Text above the first rule is a note for people. A bullet
without a colon, or any other line, stays part of the rule's description.

## Check a file

```bash
curva ask check rules.md          # each rule in plain words, then the questions and triggers it runs
curva ask check rules.md --json   # only the JSON, ready for a request or a watch start message
```

A mistake names the line and what to change:

```text
rules.md: Line 7: Curva does not know the setting `colour:`, so use one of not, alert, choice, score, text, webhook, slack, teams, discord, telegram or if, or write this line as a sentence without the colon if it describes the rule.
```

## Anywhere `ask` works

The same file works on `decide`, `listen` and `watch`. The SDKs read the file and send its text,
because the server cannot read your files. Over HTTP, send the text itself as `ask`. To see what the
server understood, or to turn plain words into a file, send `{"text": ...}` to `POST /v1/ask-file`.
A file is read with no model call. `listen` takes alerts that do not count frames (`- alert: 3 of 5
frames` is for video).

```python
decision = curva.decide({"ticket": "I was charged twice"}, ask="support-rules.md")
```

## Speed

The file is read once when a stream starts, never per frame. These are the numbers we measured
on an Apple M-series laptop.

| Rules in the file | Parse time (p50) |
|---|---|
| 1 | 3.8 µs |
| 10 | 37 µs |
| 50 | 177 µs |

A frame costs the same with an ask file as with the same questions written as JSON, because the
server runs the same questions either way. Timed on the local tier with every question's head
switched on (300 frames each, release build, 2026-10-27):

| Questions | Ask file, p50 / p99 | JSON, p50 / p99 |
|---|---|---|
| 1 | 15.0 / 45.9 ms | 15.1 / 35.5 ms |
| 5 | 15.0 / 19.0 ms | 15.0 / 26.5 ms |
| 20 | 14.8 / 25.3 ms | 14.9 / 24.1 ms |

The image model takes almost all of that time, so 20 questions cost no more than one.

Saving the file while a stream runs, live on Qwen3-VL (Bedrock), a 72 s driving clip at one frame
a second, four edits: the Python SDK sees the change within 0.25 s and switches to the new rules in
5 ms (p50; 78 ms at most), and the first answer to a new rule arrives 1.06 s after the save (p50,
1.08 s at most), which is mostly the hosted model's own time.

Plain words become a file in about 2 s (p50 of 10, Kimi K2.5 and Qwen3-VL on Bedrock). The first
run with plain words had its first answer after 4.1 s; the next run read the saved file and had it
after 1.9 s, with no model call for the file.

## Examples

Ready files for different kinds of camera come with `curva`:

```bash
curva ask example                       # construction-site, warehouse-fire, elderly-fall, retail-staff-only, parking, traffic, driving
curva ask example warehouse-fire > rules.md
```

`driving` gives exactly the questions of the built-in `driving` set, so its answers are the same.
