Documentation · Knowledge
Metrics and definitions
A metric in Corvu is a file with a formula, not a paragraph in a glossary. The agent does not retell a definition: it fetches it with a tool and puts it into the query verbatim — which is why “revenue” is counted the same way every time.
What a metric is
A file in the project's “Knowledge” — for example olist/metrics/revenue_goods.sql. The header is written as comments in the file's own language (-- in SQL, # in Python, <!-- --> in Markdown), so the file stays ordinary: its query runs in any SQL client. A file with a metric key in its header declares a metric.
The first-level folder names the source the metric belongs to. A metric in the workspace layer applies in every project; a project's metric of the same name overrides it — the narrower wins.
Header fields
| Field | Required | Meaning |
|---|---|---|
name | no | The name people call the metric by: “Goods revenue”. |
description | no | What the metric is for and which words to find it by (“revenue”, “turnover”). The agent sees the name and description up front, the formula only when it fetches the definition. |
metric | yes | The identifier: lowercase Latin letters, digits and _, up to 64 characters. The agent fetches the definition by it, and the result column is named after it. |
formula | yes | The expression we calculate: sum(i.price). |
from | yes | Over which tables: orders o join order_items i on …. Required: a formula without its own FROM is a number counted over somebody else's rows (orders and order lines give different totals). |
filters | no | What we leave out: o.order_status not in ('canceled', 'unavailable'). |
time | no | The date column the metric is cut by period on. |
grain | no | What one row of the source is: order_items. |
dimensions | no | Breakdowns. A breakdown from a table outside from carries its own join: customer_state via join customers c on …. |
kind | no | amount, count or ratio: whether the value can be added across a breakdown. |
direction | no | up_is_good, down_is_good or neutral: which way is good for the value. |
owner, source | no | Who answers for the metric and which source it belongs to, when the folder does not say. |
certified | no | true — a person vouches for the definition. Only a person sets it; the agent never writes this key. |
A value with a colon (for example ::date in a formula) is fine: a header line continues until the next known key appears. An unknown key is read not as a key but as a continuation of the previous value.
A full example
-- name: Goods revenue
-- description: Revenue from goods, shipping excluded. The default metric for "revenue", "turnover" and "sales" unless "with shipping" is said.
-- metric: revenue_goods
-- formula: sum(i.price)
-- from: orders o join order_items i on i.order_id = o.order_id
-- filters: o.order_status not in ('canceled', 'unavailable')
-- time: o.order_purchase_timestamp
-- grain: order_items
-- dimensions: customer_state via join customers c on c.customer_id = o.customer_id,
-- seller_id
-- kind: amount
-- direction: up_is_good
select sum(i.price) as revenue_goods
from orders o
join order_items i on i.order_id = o.order_id
where o.order_status not in ('canceled', 'unavailable');
The whole file: the header plus a query you can run as it is. If you remove from or formula, the metric is not declared and the “Metrics” screen shows a problem naming the file.
How the agent fetches a definition
- The system prompt gets the list of declared metrics — names and descriptions, without formulas.
- For a question about “revenue” the agent starts by calling
use_metric("revenue_goods"): the tool returns the expression, FROM and WHERE verbatim, the date column and a minimal query without time grouping. - Metrics with different
fromare counted in separate CTEs — otherwise orders with no lines would drop out of the count. - The “applied” mark is set only if the metric's formula (case and spacing ignored) really stands in the code of some block. An agent that fetched the definition and then wrote its own sum gets no mark.
Two files, one dispute. If two files declare the same metric for the same source, Corvu does not pick: the “Metrics” screen shows both files and the agent calls the definition disputed. The narrower wins: a source's metric overrides a general one of the same name, and that is not a conflict.
The number passport
Press a number in an answer, in a document or on a metric tile and “Where this number came from” opens: the block's code, the source, the applied metrics (each with its “applied” mark), the date the data is as of, the version and its reason (question, rebuild, schedule). If the number came from the cache, the passport says how many minutes old it is; if the source counts in another time zone, it adds a note about server time.
The passport is not a quality score but provenance: it shows exactly what was calculated, so that it can be checked.
How to add or change a metric
- In “Knowledge” open “Metrics” and press “New metric” — the file name is taken from the identifier (lowercase Latin).
- Edit the file right in “Knowledge”: changes apply from the next question.
- Ask the agent to record a definition. It proposes the text first and writes to knowledge only after your “Yes”.
- From a script:
corvu context push file.sqlorPUT /api/public/v1/context/filewithbase_hash, so a colleague's edit is not overwritten (see API and CLI).
“Applied” and “certified” are different things. The first means the formula stands in the query; the second means a person vouches for it (certified: true). The agent never writes that header line.
Ready to try it? Demo data is already inside.
Request access Sign in