Indexing & Maintenance
vchord_bm25 provides the bm25 index access method (CREATE ACCESS METHOD bm25 TYPE INDEX HANDLER _bm25_amhandler) and the bm25_ops operator class.
Creating a bm25 Index
Stable Releases (v0.1 – v0.3, bm25vector)
Next-Gen main Branch (tsvector)
In the main branch, bm25_ops operates on tsvector and supports index-level storage parameters (options, limit, and prefilter):
Storage Parameter (WITH (...)) |
Type | Default | Range | Description |
|---|---|---|---|---|
options (k1) |
float (in TOML) |
1.2 |
1.2 – 2.0 |
Term frequency saturation parameter . Higher values increase the weight of repeated occurrences of a term within a document. |
options (b) |
float (in TOML) |
0.75 |
0.0 – 1.0 |
Document length normalization parameter . 0.0 disables length normalization; 1.0 fully normalizes by document length relative to . |
limit |
int |
0 |
0 – 65535 |
Default Top-K search limit stored on the index (used when session GUC bm25.limit = 0). |
prefilter |
bool |
false |
true / false |
Default prefilter behavior stored on the index (can be overridden per session via bm25.prefilter). |
You can dynamically update limit or prefilter on an existing index with ALTER INDEX:
Automatic Tokenization Triggers (v0.1 – v0.3)
When using pg_tokenizer, you can keep your bm25vector column automatically synchronized on INSERT and UPDATE:
Using a Custom Model Trigger (One-Step Helper)
create_custom_model_tokenizer_and_trigger creates a custom model, a tokenizer, backfills existing rows, and attaches an automatic BEFORE INSERT OR UPDATE trigger:
Using a Standard PL/pgSQL Trigger with Pretrained Models
If you use a pretrained model (such as llmlingua2 or bert_base_uncased), create a standard trigger function:
Segment Architecture: Growing vs. Sealed Segments (v0.1 – v0.3)
Internally, vchord_bm25 organizes index tuples into two segment states:
- Growing Segment: Newly inserted tuples (
INSERT/UPDATE) are appended to the growing segment for fast write throughput without re-compressing entire posting lists. - Sealed Segment: When the growing segment exceeds
bm25_catalog.segment_growing_max_page_sizepages (default4096pages, ~32 MB), it is sealed into an immutable, read-only segment with delta-bitpacked 128-document blocks, precomputed block-max upper bounds, and term document frequency statistics.
Parallel Index Build & Progress Monitoring
Index creation supports PostgreSQL parallel maintenance workers and reports live build progress via pg_stat_progress_create_index across three phases:
initializingscanning tablewriting index structures
Inspecting Index Pages (v0.3.0)
Version 0.3.0 provides bm25_page_inspect(index regclass, blkno int) to inspect the internal metadata and page headers of a bm25 index:
Index Constraints & Limitations
- Single-Column Only: A
bm25index can only be created on a singlebm25vector(ortsvector) column. Multicolumnbm25indexes are not supported. - No Unlogged Tables:
UNLOGGEDtables are not supported by thebm25access method (ambuildemptyraisesUnlogged indexes are not supported). - Forward Scan Direction Only:
bm25index scans only support forward (ASC) scan direction on<&>.