Use fts5vocab to see the searchable tokens FTS5 stored, rather than guessing from the original text.
dotnet add package RecursiveAI.OneLiteRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
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, then dotnet run.
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.
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:
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.
dotnet run -- --positionscafe: 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
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 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 lists what each mode returns.