anfra docsAlpha
Semantic layer

Overview

Define your metrics, dimensions and joins once, as code, so every app and agent gets the same answer

Every query in a data app and every answer from an agent goes through the semantic layer. A number defined once here means the same thing on every page that uses it.

Why a semantic layer

A question like "What was revenue last month?" has many possible answers in a warehouse. Which tables hold orders, how they join to products, and whether revenue includes refunds are decisions someone has to make, and make the same way every time.

The semantic layer records those decisions once, as code in your project. Apps and agents then ask for "revenue by month" by name, and anfra generates the SQL, joins included. Every page and every agent that asks the same question gets the same number.

  • Define once. Write each table mapping, join and calculation in one place, in AML.
  • Query by name. Ask for metrics and dimensions in AQL, never with hand-written SQL.
  • Review like code. Definitions are plain files in Git, so a change to a metric is reviewed, versioned and rolled back like any other change.

anfra's semantic layer is AMQL, the most expressive semantic layer available today. See how it compares.

Building blocks

A semantic layer is built from four kinds of objects. Data models sit closest to the warehouse, datasets join them, and metrics and dimensions are what apps and agents query.

ObjectWhat it doesWhere it lives
Data modelMaps one table or SQL query to dimensions and measures.models/*.model.aml
DatasetJoins data models through relationships. It is what apps and agents query.datasets/*.dataset.aml
MetricA named calculation on a dataset, such as revenue. It can span models and build on other metrics.Inside a dataset
DimensionA field to group or filter by, such as a date, status or country.Usually on a data model

For example, a sales dataset joins the orders, order_items and products models, and defines revenue as the sum of quantity times price. An app that shows revenue by month queries sales for the revenue metric and the orders.created_at dimension, and never sees the join.

Two ways to start

  • From your tables. Model your data walks through building that sales dataset step by step, usually with your coding agent writing the AML.
  • From an existing semantic layer. If your metrics are already defined in Snowflake, Databricks, Looker or Power BI, you don't have to start over. anfra references or converts them.

Semantic layer and Semantic Catalog

The semantic layer defines how metrics are calculated. The Semantic Catalog is the context layer around it: it adds the documentation, ownership and lineage an agent needs to pick the right metric and trace where it comes from. anfra ingest reads your AML into the catalog, alongside your dbt and LookML projects.

Next steps

On this page