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

# Bases and saved views

> Saved DQL queries rendered as a table, cards, list, or map over your pages' frontmatter.

A **base** is a database-style view over your knowledge base. Each base is a **saved view**: a named [DQL](https://docs.kiwifs.com/concepts/dql.md) query plus presentation settings, stored as JSON under `.kiwi/views/`. Open **Bases** in the web UI to browse the results, or run the same view from the API or MCP.

Use a base when you want a reusable slice of your pages, such as all open incidents, every paper tagged `llm`, or vendors that have an office location.

## How it works

**1. Pages carry frontmatter**

Every field you want to query lives in YAML frontmatter, for example `status`, `owner`, or `due`.

**2. A view stores a DQL query**

The view's `query` selects and shapes rows. Filtering and sorting belong in the query (`WHERE`, `SORT`).

**3. Executing the view runs the query**

`GET /api/kiwi/views/{name}/execute` runs the query against the frontmatter index, then evaluates any computed `formula` columns.

**4. The web UI renders the rows**

**Bases** shows the result in the view's default layout. You can switch layouts and quick-search the loaded rows without editing the view.

> [!NOTE]
>
> Executing a view requires the default SQLite search engine. With `[search] engine = "grep"`, the execute endpoint returns `503`.

## File format

Each view is one JSON file named after the view.

**.kiwi**

**views**

**open-incidents.json**

**reading-list.json**

```json .kiwi/views/open-incidents.json theme={null}
{
  "name": "open-incidents",
  "query": "TABLE title, severity, owner, minutes_down FROM \"incidents\" WHERE status != \"resolved\" SORT severity ASC",
  "layout": "table",
  "columns": [
    { "property": "minutes_down", "label": "Downtime", "summary": "sum" },
    { "property": "hours_down", "label": "Hours", "formula": "round(minutes_down / 60, 1)" }
  ]
}
```

| Field | Purpose |
| - | - |
| `name` | Identifier. It always matches the filename; on save, the name in the URL wins. |
| `query` | DQL query run by the Dataview engine. It must start with a query type such as `TABLE` or `LIST`. |
| `layout` | Default layout in the web UI: `table`, `cards`, `list`, or `map`. |
| `columns` | Optional column specs: `property`, `label`, `formula` (computed value), and `summary` (`sum`, `avg`, `count`, `min`, `max`). |
| `filters` | Optional structured filters (`field`, `operator`, `value`). Stored with the view but not applied by the execute endpoint, so put filtering in the query. |
| `sort` | Optional sort keys (`field`, `order`). Stored only; use `SORT` in the query. |
| `group_by` | Optional grouping field. Stored only. |

View names must start with a letter or digit and may contain letters, digits, spaces, hyphens, and underscores.

### Computed columns

A column with a `formula` is evaluated for each row after the query runs, and the result is written into that column's `property`. Formulas support:

* Field references, numbers, and quoted strings
* Arithmetic with `+`, `-`, `*`, and `/`
* `length(x)`, `round(x, digits)`, and `if(field, then, else)`, where the condition is true when the field is set and not empty

## Layouts in the web UI

| Layout | Best for | Notes |
| - | - | - |
| Table | Comparing fields side by side | Shows column `summary` values in the footer. |
| Cards | Visual collections | Uses a `cover` or `image` frontmatter field as the card image. |
| List | Compact scanning | Title plus key fields. |
| Map | Places | Plots rows that have `latitude` and `longitude`, `lat` and `lng`, or a `location` string such as `"52.37, 4.89"`. |

Hide the **Bases** toolbar button with `bases = false` under `[ui.features]`.

## Create and run a view

> [tab] REST
>
> ```bash Terminal theme={null}
> curl -X PUT 'http://localhost:3333/api/kiwi/views/open-incidents' \
>   -H 'Content-Type: application/json' \
>   -d '{
>     "query": "TABLE title, severity, owner FROM \"incidents\" WHERE status != \"resolved\"",
>     "layout": "table"
>   }'
>
> curl 'http://localhost:3333/api/kiwi/views/open-incidents/execute?limit=50'
> ```

> [tab] MCP
>
> Call `kiwi_views_save` to create or update the view, then `kiwi_views_execute` to run it. `kiwi_views_list`, `kiwi_views_get`, and `kiwi_views_delete` cover the rest.

> [tab] Web UI
>
> Click **Bases** in the toolbar, then **New view**. Enter a name and a DQL query such as `TABLE title, status FROM "incidents"`, pick a default layout, and click **Save**.

> [!NOTE]
>
> Saved views are configuration under `.kiwi/`, not pages. Saving one writes the JSON file directly; it does not create a git commit or appear in search.

## Saved views versus computed views

Saved views live in `.kiwi/views/` and render in the web UI. **Computed views** are markdown pages with `kiwi-view: true` and a `kiwi-query` in frontmatter. KiwiFS writes the query result into the page body between `<!-- kiwi:auto -->` and `<!-- /kiwi-view -->` markers, so any tool that reads the file sees the result. Regenerate one with `POST /api/kiwi/view/refresh` or the `kiwi_view_refresh` MCP tool. See [DQL](https://docs.kiwifs.com/concepts/dql.md) for details.

## Related

> [card] [Views REST API](https://docs.kiwifs.com/api/views.md)
>
> List, save, delete, and execute views.

> [card] [DQL](https://docs.kiwifs.com/concepts/dql.md)
>
> The query language behind every view.

> [card] [Metadata API](https://docs.kiwifs.com/api/metadata.md)
>
> Query frontmatter directly.

> [card] [Web UI](https://docs.kiwifs.com/guides/web-ui.md)
>
> Toolbar views, including Bases.


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