> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usedatabrain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Datamarts

> Create optimized data models for analytics and AI-powered insights

## What is a Datamart?

A Datamart is a curated, optimized subset of your data specifically designed for analytics and AI-powered queries. It sits between your raw data and your dashboards / AI layer, providing a clean, query-ready model that is easy for both humans and AI to work with.

## Why Use Datamarts?

> [card] Faster Queries
>
> Optimized tables and columns for lightning-fast analytics

> [card] AI-Ready Data
>
> Structured for natural language queries and AI insights

> [card] Simplified Schema
>
> Business-friendly data model hiding technical complexity

> [card] Consistent Metrics
>
> Single source of truth for key business metrics

## Creating a Datamart

**1. Create Datamart**

Provide a name and select a datasource. Each datamart connects to a single datasource.

**2. Select Tables**

Choose which tables from the schema to include in your datamart. You can select tables from different schemas within the same datasource.

**3. Configure Columns**

Select which columns to include from the selected tables. Preview table data and configure column visibility.

**4. Configure Tenancy (Optional)**

Set up multi-tenancy settings:

* **Table-level tenancy**: Select a table with primary key and client name columns
* **Database-level tenancy**: Use separate databases per tenant
* **Multi-database tenancy**: Use multiple databases (MSSQL only)

**5. Add Descriptions & Metadata**

After creation, add business-friendly names, descriptions, and relationships in the Datamart Description page.

