Tokenizers
By default, text columns are tokenized using the unicode tokenizer, which splits text according to the Unicode segmentation standard. Because index creation is a time-consuming operation, we recommend experimenting with the available tokenizers to find the most suitable one before runningCREATE INDEX.
For instance, if a column contains multiple languages, the ICU tokenizer may be more appropriate.
Token Filters
After tokens are created, token filters can be configured to apply further processing like lowercasing, stemming, or unaccenting. For example, the following code block adds English stemming todescription:
BM25 Parameters
Tuning BM25 parameters is not necessary for most use cases.
k1 and b, to control how term frequency and field length affect relevance scores. You can configure them independently for each field when creating an index.
Pass
k1 and b as options to a field’s tokenizer. In this example, the description field uses lower values to reduce the influence of repeated terms and field length. The category field gives repeated terms more weight while keeping the default length normalization.
Faster BM25 Queries
This feature is available in versions
0.26.0 and above.pnorms=true
when creating your index, at the cost of a larger index and longer builds.
Enable the Optimization
Setpnorms=true on the tokenizer cast for each
text field used in BM25 scoring. The option defaults to false. This example
enables it for description:
pnorms=true to enable it.
Performance Tradeoff
BM25 scoring uses the length of each text field to help determine relevance. Settingpnorms=true stores an extra, denser copy of this information where the scoring
process can read it more efficiently. Depending on the data and query, this can
make queries several times faster without changing scores or relevance ranking.
For each field with pnorms enabled, the extra storage is roughly one byte per
distinct term in each document, plus metadata. The extra data also increases
the work required to build and merge index segments. Enable pnorms on fields
where faster BM25 top K queries justify those costs.
Faster Counts
This feature is available in versions
0.26.2 and above. Indexes built before
0.26.2 must be rebuilt to receive
this optimization.COUNT(*) queries that combine common search terms
with AND or OR by storing additional bitmap structures.
Index Configuration
Thebitmap_postings option on a tokenizer cast
defaults to true.
It is enabled by default because the storage overhead is usually very small.
If your workload does not require counts, you can disable it for a field with
bitmap_postings=false: