> ## 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.

# Search

> Full-text, hybrid, trust-ranked, semantic, frontmatter, and structural-similarity search endpoints.

Use these endpoints to find pages by keyword, meaning, frontmatter, or shape. Pick the one that fits the question:

| Endpoint | Use it when |
| - | - |
| [`GET /search`](#full-text-search) | You have keywords. BM25 over SQLite FTS5, with a soft trust boost. Add `mode=hybrid` to fuse in vector results. |
| [`GET /search/verified`](#trust-ranked-search) | You want verified and source-of-truth pages strongly preferred. |
| [`GET /search/semantic`](#semantic-search) | You have a natural-language question and a vector index is configured. |
| [`POST /brief`](#context-pack) | You want a token-budgeted pack of the most relevant sections in one call. |
| [`GET /meta`](#frontmatter-query) | You want to filter pages by frontmatter values. |
| [`GET /similar`](#similar-pages) | You want pages whose frontmatter is structurally closest to a page or a vector. |

All paths are relative to `http://localhost:3333/api/kiwi`. For DQL queries and the link graph, see [Metadata and graph](https://docs.kiwifs.com/api/metadata.md).

## Full-text search

Run a BM25-ranked keyword search over page content.

**`GET /api/kiwi/search`**

**q** `string` *required*

Search query. See [query syntax](#query-syntax).

**limit** `integer` (default: 50)

Maximum results to return. Capped at `200`.

**offset** `integer` (default: 0)

Number of results to skip.

**path\_prefix** `string`

Restrict results to paths that start with this prefix, for example `runbooks/`. `pathPrefix` is accepted as an alias.

**mode** `string` (default: fts)

`fts` for BM25 only, or `hybrid` to fuse BM25 with vector search. See [hybrid search](#hybrid-search). Any other value returns `400`.

**boost** `string`

Set to `none` or `off` to disable the default trust boost.

**scope** `string`

Keep only pages whose frontmatter `scope` equals this value.

**include\_superseded** `boolean` (default: false)

Include pages with `memory_status: superseded`. They are excluded by default.

**recency\_weight** `number` (default: 0)

Blend recency into ranking, from `0.0` (relevance only) to `1.0` (recency only). Values outside that range return `400`.

**modifiedAfter** `string`

RFC 3339 timestamp. Keep only pages modified after it, for example `2026-09-01T00:00:00Z`.

**suggest\_threshold** `integer` (default: 3)

Maximum edit distance for "did you mean" title suggestions when the first page of results is empty. Capped at `10`.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/search?q=payment+timeout&limit=10'
```

**query** `string`

The query as received.

**limit** `integer`

The effective limit after defaults and caps.

**offset** `integer`

The effective offset.

**results** `object[]`

Ranked results.

**result**

**path** `string`

Page path relative to the knowledge root.

**matches** `object[]`

Matching lines, each with `line` (1-based) and `text`.

**score** `number`

Ranking score. Comparable only within one response.

**snippet** `string`

Highlighted excerpt, when available.

**permalink** `string`

Public URL of the page, when a public URL is configured.

**suggestions** `object[]`

Present only when the query returned nothing at `offset=0`. Each entry has `query`, `path`, `title`, and `distance`.

```json Response theme={null}
{
  "query": "payment timeout",
  "limit": 10,
  "offset": 0,
  "results": [
    {
      "path": "concepts/payments.md",
      "matches": [{ "line": 12, "text": "Retries happen after a payment timeout of 30s." }],
      "score": 4.82,
      "snippet": "...retries after a <mark>payment</mark> <mark>timeout</mark>...",
      "permalink": "https://wiki.example.com/page/concepts/payments.md"
    }
  ]
}
```

Returns `400` when `q` is missing or a parameter is malformed. Returns `501` when `scope` is used on a non-SQLite search backend.

> [!NOTE]
>
> By default results get a soft trust boost: `status: verified`, `source-of-truth: true`, and a `confidence` between 0 and 1 nudge a page up, while `status: deprecated` or `outdated` nudge it down. Requests that set `scope`, `include_superseded`, or `recency_weight` skip the boost.

### Query syntax

Plain words are matched as an implicit AND, and punctuation such as hyphens is handled for you. If the query contains FTS5 syntax (quotes, parentheses, `*`, `^`, `:`, or uppercase `AND`/`OR`/`NOT`), KiwiFS passes it to FTS5 unchanged.

| Syntax | Example | Behavior |
| - | - | - |
| Keywords | `payment timeout` | Pages containing both terms |
| AND | `payment AND timeout` | Same as space-separated |
| OR | `payment OR billing` | Pages containing either term |
| NOT | `payment NOT refund` | Excludes pages containing the second term |
| Phrase | `"payment timeout"` | The exact phrase |
| Prefix | `auth*` | Terms starting with `auth` |

```bash Boolean theme={null}
curl 'http://localhost:3333/api/kiwi/search?q=payment+AND+timeout'
```

```bash Phrase theme={null}
curl 'http://localhost:3333/api/kiwi/search?q=%22payment+timeout%22'
```

```bash Exclusion theme={null}
curl 'http://localhost:3333/api/kiwi/search?q=payment+NOT+refund'
```

## Hybrid search

Fuse BM25 and vector rankings with Reciprocal Rank Fusion (RRF) on the same endpoint.

**`GET /api/kiwi/search?mode=hybrid`**

Hybrid mode accepts `q`, `limit`, `offset`, `path_prefix`, and `boost` from [full-text search](#full-text-search), plus:

**rrf\_k** `number` (default: 60)

RRF rank constant. Must be greater than 0. Smaller values let one engine's top hit dominate; larger values flatten rank differences.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/search?mode=hybrid&q=payment+timeout&limit=10'
```

**mode** `string`

Always `hybrid`.

**engines** `string[]`

Engines that contributed: `["fts", "semantic"]`, or `["fts"]` when no vector index is configured. The request still succeeds with `200` in that case.

**rrf\_k** `number`

The RRF constant used.

**results** `object[]`

Each result has `path`, `matches`, `score` (the RRF score), `snippet`, `permalink`, `fts_rank`, and `semantic_rank`. A rank of `0` means that engine did not return the page.

```json Response theme={null}
{
  "query": "payment timeout",
  "mode": "hybrid",
  "limit": 10,
  "offset": 0,
  "engines": ["fts", "semantic"],
  "rrf_k": 60,
  "results": [
    {
      "path": "concepts/payments.md",
      "score": 0.032,
      "snippet": "...retries after a payment timeout...",
      "fts_rank": 1,
      "semantic_rank": 3
    }
  ]
}
```

## Trust-ranked search

Run the same BM25 search, then re-rank hard by trust signals in frontmatter.

**`GET /api/kiwi/search/verified`**

Compared with the default soft boost, `status: verified` pages get a 2x multiplier, `source-of-truth: true` pages 3x, `status: outdated` 0.3x, and `status: deprecated` 0.1x. Results are re-ranked, not filtered: every BM25 hit is still returned.

**q** `string` *required*

Search query, using the same [syntax](#query-syntax) as full-text search.

**limit** `integer` (default: 50)

Maximum results. Capped at `200`.

**offset** `integer` (default: 0)

Number of results to skip.

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/search/verified?q=auth'
```

The response has the same shape as [full-text search](#full-text-search).

```json Response theme={null}
{
  "query": "auth",
  "limit": 50,
  "offset": 0,
  "results": [
    {
      "path": "concepts/auth.md",
      "matches": [{ "line": 3, "text": "OAuth2 auth flow with refresh tokens." }],
      "score": 8.91,
      "snippet": "...OAuth2 <mark>auth</mark> flow..."
    }
  ]
}
```

Returns `501` when the search backend is not SQLite.

> [!TIP]
>
> Add `status: verified` or `source-of-truth: true` to a page's frontmatter to lift it in trust-ranked results.

## Semantic search

Find pages by meaning using vector embeddings.

**`GET /api/kiwi/search/semantic`** or **`POST /api/kiwi/search/semantic`**

Send parameters as query parameters, or as a JSON body on `POST`. Body values win over query parameters.

**query** `string` *required*

Natural-language query. On `GET`, pass it as `q`.

**topK** `integer` (default: 10)

Maximum results to return.

**offset** `integer` (default: 0)

Number of results to skip.

**scope** `string`

Keep only pages whose frontmatter `scope` equals this value.

**modifiedAfter** `string`

RFC 3339 timestamp. Keep only pages modified after it. Body only.

```bash POST theme={null}
curl -X POST 'http://localhost:3333/api/kiwi/search/semantic' \
  -H "Content-Type: application/json" \
  -d '{"query": "how does auth work?", "topK": 5}'
```

```bash GET theme={null}
curl 'http://localhost:3333/api/kiwi/search/semantic?q=how+does+auth+work&topK=5'
```

**query** `string`

The query as received.

**topK** `integer`

The effective result cap.

**offset** `integer`

The effective offset.

**results** `object[]`

Ranked chunks.

**result**

**path** `string`

Page path.

**chunkIdx** `integer`

Index of the matching chunk within the page.

**score** `number`

Similarity score. Higher is closer.

**snippet** `string`

Text of the matching chunk.

```json Response theme={null}
{
  "query": "how does auth work?",
  "topK": 5,
  "offset": 0,
  "results": [
    {
      "path": "concepts/auth.md",
      "chunkIdx": 0,
      "score": 0.92,
      "snippet": "OAuth2 + JWT based authentication system..."
    }
  ]
}
```

Returns `400` when no query is given or `modifiedAfter` is not RFC 3339. Returns `503` when semantic search is not enabled.

> [!NOTE]
>
> Semantic search needs an embedder and vector store. Configure them under `[search.vector]` in `.kiwi/config.toml`. See [Configuration](https://docs.kiwifs.com/configuration.md#search).

## Context pack

Retrieve the most relevant pages and pack them, whole or by section, into a token budget.

**`POST /api/kiwi/brief`**

The pack uses hybrid retrieval and counts real BPE tokens. Content is never summarized or rewritten. Anything that did not fit is listed in `dropped` with its token cost, so you can fetch it explicitly or raise the budget.

**query** `string` *required*

Retrieval query. You can also pass it as the `q` query parameter.

**budget\_tokens** `integer` (default: 4000)

Hard token ceiling. A negative value returns an empty pack whose `dropped` list still names every candidate, which lets you ask what a query would cost.

**max\_pages** `integer` (default: 20)

Maximum candidate pages considered before packing.

**path\_prefix** `string`

Restrict retrieval to paths under this prefix.

**encoding** `string` (default: cl100k\_base)

BPE vocabulary used to count tokens.

```bash theme={null}
curl -X POST 'http://localhost:3333/api/kiwi/brief' \
  -H "Content-Type: application/json" \
  -d '{"query": "how does auth work?", "budget_tokens": 4000, "max_pages": 20}'
```

**query** `string`

The query as received.

**budget\_tokens** `integer`

The effective budget.

**used\_tokens** `integer`

Tokens used by `items`.

**tokenizer** `string`

Encoding used to count tokens.

**candidates** `integer`

Pages retrieval offered before budgeting.

**items** `object[]`

Packed content in relevance order.

**item**

**path** `string`

Page path.

**title** `string`

Page title, when known.

**heading** `string`

Section heading. Empty when the whole page is included.

**content** `string`

Verbatim page or section text.

**tokens** `integer`

Token count of `content`.

**score** `number`

Retrieval score.

**fts\_rank** `integer`

Rank from full-text search, `0` if absent.

**semantic\_rank** `integer`

Rank from semantic search, `0` if absent.

**partial** `boolean`

`true` when some of the page's sections were left out.

**dropped** `object[]`

Content that did not make it in. Each entry has `path`, optional `heading`, `tokens`, `score`, and `reason`: `budget exhausted`, `page truncated to fit budget`, `page could not be read`, or `page has no content`.

```json Response theme={null}
{
  "query": "how does auth work?",
  "budget_tokens": 4000,
  "used_tokens": 3712,
  "tokenizer": "cl100k_base",
  "items": [
    {
      "path": "concepts/auth.md",
      "title": "Authentication",
      "content": "# Authentication\n\nOAuth2 + JWT based authentication system...",
      "tokens": 2140,
      "score": 0.033,
      "fts_rank": 1,
      "semantic_rank": 1
    }
  ],
  "dropped": [
    { "path": "runbooks/sso-outage.md", "reason": "budget exhausted", "tokens": 1880, "score": 0.016 }
  ],
  "candidates": 7
}
```

## Frontmatter query

Filter pages by frontmatter values using JSON path expressions.

**`GET /api/kiwi/meta`**

Each filter is `<field><op><value>`, where `field` is a JSON path starting with `$.` (for example `$.status` or `$.tags[*]`). Operators are `=`, `!=`, `<>`, `<`, `<=`, `>`, `>=`, `LIKE`, and `NOT LIKE`.

**where** `string`

AND filter. Repeat the parameter to combine several, for example `where=$.status=draft&where=$.priority>2`.

**or** `string`

OR filter. Repeat for several alternatives.

**scope** `string`

Shorthand for `where=$.scope=<value>`.

**sort** `string`

JSON path to sort by, for example `$.updated`.

**order** `string` (default: asc)

`asc` or `desc`.

**limit** `integer` (default: 50)

Maximum results. Capped at `200`.

**offset** `integer` (default: 0)

Number of results to skip.

```bash theme={null}
curl -G 'http://localhost:3333/api/kiwi/meta' \
  --data-urlencode 'where=$.status=draft' \
  --data-urlencode 'sort=$.updated' \
  --data-urlencode 'order=desc'
```

**count** `integer`

Number of results in this response.

**limit** `integer`

The effective limit.

**offset** `integer`

The effective offset.

**results** `object[]`

Each result has `path`, `frontmatter` (the full frontmatter object), and `permalink` when a public URL is configured.

```json Response theme={null}
{
  "count": 1,
  "limit": 50,
  "offset": 0,
  "results": [
    {
      "path": "concepts/billing.md",
      "frontmatter": { "title": "Billing", "status": "draft", "updated": "2026-09-20" }
    }
  ]
}
```

Returns `400` for a malformed filter or a field that does not start with `$.`. Returns `501` when the search backend is not SQLite.

> [!TIP]
>
> For projections, grouping, and sorting across many fields, use [DQL](https://docs.kiwifs.com/api/metadata.md#dql-query) instead.

## Similar pages

Rank pages by how close their frontmatter is to a given page or to an inline field vector.

**`GET /api/kiwi/similar`**

Similarity uses Gower distance over the numeric and categorical fields named in a `[[similarity.profiles]]` block in `.kiwi/config.toml`. Pass `vector` to ask about a case that is not in the knowledge base yet.

**path** `string`

Page to find neighbors of. Required unless `vector` is set.

**vector** `string`

JSON object of field values, for example `{"format":"csv","stats.rows":12000}`. With `path`, these values override the page's own.

**profile** `string`

Similarity profile name. Optional when exactly one profile is configured.

**k** `integer` (default: 5)

Number of neighbors to return.

```toml .kiwi/config.toml theme={null}
[[similarity.profiles]]
name = "dataset"
match = { kind = "dataset" }
numeric = ["stats.rows", "stats.columns"]
categorical = ["format", "license"]
weights = { "format" = 2.0 }
```

```bash theme={null}
curl 'http://localhost:3333/api/kiwi/similar?path=datasets/sales-2025.md&k=3'
```

**profile** `string`

Profile used.

**query\_path** `string`

The `path` you passed, if any.

**query\_vector** `object`

The resolved field vector that was compared.

**fields** `string[]`

Fields in the profile.

**candidate\_count** `integer`

Pages compared.

**truncated** `boolean`

`true` when the candidate set hit its cap, so ranking covers only part of the corpus.

**neighbors** `object[]`

Ranked neighbors.

**neighbor**

**path** `string`

Page path.

**score** `number`

`1 - rank_distance`. Higher is more similar; results are ordered by it.

**distance** `number`

Gower distance over the fields both sides have.

**rank\_distance** `number`

Distance that counts missing fields as maximally different.

**coverage** `number`

Weighted share of fields that were comparable.

**comparable\_fields** `integer`

Fields both sides had.

**total\_fields** `integer`

Fields in the profile.

**contributions** `object[]`

Per-field breakdown with `field`, `kind`, `distance`, `weight`, `skipped`, and the two values `a` and `b`.

```json Response theme={null}
{
  "profile": "dataset",
  "query_path": "datasets/sales-2025.md",
  "query_vector": { "format": "csv", "license": "cc-by", "stats.rows": 12000, "stats.columns": 14 },
  "fields": ["stats.rows", "stats.columns", "format", "license"],
  "candidate_count": 42,
  "neighbors": [
    {
      "path": "datasets/sales-2024.md",
      "score": 0.94,
      "distance": 0.06,
      "rank_distance": 0.06,
      "coverage": 1,
      "comparable_fields": 4,
      "total_fields": 4,
      "contributions": [
        { "field": "format", "kind": "categorical", "distance": 0, "weight": 2, "skipped": false, "a": "csv", "b": "csv" }
      ]
    }
  ]
}
```

Returns `400` when neither `path` nor `vector` is given, the profile is unknown, `k` is not a positive integer, or `vector` is not a JSON object. Returns `503` when no similarity profiles are configured.

## Related

> [card] [Search concepts](https://docs.kiwifs.com/concepts/search.md)
>
> How the three search tiers fit together.

> [card] [Metadata and graph](https://docs.kiwifs.com/api/metadata.md)
>
> DQL queries, aggregations, backlinks, and the link graph.

> [card] [Configuration](https://docs.kiwifs.com/configuration.md#search)
>
> Search engine and vector settings.

> [card] [Analytics](https://docs.kiwifs.com/api/analytics.md)
>
> Search analytics and failed queries.


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