> [card] [Create a Datamart](https://docs.usedatabrain.com/guides/datasources/create-a-datamart.md)
>
> Step-by-step datamart creation guide

## Key Features

### Tables

Select tables from your datasource:

* Choose tables from available schemas
* Preview table data before including
* Select multiple tables from different schemas
* Hide tables that aren't needed

### Columns

Configure which columns to include:

* Select specific columns from each table
* Hide unnecessary columns
* Preview column data
* Configure column visibility

### Tenancy Configuration

Set up multi-tenancy (optional):

* Table-level tenancy with primary key and client columns
* Database-level tenancy for complete isolation
* Multi-database tenancy (MSSQL only)

### Relationships

Define relationships between tables (configured after creation):

* One-to-many relationships
* Many-to-many relationships
* Self-referential joins
* Configure join types and cardinality

### Metadata & Descriptions

Add context to make your datamart analytics- and AI-ready (configured after creation):

* Table descriptions
* Column descriptions and labels
* Business-friendly aliases
* Example questions for downstream AI experiences

## Datamart Structure

Each datamart connects to a single datasource. Within that datasource, you can:

* Select tables from multiple schemas
* Configure columns from selected tables
* Define relationships between tables
* Set up multi-tenancy at table, database, or multi-database level

> [card] [Semantic Layer](https://docs.usedatabrain.com/guides/datasources/semantic-layer.md)
>
> Learn about semantic layer capabilities

## Tenancy & Multi-Tenancy

Datamarts support multi-tenant architectures for data isolation:

### Tenancy Levels

**Table-Level Tenancy**

* Select a table with primary key and client name columns
* Data is filtered automatically based on client ID
* Suitable for single-database multi-tenant setups

**Database-Level Tenancy**

* Use separate databases per tenant
* Each tenant's data is completely isolated
* Automatically routes queries to the correct database

**Multi-Database Tenancy** (MSSQL only)

* Use multiple databases for tenant isolation
* Supports complex multi-tenant architectures
* Configure schema lists per tenant

### Access Control

Datamart access is controlled through workspace permissions:

* View, Create, Edit, Delete permissions
* Edit Tenancy permission for configuring multi-tenancy

## Use Cases

### AI-Powered Analytics

Enable business users to ask questions in natural language (powered by the semantic layer you configure later):

* "Top customers by revenue"
* "Sales trends last quarter"
* "Compare regions"

### Consistent Metrics

Ensure everyone uses the same definitions:

* Standard KPI calculations
* Consistent aggregations
* Unified dimensions

### Fast Dashboards

Power dashboards with optimized data models:

* Selected tables and columns for faster queries
* Clear relationships between tables
* Multi-tenant data isolation

### Multi-Tenant Applications

Enable data isolation for SaaS applications:

* Table-level tenancy for single-database setups
* Database-level tenancy for complete isolation
* Multi-database tenancy for complex architectures

## Best Practices

> [accordion] Start Simple
>
> Begin with core tables and metrics. Expand the datamart gradually as needs grow.

> [accordion] Use Business Language
>
> Name fields and tables using terms your business users understand, not technical jargon.

> [accordion] Document Everything
>
> Add descriptions to all fields. This helps both dashboard users and AI understand your data.

> [accordion] Optimize for Common Queries
>
> Model your datamart around your most frequent query patterns.

> [accordion] Keep It Fresh
>
> Set up regular updates to ensure datamart data is current.

## Datamart vs. Data Warehouse

| Aspect | Datamart | Data Warehouse |
| - | - | - |
| **Scope** | Focused on specific use case | Enterprise-wide data |
| **Purpose** | Analytics & AI queries | Source of truth storage |
| **Schema** | Denormalized, optimized | Normalized, comprehensive |
| **Users** | Business analysts, AI | Data engineers, analysts |
| **Performance** | Optimized for reads | Balanced read/write |

## Datamart Features

### Table & Column Management

* Select tables from schemas within your datasource
* Configure which columns are visible
* Preview table data before including
* Hide tables or columns as needed

### Relationships

* Define relationships between tables in your datamart
* Configure cardinality and join types

### Metadata & Descriptions

* Table descriptions
* Column descriptions and labels
* Business-friendly aliases

## Datamart API

Manage datamarts programmatically through the Data App API:

### List Datamarts

```bash theme={"dark"}
curl --request GET \
  --url https://api.usedatabrain.com/api/v2/datamarts \
  --header 'Authorization: Bearer YOUR_API_TOKEN'
```

### Create Datamart

```bash theme={"dark"}
curl --request POST \
  --url https://api.usedatabrain.com/api/v2/datamarts \
  --header 'Authorization: Bearer YOUR_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Sales Datamart",
    "datasourceId": "your-datasource-id"
  }'
```

### Update Datamart

```bash theme={"dark"}
curl --request PUT \
  --url https://api.usedatabrain.com/api/v2/datamarts \
  --header 'Authorization: Bearer YOUR_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "your-datamart-id",
    "name": "Updated Name"
  }'
```

> [card] [Data App API](https://docs.usedatabrain.com/developer-docs/helpers/api-reference/data-app-api)
>
> Complete Data App API reference

***

## Semantic Layer & AI Chat

The semantic layer and AI chat features are built **on top of** your datamart. Once your datamart is created, you configure the semantic layer to make it AI-friendly.

### Semantic Layer Basics

The semantic layer translates technical data structures into business concepts.

#### Business Names

```text theme={"dark"}
customer_acq_date → Customer Acquisition Date
mrr               → Monthly Recurring Revenue
cac               → Customer Acquisition Cost
```

#### Descriptions

Add helpful descriptions that appear in AI responses and tooltips:

* What the metric or column measures
* How it's calculated
* When to use it
* Known limitations

#### Data Types

Define appropriate data types:

* Dimensions (categories)
* Measures (numeric values)
* Dates and times
* Text and strings

### AI Chat Mode Integration

Datamarts power AI chat mode, enabling natural language analytics.

#### How It Works

1. **User asks a question** – e.g. "What were total sales last month?"
2. **AI understands intent** – uses datamart metadata and semantic layer to interpret the question
3. **Generate SQL** – creates an optimized query based on the datamart structure
4. **Return results** – displays data with a natural language explanation

#### LLM Configuration

Connect your preferred LLM:

* OpenAI GPT
* Claude AI
* Azure OpenAI
* Llama
* Mixtral

> [card] [LLM Connectors](https://docs.usedatabrain.com/developer-docs/helpers/llm-connectors.md)
>
> Configure AI models for chat mode

### Datamart Management for Semantic Layer

Once the datamart exists, you configure the semantic layer and examples from the Semantic Layer and Datamart Description pages.

#### Datamart Description

Add metadata and context to your datamart:

* **Table Descriptions**: Add business-friendly descriptions for tables
* **Column Descriptions**: Document what each column represents
* **Relationships**: Define relationships between tables
* **Examples**: Add example questions for AI chat mode
* **Synonyms**: Configure column synonyms for better AI understanding

#### Semantic Layer Tools

* **Lab**: Generate and test synthetic queries
* **Playground**: Test natural language questions against the datamart
* **Sample Set**: Configure sample data for AI training and evaluation

### Best Practices for Semantic Layer

> [accordion] Align With Business Language
>
> Use the same terms your business stakeholders use in meetings and reports.

> [accordion] Iterate With Real Questions
>
> Test the semantic layer using real questions from users and refine names, descriptions, and examples.

> [accordion] Keep Examples Up To Date
>
> Regularly review and update example questions and feedback to improve AI answers over time.

## Next Steps

> [card] [Create a Datamart](https://docs.usedatabrain.com/guides/datasources/create-a-datamart.md)
>
> Build your first datamart

> [card] [Enable AI Chat](https://docs.usedatabrain.com/developer-docs/chat-mode/step-1-create-datamart-and-workspace.md)
>
> Set up AI-powered queries

> [card] [Semantic Layer](https://docs.usedatabrain.com/guides/datasources/semantic-layer.md)
>
> Configure your semantic layer

> [card] [LLM Architecture](https://docs.usedatabrain.com/developer-docs/helpers/llm-architecture.md)
>
> Understand AI integration


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.