@graphit/cli 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/client.d.ts +16 -0
- package/dist/api/client.js +67 -0
- package/dist/api/client.js.map +1 -0
- package/dist/auth/credentials.d.ts +15 -0
- package/dist/auth/credentials.js +34 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/login.d.ts +2 -0
- package/dist/auth/login.js +230 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/token.d.ts +5 -0
- package/dist/auth/token.js +42 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +68 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/connector.d.ts +2 -0
- package/dist/commands/connector.js +97 -0
- package/dist/commands/connector.js.map +1 -0
- package/dist/commands/dashboard.d.ts +2 -0
- package/dist/commands/dashboard.js +124 -0
- package/dist/commands/dashboard.js.map +1 -0
- package/dist/commands/ds.d.ts +2 -0
- package/dist/commands/ds.js +53 -0
- package/dist/commands/ds.js.map +1 -0
- package/dist/commands/kb.d.ts +2 -0
- package/dist/commands/kb.js +505 -0
- package/dist/commands/kb.js.map +1 -0
- package/dist/commands/query.d.ts +2 -0
- package/dist/commands/query.js +61 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/setup.d.ts +2 -0
- package/dist/commands/setup.js +173 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +9 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/output/format.d.ts +8 -0
- package/dist/output/format.js +30 -0
- package/dist/output/format.js.map +1 -0
- package/dist/output/json.d.ts +1 -0
- package/dist/output/json.js +4 -0
- package/dist/output/json.js.map +1 -0
- package/dist/output/table.d.ts +2 -0
- package/dist/output/table.js +17 -0
- package/dist/output/table.js.map +1 -0
- package/dist/update-check.d.ts +3 -0
- package/dist/update-check.js +78 -0
- package/dist/update-check.js.map +1 -0
- package/package.json +1 -1
- package/skills/graphit/SKILL.md +84 -8
- package/skills/graphit/cursor/graphit-kb-actions.mdc +101 -0
- package/skills/graphit/cursor/graphit-kb-awareness.mdc +88 -0
- package/skills/graphit/cursor/graphit-kb-explanation.mdc +56 -0
- package/skills/graphit/cursor/graphit-kb-exploration.mdc +7 -13
- package/skills/graphit/cursor/graphit-kb-graph-structure.mdc +61 -0
- package/skills/graphit/cursor/graphit-kb-traversal.mdc +64 -0
- package/skills/graphit/cursor/graphit-parameterized-metrics.mdc +95 -0
- package/skills/graphit/graphit.mdc +12 -1
- package/skills/graphit/references/kb-actions.md +95 -0
- package/skills/graphit/references/kb-awareness.md +82 -0
- package/skills/graphit/references/kb-explanation.md +50 -0
- package/skills/graphit/references/kb-exploration.md +7 -13
- package/skills/graphit/references/kb-graph-structure.md +55 -0
- package/skills/graphit/references/kb-traversal.md +58 -0
- package/skills/graphit/references/parameterized-metrics.md +89 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# KB-Aware Planning
|
|
2
|
+
|
|
3
|
+
> Load when: planning graphs that involve metrics (aggregations) or dimensions (grouping/filtering columns), or when the user references a business concept that might already exist as a KB asset.
|
|
4
|
+
|
|
5
|
+
Before writing inline SQL with raw aggregations or column references, check whether a KB asset already defines the concept. Using KB assets ensures consistent formulas across dashboards and makes future graphs faster to create.
|
|
6
|
+
|
|
7
|
+
## KB-First Discovery
|
|
8
|
+
|
|
9
|
+
Before proposing graphs with inline aggregations or custom column expressions:
|
|
10
|
+
|
|
11
|
+
1. Check the KB Overview in the system prompt for existing metrics and dimensions
|
|
12
|
+
2. If the KB Overview shows assets that match the user's request, reference them by name
|
|
13
|
+
3. If no matching asset exists, recommend creating it first, then build the graph referencing the new asset
|
|
14
|
+
|
|
15
|
+
If the KB Overview shows tables but no metrics or dimensions, this is the strongest signal to suggest KB asset creation. Propose foundational metrics and dimensions based on the table schema before planning any graphs. If the user explicitly declines ("just build it", "skip KB"), respect that and work from table schema.
|
|
16
|
+
|
|
17
|
+
## When to Propose KB Asset Creation
|
|
18
|
+
|
|
19
|
+
| Signal | Proposed asset | Why |
|
|
20
|
+
|--------|---------------|-----|
|
|
21
|
+
| User requests a business metric (revenue, DAU, conversion rate) with no KB match | Metric | Reusable formula across dashboards |
|
|
22
|
+
| User groups by a derived expression (date bucket, category mapping, JSON extraction) | Dimension | Consistent grouping logic |
|
|
23
|
+
| User describes a business rule ("active means logged in within 30 days") | Rule | Applied automatically to future queries |
|
|
24
|
+
| User uses a business term not in KB ("GMV", "churn", "ARPU") | Synonym | Maps colloquial terms to defined metrics |
|
|
25
|
+
|
|
26
|
+
Propose creation as the default path: "Your KB doesn't have a revenue metric yet. I'd recommend creating one first - that way it's reusable across all your dashboards with a consistent formula. Then I'll build the graph using it. Sound good?"
|
|
27
|
+
|
|
28
|
+
## Metric vs Dimension Distinction
|
|
29
|
+
|
|
30
|
+
| Property | Metric | Dimension |
|
|
31
|
+
|----------|--------|-----------|
|
|
32
|
+
| Formula type | Aggregation required (SUM, COUNT, AVG, MIN, MAX) | Row-level only (no aggregates) |
|
|
33
|
+
| Table scope | Can reference multiple tables | Exactly one table |
|
|
34
|
+
| Purpose | Measures (what you count/sum) | Grouping axes (how you slice) |
|
|
35
|
+
| Example | `SUM(ORDERS.AMOUNT)` | `DATE_TRUNC('month', EVENTS.EVENT_TS)` |
|
|
36
|
+
| Invalid example | `ORDERS.AMOUNT` (no aggregate) | `SUM(EVENTS.DURATION)` (has aggregate) |
|
|
37
|
+
|
|
38
|
+
## Topics
|
|
39
|
+
|
|
40
|
+
When creating any KB asset, consider which business topic it belongs to and pass `topics` (e.g., `["ACQUISITION"]`, `["MONETIZATION"]`). Check the KB Overview for existing topic names first to avoid duplicates. UPPER_SNAKE_CASE.
|
|
41
|
+
|
|
42
|
+
## Reuse Over Reinvention
|
|
43
|
+
|
|
44
|
+
When planning multi-graph dashboards, identify shared concepts across graphs and propose KB assets for them:
|
|
45
|
+
|
|
46
|
+
- If 3 graphs all use `SUM(ORDERS.AMOUNT)`, propose a TOTAL_REVENUE metric once
|
|
47
|
+
- If 2 graphs group by `DATE_TRUNC('month', TS)`, propose a MONTHLY dimension once
|
|
48
|
+
- Reference the KB asset by name in subsequent graphs instead of repeating the formula
|
|
49
|
+
|
|
50
|
+
## Cross-Table Referencing
|
|
51
|
+
|
|
52
|
+
When a metric or dimension already exists on one table and the user wants the same concept on a sibling table with identical columns, **reference it** instead of creating a duplicate:
|
|
53
|
+
|
|
54
|
+
`edit(entity_type="metric", id="TOTAL_REVENUE", secondary_tables=["ORDERS_12M"])`
|
|
55
|
+
|
|
56
|
+
- Metrics/dimensions: the target table must contain every column the formula references (validated on save).
|
|
57
|
+
- Rules: the target table just needs to exist (no column check).
|
|
58
|
+
- This is a pointer, not a copy. Edits propagate to all placements.
|
|
59
|
+
- In the KB tree, referenced placements appear with a `*` suffix and link back to the original.
|
|
60
|
+
|
|
61
|
+
Suggest referencing when: the user has sibling data sources with the same schema (e.g., 6M and 12M windows), or asks to "make X available on Y table".
|
|
62
|
+
|
|
63
|
+
> For metric formula syntax, aggregation patterns, and WHERE clause rules, see `kb_authoring/references/formula-syntax.md`. For creating KB assets, hand off to `kb_authoring`.
|
|
64
|
+
|
|
65
|
+
## KB Graph Navigation
|
|
66
|
+
|
|
67
|
+
For structural questions about the KB (what is a topic, what depends on X, how do domains work), graph traversal, or KB organization requests, activate the `kb_navigation` shared skill. It provides:
|
|
68
|
+
|
|
69
|
+
- `kb_explore` tool for graph traversal (what depends on X, what joins with Y)
|
|
70
|
+
- Structural explanations grounded in actual KB data
|
|
71
|
+
- Full action parity with the manual KB page UI
|
|
72
|
+
- Topic and domain filtering via `search` tool
|
|
73
|
+
|
|
74
|
+
**When to activate kb_navigation vs stay in current skill:**
|
|
75
|
+
|
|
76
|
+
| User Intent | Activate kb_navigation? |
|
|
77
|
+
|-------------|------------------------|
|
|
78
|
+
| "What is a topic?" or "How do domains work?" | Yes - structural question |
|
|
79
|
+
| "What depends on this table?" | Yes - graph traversal |
|
|
80
|
+
| "Organize my KB" or "Clean up topics" | Yes - KB management |
|
|
81
|
+
| "Show me revenue metrics for my graph" | No - use search + read, stay in current skill |
|
|
82
|
+
| "Create a metric called X" | No - use kb_expert or kb_authoring |
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# KB Explanation - Structural Q&A Patterns
|
|
2
|
+
|
|
3
|
+
Tier 1 structural questions about KB concepts. Answer these using the patterns below, grounded in actual KB data when possible. Use business-friendly language - no implementation details.
|
|
4
|
+
|
|
5
|
+
## Tier 1: Structural (In Scope)
|
|
6
|
+
|
|
7
|
+
Answer directly using these patterns. Always verify against actual KB state when the question involves specific entities.
|
|
8
|
+
|
|
9
|
+
### What is a topic?
|
|
10
|
+
A topic is a business concept tag you apply to metrics, dimensions, rules, and synonyms. Examples: REVENUE, ACQUISITION, RETENTION. Any asset can have multiple topics. Topics help organize the KB by business meaning rather than physical table location.
|
|
11
|
+
|
|
12
|
+
### What is a domain?
|
|
13
|
+
A domain is a high-level business area like MARKETING, SALES, or PRODUCT. Domains are broader than topics - think of them as departments or business units. A domain is set on a table, and every metric, dimension, and rule built on that table belongs to that domain automatically. An org typically has 3-10 domains and 10-30+ topics.
|
|
14
|
+
|
|
15
|
+
### How do domains and topics differ?
|
|
16
|
+
The difference is granularity and how they attach:
|
|
17
|
+
- A **domain** is coarse (5-10 per org: MARKETING, FINANCE, PRODUCT) and is set on the table. Each asset has one home domain, inherited from the table its data comes from. An asset can also be marked relevant to a few extra domains when it genuinely spans areas.
|
|
18
|
+
- A **topic** is fine (10-30+ per org: REVENUE, ACQUISITION, RETENTION) and is tagged directly on assets. An asset can carry several topics at once.
|
|
19
|
+
|
|
20
|
+
A single domain like MARKETING might contain topics like ACQUISITION, ATTRIBUTION, and CAMPAIGN_PERFORMANCE.
|
|
21
|
+
|
|
22
|
+
### What is a table in the KB?
|
|
23
|
+
A table represents a physical data location in the warehouse. Metrics and dimensions depend on tables because their SQL formulas reference table columns. Tables are structural, not tags - the dependency is derived from the SQL, not manually assigned.
|
|
24
|
+
|
|
25
|
+
### What is a relationship?
|
|
26
|
+
A relationship documents a JOIN between two tables. It specifies which columns connect them and what kind of join to use. When the agent writes SQL across multiple tables, it uses relationships to build correct JOINs.
|
|
27
|
+
|
|
28
|
+
### Why is [metric] under [table]?
|
|
29
|
+
A metric appears under a table because the metric's SQL formula depends on columns in that table. Check the metric's dependencies to see exactly which columns it uses. A metric can depend on multiple tables - it appears under each one, with the first listed as primary. An asset can also appear under a table via **referencing** (`secondary_tables`) - this shows as a `*` marker in the tree and means the asset was made available on that table as a read-only pointer. The original lives on its home table.
|
|
30
|
+
|
|
31
|
+
### Why is [asset] in [topic]?
|
|
32
|
+
An asset appears under a topic because someone (user, agent, or scanner) tagged it with that topic. Topics are manually assigned tags, not automatically derived. Check the asset's topics list to see all its topic assignments.
|
|
33
|
+
|
|
34
|
+
### Why is [asset] in [domain]?
|
|
35
|
+
An asset's domain comes from the table its data lives in: whoever set the table's domain, every asset on that table inherits it. So a metric is in MARKETING because its primary table is a MARKETING table, not because the metric itself was tagged. If an asset genuinely spans areas, it can also be marked relevant to extra domains, which show as badges and match domain filters without moving it in the tree. To change a metric's home domain, change the domain on its table.
|
|
36
|
+
|
|
37
|
+
### How do tables and topics differ?
|
|
38
|
+
Tables are physical (where the data lives in the warehouse). Topics are conceptual (what the data is about). One table can have assets tagged with many different topics, and one topic can span assets across multiple tables.
|
|
39
|
+
|
|
40
|
+
### What is memory?
|
|
41
|
+
Memory stores org-level context notes - background information about the organization, its goals, terminology, or conventions. Memory is global (not scoped to any table, domain, or topic) and appears at the root of the KB tree.
|
|
42
|
+
|
|
43
|
+
## Tier 2: Semantic (Out of Scope for This Skill)
|
|
44
|
+
|
|
45
|
+
Questions about what a specific business concept means at this organization (e.g., "what does revenue mean for us?", "how do we define an active user?") are semantic questions, not structural ones. For these:
|
|
46
|
+
1. Search the KB for the relevant metric or rule
|
|
47
|
+
2. Read its description and calculation
|
|
48
|
+
3. Present what the KB says - do not interpret or extend it
|
|
49
|
+
|
|
50
|
+
Do not attempt to answer semantic questions from general knowledge. The KB is the source of truth for this org's definitions.
|
|
@@ -6,12 +6,11 @@ Consult when starting a dashboard build. The Knowledge Base contains reusable me
|
|
|
6
6
|
|
|
7
7
|
Before writing raw SQL with inline aggregations or column references:
|
|
8
8
|
|
|
9
|
-
1.
|
|
10
|
-
2.
|
|
11
|
-
3. If
|
|
12
|
-
4.
|
|
13
|
-
|
|
14
|
-
KB assets ensure consistent formulas across dashboards. If 3 charts all need `SUM(ORDERS.AMOUNT)`, one TOTAL_REVENUE metric is better than 3 inline aggregations.
|
|
9
|
+
1. Understand organization: `graphit kb list domains` shows business-area groupings (MARKETING, PRODUCT, FINANCE, etc.)
|
|
10
|
+
2. List what exists: `graphit kb list metrics`, `graphit kb list dimensions`, `graphit kb list rules`
|
|
11
|
+
3. If a KB metric matches the user's request, use its formula: `graphit kb get metric REVENUE`
|
|
12
|
+
4. If no match exists, consider whether to build the dashboard from raw columns or suggest KB asset creation first
|
|
13
|
+
5. Explore relationships: `graphit kb explore metric REVENUE` shows which tables and dimensions connect to a metric
|
|
15
14
|
|
|
16
15
|
## Metric vs Dimension
|
|
17
16
|
|
|
@@ -34,13 +33,6 @@ All KB assets use UPPER_SNAKE_CASE. The names are auto-sanitized:
|
|
|
34
33
|
| `COUNT_*` | `COUNT_ACTIVE_USERS` | Count metrics |
|
|
35
34
|
| `*_RATE` | `CONVERSION_RATE`, `CHURN_RATE` | Ratios/percentages |
|
|
36
35
|
|
|
37
|
-
## Reuse Over Reinvention
|
|
38
|
-
|
|
39
|
-
When building multi-chart dashboards, identify shared concepts:
|
|
40
|
-
- If 3 charts use `SUM(ORDERS.AMOUNT)`, reference one TOTAL_REVENUE metric
|
|
41
|
-
- If 2 charts group by `DATE_TRUNC('month', TS)`, reference one MONTHLY dimension
|
|
42
|
-
- Discover existing assets: `graphit kb search "revenue"`
|
|
43
|
-
|
|
44
36
|
## When to Suggest KB Asset Creation
|
|
45
37
|
|
|
46
38
|
| Signal | Propose |
|
|
@@ -67,3 +59,5 @@ CASE WHEN USERS.AGE >= 18 THEN 'adult' ELSE 'minor' END
|
|
|
67
59
|
```
|
|
68
60
|
|
|
69
61
|
Conditionals use CASE WHEN (not FILTER WHERE - Snowflake doesn't support it). Always guard division with NULLIF.
|
|
62
|
+
|
|
63
|
+
For deeper coverage, consult: `kb-graph-structure.md` (graph model), `kb-awareness.md` (KB-first planning), `kb-explanation.md` (structural Q&A), `parameterized-metrics.md` (metric templates), `kb-traversal.md` (graph queries), `kb-actions.md` (full CRUD).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# KB Graph Structure
|
|
2
|
+
|
|
3
|
+
The Knowledge Base is a labeled property graph. Assets carry tags that place them in a tree, but the underlying structure is a graph with typed edges.
|
|
4
|
+
|
|
5
|
+
## Node Types
|
|
6
|
+
|
|
7
|
+
| Type | Count Range | Description |
|
|
8
|
+
|------|-------------|-------------|
|
|
9
|
+
| metric | 10-200+ | Aggregation formula (SUM, COUNT, AVG) that computes a business KPI |
|
|
10
|
+
| dimension | 20-500+ | Row-level SQL expression on one table, used for grouping or filtering |
|
|
11
|
+
| rule | 5-100+ | Free-text business constraint, optionally scoped to one or more tables |
|
|
12
|
+
| synonym | 10-100+ | Maps a business term to a canonical metric, dimension, or column |
|
|
13
|
+
| table | 2-50+ | Physical data location in the warehouse, with typed columns |
|
|
14
|
+
| topic | 5-30+ | Business-concept tag applied to assets (e.g., REVENUE, ACQUISITION) |
|
|
15
|
+
| domain | 3-10 | High-level business area (e.g., MARKETING, SALES, PRODUCT) |
|
|
16
|
+
| relationship | 2-30+ | Documented JOIN pattern between two tables |
|
|
17
|
+
| memory | 1-5 | Org-level context notes, always global scope |
|
|
18
|
+
|
|
19
|
+
## Edge Types
|
|
20
|
+
|
|
21
|
+
| Edge | From | To | Meaning |
|
|
22
|
+
|------|------|----|---------|
|
|
23
|
+
| depends_on | metric, dimension | table | Asset's SQL references columns in this table |
|
|
24
|
+
| tagged_with | metric, dimension, rule, synonym | topic | Asset carries this business-concept tag |
|
|
25
|
+
| in_domain | table, metric, dimension, rule, synonym | domain | A table has one home domain; assets inherit that home from their primary table, plus any cross-cutting extras |
|
|
26
|
+
| joins | relationship | table, table | Two tables have a documented JOIN on specific columns |
|
|
27
|
+
| references | rule, synonym | table, column | Rule or synonym references a specific table or column name |
|
|
28
|
+
|
|
29
|
+
## Multi-Membership Semantics
|
|
30
|
+
|
|
31
|
+
Tables and topics are multi-valued; domain works differently - a single **home** that cascades:
|
|
32
|
+
|
|
33
|
+
- A metric can depend on **multiple tables** (e.g., JOIN across ORDERS and CUSTOMERS), and appears under each.
|
|
34
|
+
- An asset has **one home domain**, inherited from its primary table (the first table its SQL depends on). The asset does not carry its own domain tag - set the domain on the table and every asset on that table inherits it.
|
|
35
|
+
- An asset can carry **multiple topics** (e.g., ARPU tagged with both REVENUE and MONETIZATION).
|
|
36
|
+
- An asset can be **referenced** onto additional tables via `secondary_tables`. Referenced placements appear in the tree under the target table with a `*` suffix and link back to the original. The asset is editable only from its home table.
|
|
37
|
+
- Synonyms can carry **cross-cutting domains** in `extra_domain_ids` for relevance beyond the home domain. Table-backed assets (metrics, dimensions, rules) derive domain membership entirely from their tables.
|
|
38
|
+
|
|
39
|
+
For multiple tables, the tree shows the asset under each table with a link icon. For domain, the tree places each table (and its assets) under its one home domain only - cross-cutting extras are badges, not duplicate placements.
|
|
40
|
+
|
|
41
|
+
## Tags vs Structure
|
|
42
|
+
|
|
43
|
+
| Concept | Type | Cardinality | Notes |
|
|
44
|
+
|---------|------|-------------|-------|
|
|
45
|
+
| Domain | Home (on table) + secondary_tables | One home per asset (from its table); domain derived from all tables | Coarser grouping (~5-10 per org). Home cascades from the primary table; `secondary_tables` extends reach; synonyms use `extra_domain_ids` |
|
|
46
|
+
| Topic | Pure tag | Any (typically 1-3) | Finer grouping (~10-30+ per org) |
|
|
47
|
+
| Table | Structural dependency | Any (typically 1-2) | Based on SQL dependencies, not manual tagging |
|
|
48
|
+
| Relationship | First-class edge | Exactly 2 tables | Explicit JOIN documentation |
|
|
49
|
+
| Memory | Global | N/A | Not scoped to any table, domain, or topic |
|
|
50
|
+
|
|
51
|
+
**Key insight for traversal:** Topics are multi-valued tags on assets (agent adds/removes via `edit`). Domain is a single home set on the **table** (`edit(entity_type="table", domain_id=...)`), which cascades to every asset on that table. Table-backed assets derive domain membership from all their tables (primary + `secondary_tables`). Synonyms use `extra_domain_ids` for cross-cutting domain relevance. Table dependencies are structural (derived from SQL). Relationships are explicit edges between tables.
|
|
52
|
+
|
|
53
|
+
## Tree Rendering Order
|
|
54
|
+
|
|
55
|
+
The default tree renders as: Domain > Table > Topic > Asset, where each table sits under its one home domain. This is a visualization choice; the data model also supports other groupings (Topic > Table, flat list). When the user asks "where is X?", an asset lives under its primary table's home domain - report that, plus any domains from its `secondary_tables` placements and its topics.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# KB Traversal - Worked Examples
|
|
2
|
+
|
|
3
|
+
Common graph queries and which tool to use for each. Agent tool names map to CLI commands: `search` = `graphit kb search`, `read` = `graphit kb get`, `list` = `graphit kb list`, `kb_explore` = `graphit kb explore`.
|
|
4
|
+
|
|
5
|
+
## Tool Selection Guide
|
|
6
|
+
|
|
7
|
+
| Question Shape | Best Tool | Why |
|
|
8
|
+
|----------------|-----------|-----|
|
|
9
|
+
| Semantic ("find things like X") | `search` | Embedding-based discovery across all asset types |
|
|
10
|
+
| Pointed retrieval ("get metric Y") | `read` | Direct fetch by exact name, returns full details |
|
|
11
|
+
| Topic/domain filter ("metrics in REVENUE") | `search` with topics/domain params | Filtered discovery, intersects with query |
|
|
12
|
+
| Connectivity ("what depends on X") | `kb_explore` | Graph walk from a starting entity, returns typed edges |
|
|
13
|
+
| Joins specifically | `kb_explore` with edge_types=["joins"] | Targeted relationship traversal |
|
|
14
|
+
| Multi-hop ("what's 2 hops from X") | `kb_explore` with max_depth=2 | Recursive walk, capped at 3 hops |
|
|
15
|
+
|
|
16
|
+
## Common Queries
|
|
17
|
+
|
|
18
|
+
### "Find all revenue metrics"
|
|
19
|
+
Use `search` with a topic filter to get metrics tagged with the REVENUE topic. If the user means revenue conceptually (not a specific topic), use a semantic search query instead.
|
|
20
|
+
|
|
21
|
+
### "What depends on ORDERS table?"
|
|
22
|
+
Use `kb_explore` starting from the table, filtering to depends_on edges. Returns all metrics and dimensions whose SQL references ORDERS columns.
|
|
23
|
+
|
|
24
|
+
### "What joins with MARKETING_UA_DS?"
|
|
25
|
+
Use `kb_explore` starting from the table, filtering to joins edges. Returns relationship entities that document JOINs involving that table.
|
|
26
|
+
|
|
27
|
+
### "What domains do we have?"
|
|
28
|
+
Use `list` with the domain entity type (`list(entity_type="domain")`). It returns every domain with its description and asset_count, plus an "Uncategorized" entry when tables with no domain exist. Report all of them, including ones with asset_count=0. Do NOT use `search` (domain is not a searchable type) or `kb_explore` (it traverses from one named domain - a wildcard like "*" returns nothing).
|
|
29
|
+
|
|
30
|
+
### "What's left in uncategorized?"
|
|
31
|
+
Two paths: (1) `list(entity_type="table")` and filter for `domain_id=null` to find unassigned tables, then `kb_explore(entity_type="domain", entity_name="Uncategorized")` to get all tables and assets in the pseudo-domain; or (2) just use `kb_explore(entity_type="domain", entity_name="Uncategorized")` directly to get everything.
|
|
32
|
+
|
|
33
|
+
### "Show me everything in the MARKETING domain"
|
|
34
|
+
Use `kb_explore` starting from the domain. Returns tables (via in_domain edge) and all assets within those tables (via depends_on edges at depth 2).
|
|
35
|
+
|
|
36
|
+
### "What topics does ARPU_D1 belong to?"
|
|
37
|
+
Use `kb_explore` starting from the metric, filtering to tagged_with edges. Returns all topic nodes the metric is tagged with.
|
|
38
|
+
|
|
39
|
+
### "Find metrics in same table as ARPU_D1 but different topic"
|
|
40
|
+
Two-step query:
|
|
41
|
+
1. Use `kb_explore` on ARPU_D1 to find its table(s) and topic(s)
|
|
42
|
+
2. Use `search` filtered to that table's metrics, then compare topics in the results
|
|
43
|
+
|
|
44
|
+
### "What domains have retention metrics?"
|
|
45
|
+
Use `search` with topics=["RETENTION"] and types=["metric"]. A metric's domain is derived from its dependency tables and secondary_tables - there is no domain field directly on the metric. Group the results by that effective domain. To get the home domain for one metric, `kb_explore` from the metric with edge_types=["in_domain"] returns it.
|
|
46
|
+
|
|
47
|
+
### "Show me the full graph around table X"
|
|
48
|
+
Use `kb_explore` with max_depth=2 and no edge_type filter. Returns the table's domain, all dependent assets, all topics those assets carry, and all relationships the table participates in.
|
|
49
|
+
|
|
50
|
+
## Depth Guidelines
|
|
51
|
+
|
|
52
|
+
| Depth | Use When |
|
|
53
|
+
|-------|----------|
|
|
54
|
+
| 1 (default) | Direct neighbors only. Best for most questions. |
|
|
55
|
+
| 2 | When you need one extra hop (e.g., table's assets AND their topics) |
|
|
56
|
+
| 3 (max) | Full neighborhood. Use sparingly - can return many results for connected tables. |
|
|
57
|
+
|
|
58
|
+
Start at depth 1. Only increase if the user's question requires it or the initial results are insufficient.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Parameterized Metrics
|
|
2
|
+
|
|
3
|
+
A parameterized metric is a template with `${PARAM:NAME}` tokens in its calculation. Each token maps to a named parameter with a list of values (value_name to SQL fragment). The system auto-generates child variants for every combination of parameter values.
|
|
4
|
+
|
|
5
|
+
Example: ROAS with parameters REVENUE (9 values) and DN (4 values) produces 36 validated child metrics from 1 template.
|
|
6
|
+
|
|
7
|
+
## When to Parameterize
|
|
8
|
+
|
|
9
|
+
**Create parameterized** when columns follow a variant pattern:
|
|
10
|
+
- `total_iap`, `total_iap_new_users`, `estimated_gross_iap` -> one REVENUE parameter
|
|
11
|
+
- Metrics that differ only by a WHERE clause (D7, D30, D90) -> one DN parameter
|
|
12
|
+
|
|
13
|
+
**Stay standalone** when:
|
|
14
|
+
- Metric has no natural variants
|
|
15
|
+
- Only 1-2 variants (template overhead not worth it)
|
|
16
|
+
- Variants use fundamentally different formulas
|
|
17
|
+
|
|
18
|
+
## Creating a Parameterized Metric
|
|
19
|
+
|
|
20
|
+
Use `${PARAM:NAME}` tokens in the calculation, then pass `parameters` with the value map. The `placeholder` field is optional (omit it for the new token format):
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
"calculation": "SUM(${PARAM:REVENUE}) / SUM(cost) * 100 ${PARAM:DN}",
|
|
24
|
+
"parameters": [
|
|
25
|
+
{
|
|
26
|
+
"name": "REVENUE",
|
|
27
|
+
"values": {"ALL_BOOKINGS": "total_iap", "NEW_BOOKINGS": "total_iap_new_users"},
|
|
28
|
+
"default_value": "ALL_BOOKINGS"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "DN",
|
|
32
|
+
"values": {"D0": "", "D7": "WHERE day <= 7"},
|
|
33
|
+
"default_value": "D0"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| Rule | Detail |
|
|
39
|
+
|------|--------|
|
|
40
|
+
| Token matching | Every `${PARAM:NAME}` in the calculation must have a matching parameter by name |
|
|
41
|
+
| Empty values | Valid as no-ops (e.g. D0 adds no filter) |
|
|
42
|
+
| Variant cap | Max 100 (Cartesian product of all parameter values) |
|
|
43
|
+
| Child naming | Auto-generated: `{PARENT}_{VALUE1}_{VALUE2}` (e.g. ROAS_ALL_BOOKINGS_D7) |
|
|
44
|
+
|
|
45
|
+
## Editing a Template
|
|
46
|
+
|
|
47
|
+
All edits go through the parent template. Children are read-only.
|
|
48
|
+
|
|
49
|
+
| User intent | Edit action |
|
|
50
|
+
|-------------|-------------|
|
|
51
|
+
| Change formula | Edit `calculation` on the template - children re-generate |
|
|
52
|
+
| Add a variant (e.g. D120) | Edit `parameters`, add the new value to the relevant parameter |
|
|
53
|
+
| Remove variants | Edit `parameters`, remove values from the relevant parameter |
|
|
54
|
+
| Change description/topics | Edit those fields on the template - no child re-generation |
|
|
55
|
+
|
|
56
|
+
If a child metric is targeted for edit or delete, redirect to the parent:
|
|
57
|
+
"ROAS_ALL_BOOKINGS_D7 is a variant of ROAS. Edit the parent template ROAS instead."
|
|
58
|
+
|
|
59
|
+
## Using Parameterized Metrics in Queries
|
|
60
|
+
|
|
61
|
+
When a user asks for a specific variant (e.g. "show me D7 ROAS for new users"):
|
|
62
|
+
|
|
63
|
+
1. Find the template in KB context (marked with `[P:N]` in the tree)
|
|
64
|
+
2. Infer axis values from the user's message: REVENUE=NEW_BOOKINGS, DN=D7
|
|
65
|
+
3. Use `read` with `entity_type="metric"` and pass `axis_values` to get the resolved child
|
|
66
|
+
4. Use the returned validated child calculation in your graph SQL
|
|
67
|
+
|
|
68
|
+
### NEVER
|
|
69
|
+
- Substitute tokens manually in the template formula. Always use the backend-returned child SQL, which has been pre-validated.
|
|
70
|
+
|
|
71
|
+
### Defaults and Errors
|
|
72
|
+
- **Default resolution:** When the user doesn't specify parameters, pass empty `axis_values` - the backend fills defaults.
|
|
73
|
+
- **Invalid values:** If you pass an invalid axis value, the backend returns valid options. Retry with a valid value or ask the user.
|
|
74
|
+
|
|
75
|
+
## Contrast: Wrong vs Right
|
|
76
|
+
|
|
77
|
+
| Wrong | Right |
|
|
78
|
+
|-------|-------|
|
|
79
|
+
| Manually replace `${PARAM:REVENUE}` with `total_iap` in the formula and pass to graph SQL | Use `read` with `axis_values` to get pre-validated child calculation |
|
|
80
|
+
| Create separate ROAS_ALL_BOOKINGS, ROAS_NEW_BOOKINGS as standalone metrics | Create one ROAS template with a REVENUE parameter |
|
|
81
|
+
| Edit ROAS_ALL_BOOKINGS_D7 directly | Edit the parent ROAS template instead |
|
|
82
|
+
|
|
83
|
+
## Deleting a Template
|
|
84
|
+
|
|
85
|
+
Delete on the parent cascade-deletes all children. Blast radius includes all children plus their downstream refs (graphs, rules, synonyms).
|
|
86
|
+
|
|
87
|
+
## Verification
|
|
88
|
+
|
|
89
|
+
Verify on a template sets `verified=True` on the parent and all children.
|