---
title: "List SQLite FTS5 indexed terms with fts5vocab"
url: https://recursiveai.org/onelite/cookbook/list-indexed-terms-with-sqlite-fts5vocab/
description: "Use SQLite fts5vocab to list indexed terms, document counts, and total occurrences. Inspect counts by column and see where each token was indexed."
version: "1.0.0"
---

# List SQLite FTS5 indexed terms with fts5vocab

**OneLite** is a free, open-source SQLite-compatible database for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneLite) · [GitHub](https://github.com/recursive-ai-oss/onelite-csharp) · [Docs](https://recursiveai.org/onelite/docs/) · [Download example (.zip)](https://recursiveai.org/onelite/cookbook/list-indexed-terms-with-sqlite-fts5vocab/list-indexed-terms-with-sqlite-fts5vocab.zip)

Use `fts5vocab` to see the searchable tokens FTS5 stored, rather than guessing from the original text.

```shell
dotnet add package RecursiveAI.OneLite
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneLite;

await using var db =
    await Database.OpenAsync(":memory:");
await db.ExecuteScriptAsync("""
    CREATE VIRTUAL TABLE notes
    USING fts5(title, body);
    INSERT INTO notes VALUES
        ('Café', 'café café'), ('Tea', 'tea café');
    CREATE VIRTUAL TABLE vocab
    USING fts5vocab(notes, 'row');
    """);
var rows = await db.QueryAsync<string>($"""
    SELECT printf('%s: docs=%d, hits=%d',
                  term, doc, cnt)
    FROM vocab ORDER BY term
    """);
foreach (var row in rows) Console.WriteLine(row);
```

Unzip [the example](https://recursiveai.org/onelite/cookbook/list-indexed-terms-with-sqlite-fts5vocab/list-indexed-terms-with-sqlite-fts5vocab.zip), then `dotnet run`.

```text
cafe: docs=2, hits=4
tea: docs=1, hits=2
```

## The full program

The download shows both the whole-table counts and the columns that contributed `cafe`. The default tokenizer indexes “Café” as `cafe`; the token appears four times across two rows. If a vocabulary query reports `no such fts5 table`, check that the named source is an FTS5 virtual table in the expected database.

```csharp
using RecursiveAI.OneLite;

await using var db =
    await Database.OpenAsync(":memory:");
await db.ExecuteScriptAsync("""
    CREATE VIRTUAL TABLE notes
    USING fts5(title, body);
    INSERT INTO notes VALUES
        ('Café', 'café café'), ('Tea', 'tea café');
    CREATE VIRTUAL TABLE vocab
    USING fts5vocab(notes, 'row');
    """);
var rows = await db.QueryAsync<string>($"""
    SELECT printf('%s: docs=%d, hits=%d',
                  term, doc, cnt)
    FROM vocab ORDER BY term
    """);
foreach (var row in rows) Console.WriteLine(row);

await db.ExecuteScriptAsync("""
    CREATE VIRTUAL TABLE vocab_col USING fts5vocab(notes, 'col');
    """);
var columns = await db.QueryAsync<string>($"""
    SELECT printf('%s: docs=%d, hits=%d', col, doc, cnt)
    FROM vocab_col WHERE term = 'cafe' ORDER BY col
    """);
Console.WriteLine("cafe by column:");
foreach (var column in columns) Console.WriteLine(column);

if (args.Contains("--positions"))
{
    await db.ExecuteScriptAsync("""
        CREATE VIRTUAL TABLE vocab_pos USING fts5vocab(notes, 'instance');
        """);
    var positions = await db.QueryAsync<string>($"""
        SELECT printf('row %d, %s, token %d', doc, col, offset)
        FROM vocab_pos WHERE term = 'cafe' ORDER BY doc, col, offset
        """);
    Console.WriteLine("cafe positions:");
    foreach (var position in positions) Console.WriteLine(position);
}
```

`dotnet run` prints:

```text
cafe: docs=2, hits=4
tea: docs=1, hits=2
cafe by column:
body: docs=2, hits=3
title: docs=1, hits=1
```

## Variations

**Find the individual occurrences.** The download’s `--positions` option uses `fts5vocab(notes, 'instance')` to show the source row ID, column, and zero-based token position.

```shell
dotnet run -- --positions
```

```text
cafe: docs=2, hits=4
tea: docs=1, hits=2
cafe by column:
body: docs=2, hits=3
title: docs=1, hits=1
cafe positions:
row 1, body, token 0
row 1, body, token 1
row 1, title, token 0
row 2, body, token 1
```

## Related recipes

- [Create a SQLite FTS5 index and rank matches](https://recursiveai.org/onelite/cookbook/sqlite-full-text-search/)
- [Skip indexing a column in SQLite FTS5](https://recursiveai.org/onelite/cookbook/index-selected-text-columns-with-fts5/)

## The short answer

Create a virtual table with `USING fts5vocab(notes, 'row')`, where `notes` is the FTS5 table. Select `term`, `doc`, and `cnt` for the indexed token, the number of rows containing it, and the total number of occurrences. Use `'col'` instead of `'row'` to see where in the table a term came from.

## How does SQLite FTS5 turn text into indexed terms?

The tokenizer splits text into terms and decides what spelling the index stores. The [default `unicode61` tokenizer](https://www.sqlite.org/fts5.html#unicode61_tokenizer) ignores case and normally removes accents from Latin characters. That’s why the vocabulary contains `cafe`, not separate entries for `Café` and `café`. Changing the tokenizer or its options can change what this query shows. A column marked `UNINDEXED` supplies no terms, even though its original values may be stored with the row.

If a word you expected isn’t listed, check the stored spelling of the token and whether the source field is indexed. The vocabulary reads the index, not the text you display. It’s a diagnostic query; use `MATCH` on the FTS5 table to search for documents.

## How do you count word frequency in a full-text column?

Read `cnt` from the `'col'` vocabulary for the term and column you care about. The download selects `cafe` and reports three occurrences in `body` and one in `title`. The `doc` column is a different measure. It counts a row once if that column contains the term, no matter how many times the term appears there. Don’t add the per-column `doc` counts to get the number of distinct rows: the same row can appear in both counts. In the example the column counts are two and one, but there are only two distinct rows with `cafe`.

## What is the difference between fts5vocab row, col, and instance?

Use `'row'` for one record per term across the table, `'col'` for one record per term and column, or `'instance'` for each occurrence with the default `detail=full`. In the instance output, `doc` is a row ID, not a document count, and `offset` counts tokens in the column, not bytes or characters. If you open a table created with reduced `detail`, the index stores less: occurrence counts can be `NULL`, and `instance` may not have token offsets or column names. The [SQLite fts5vocab reference](https://www.sqlite.org/fts5.html#the_fts5vocab_virtual_table_module) lists what each mode returns.
