跳转到主要内容

pg_tokenizer

Tokenizers for full-text search

pg_tokenizer : Tokenizers for full-text search

Overview

ID Extension Package Version Category License Language
2170 pg_tokenizer pg_tokenizer 0.1.1 FTS Apache-2.0 Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-- No Yes Yes Yes no no
PG18 fix by Vonng.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.1 18 17 16 15 14 pg_tokenizer -
RPM PIGSTY 0.1.1 18 17 16 15 14 pg_tokenizer_$v -
DEB PIGSTY 0.1.1 18 17 16 15 14 postgresql-$v-pg-tokenizer -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
el8.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
el9.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
el9.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
el10.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
el10.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
d12.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
d12.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
d13.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
d13.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
u22.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
u22.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
u24.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
u24.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
u26.x86_64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
u26.aarch64 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1 PIGSTY 0.1.1
Package Version OS ORG SIZE File URL
pg_tokenizer_18 0.1.1 el8.x86_64 pigsty 13.3 MiB pg_tokenizer_18-0.1.1-3PIGSTY.el8.x86_64.rpm
pg_tokenizer_18 0.1.1 el8.aarch64 pigsty 13.0 MiB pg_tokenizer_18-0.1.1-3PIGSTY.el8.aarch64.rpm
pg_tokenizer_18 0.1.1 el9.x86_64 pigsty 12.5 MiB pg_tokenizer_18-0.1.1-3PIGSTY.el9.x86_64.rpm
pg_tokenizer_18 0.1.1 el9.aarch64 pigsty 12.4 MiB pg_tokenizer_18-0.1.1-3PIGSTY.el9.aarch64.rpm
pg_tokenizer_18 0.1.1 el10.x86_64 pigsty 12.4 MiB pg_tokenizer_18-0.1.1-3PIGSTY.el10.x86_64.rpm
pg_tokenizer_18 0.1.1 el10.aarch64 pigsty 12.3 MiB pg_tokenizer_18-0.1.1-3PIGSTY.el10.aarch64.rpm
postgresql-18-pg-tokenizer 0.1.1 d12.x86_64 pigsty 11.1 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~bookworm_amd64.deb
postgresql-18-pg-tokenizer 0.1.1 d12.aarch64 pigsty 10.9 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~bookworm_arm64.deb
postgresql-18-pg-tokenizer 0.1.1 d13.x86_64 pigsty 11.1 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~trixie_amd64.deb
postgresql-18-pg-tokenizer 0.1.1 d13.aarch64 pigsty 10.9 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~trixie_arm64.deb
postgresql-18-pg-tokenizer 0.1.1 u22.x86_64 pigsty 12.2 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~jammy_amd64.deb
postgresql-18-pg-tokenizer 0.1.1 u22.aarch64 pigsty 12.0 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~jammy_arm64.deb
postgresql-18-pg-tokenizer 0.1.1 u24.x86_64 pigsty 12.1 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~noble_amd64.deb
postgresql-18-pg-tokenizer 0.1.1 u24.aarch64 pigsty 12.0 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~noble_arm64.deb
postgresql-18-pg-tokenizer 0.1.1 u26.x86_64 pigsty 12.1 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~resolute_amd64.deb
postgresql-18-pg-tokenizer 0.1.1 u26.aarch64 pigsty 12.0 MiB postgresql-18-pg-tokenizer_0.1.1-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_tokenizer_17 0.1.1 el8.x86_64 pigsty 13.3 MiB pg_tokenizer_17-0.1.1-3PIGSTY.el8.x86_64.rpm
pg_tokenizer_17 0.1.1 el8.aarch64 pigsty 13.0 MiB pg_tokenizer_17-0.1.1-3PIGSTY.el8.aarch64.rpm
pg_tokenizer_17 0.1.1 el9.x86_64 pigsty 12.5 MiB pg_tokenizer_17-0.1.1-3PIGSTY.el9.x86_64.rpm
pg_tokenizer_17 0.1.1 el9.aarch64 pigsty 12.4 MiB pg_tokenizer_17-0.1.1-3PIGSTY.el9.aarch64.rpm
pg_tokenizer_17 0.1.1 el10.x86_64 pigsty 12.4 MiB pg_tokenizer_17-0.1.1-3PIGSTY.el10.x86_64.rpm
pg_tokenizer_17 0.1.1 el10.aarch64 pigsty 12.3 MiB pg_tokenizer_17-0.1.1-3PIGSTY.el10.aarch64.rpm
postgresql-17-pg-tokenizer 0.1.1 d12.x86_64 pigsty 11.1 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~bookworm_amd64.deb
postgresql-17-pg-tokenizer 0.1.1 d12.aarch64 pigsty 10.9 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~bookworm_arm64.deb
postgresql-17-pg-tokenizer 0.1.1 d13.x86_64 pigsty 11.1 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~trixie_amd64.deb
postgresql-17-pg-tokenizer 0.1.1 d13.aarch64 pigsty 10.9 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~trixie_arm64.deb
postgresql-17-pg-tokenizer 0.1.1 u22.x86_64 pigsty 12.2 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~jammy_amd64.deb
postgresql-17-pg-tokenizer 0.1.1 u22.aarch64 pigsty 12.0 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~jammy_arm64.deb
postgresql-17-pg-tokenizer 0.1.1 u24.x86_64 pigsty 12.1 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~noble_amd64.deb
postgresql-17-pg-tokenizer 0.1.1 u24.aarch64 pigsty 12.0 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~noble_arm64.deb
postgresql-17-pg-tokenizer 0.1.1 u26.x86_64 pigsty 12.1 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~resolute_amd64.deb
postgresql-17-pg-tokenizer 0.1.1 u26.aarch64 pigsty 12.0 MiB postgresql-17-pg-tokenizer_0.1.1-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_tokenizer_16 0.1.1 el8.x86_64 pigsty 13.3 MiB pg_tokenizer_16-0.1.1-3PIGSTY.el8.x86_64.rpm
pg_tokenizer_16 0.1.1 el8.aarch64 pigsty 13.0 MiB pg_tokenizer_16-0.1.1-3PIGSTY.el8.aarch64.rpm
pg_tokenizer_16 0.1.1 el9.x86_64 pigsty 12.5 MiB pg_tokenizer_16-0.1.1-3PIGSTY.el9.x86_64.rpm
pg_tokenizer_16 0.1.1 el9.aarch64 pigsty 12.4 MiB pg_tokenizer_16-0.1.1-3PIGSTY.el9.aarch64.rpm
pg_tokenizer_16 0.1.1 el10.x86_64 pigsty 12.4 MiB pg_tokenizer_16-0.1.1-3PIGSTY.el10.x86_64.rpm
pg_tokenizer_16 0.1.1 el10.aarch64 pigsty 12.3 MiB pg_tokenizer_16-0.1.1-3PIGSTY.el10.aarch64.rpm
postgresql-16-pg-tokenizer 0.1.1 d12.x86_64 pigsty 11.1 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~bookworm_amd64.deb
postgresql-16-pg-tokenizer 0.1.1 d12.aarch64 pigsty 10.9 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~bookworm_arm64.deb
postgresql-16-pg-tokenizer 0.1.1 d13.x86_64 pigsty 11.1 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~trixie_amd64.deb
postgresql-16-pg-tokenizer 0.1.1 d13.aarch64 pigsty 10.9 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~trixie_arm64.deb
postgresql-16-pg-tokenizer 0.1.1 u22.x86_64 pigsty 12.2 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~jammy_amd64.deb
postgresql-16-pg-tokenizer 0.1.1 u22.aarch64 pigsty 12.0 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~jammy_arm64.deb
postgresql-16-pg-tokenizer 0.1.1 u24.x86_64 pigsty 12.1 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~noble_amd64.deb
postgresql-16-pg-tokenizer 0.1.1 u24.aarch64 pigsty 12.0 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~noble_arm64.deb
postgresql-16-pg-tokenizer 0.1.1 u26.x86_64 pigsty 12.1 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~resolute_amd64.deb
postgresql-16-pg-tokenizer 0.1.1 u26.aarch64 pigsty 12.0 MiB postgresql-16-pg-tokenizer_0.1.1-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_tokenizer_15 0.1.1 el8.x86_64 pigsty 13.3 MiB pg_tokenizer_15-0.1.1-3PIGSTY.el8.x86_64.rpm
pg_tokenizer_15 0.1.1 el8.aarch64 pigsty 13.0 MiB pg_tokenizer_15-0.1.1-3PIGSTY.el8.aarch64.rpm
pg_tokenizer_15 0.1.1 el9.x86_64 pigsty 12.5 MiB pg_tokenizer_15-0.1.1-3PIGSTY.el9.x86_64.rpm
pg_tokenizer_15 0.1.1 el9.aarch64 pigsty 12.4 MiB pg_tokenizer_15-0.1.1-3PIGSTY.el9.aarch64.rpm
pg_tokenizer_15 0.1.1 el10.x86_64 pigsty 12.3 MiB pg_tokenizer_15-0.1.1-3PIGSTY.el10.x86_64.rpm
pg_tokenizer_15 0.1.1 el10.aarch64 pigsty 12.3 MiB pg_tokenizer_15-0.1.1-3PIGSTY.el10.aarch64.rpm
postgresql-15-pg-tokenizer 0.1.1 d12.x86_64 pigsty 11.1 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~bookworm_amd64.deb
postgresql-15-pg-tokenizer 0.1.1 d12.aarch64 pigsty 10.9 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~bookworm_arm64.deb
postgresql-15-pg-tokenizer 0.1.1 d13.x86_64 pigsty 11.1 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~trixie_amd64.deb
postgresql-15-pg-tokenizer 0.1.1 d13.aarch64 pigsty 10.9 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~trixie_arm64.deb
postgresql-15-pg-tokenizer 0.1.1 u22.x86_64 pigsty 12.1 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~jammy_amd64.deb
postgresql-15-pg-tokenizer 0.1.1 u22.aarch64 pigsty 12.0 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~jammy_arm64.deb
postgresql-15-pg-tokenizer 0.1.1 u24.x86_64 pigsty 12.1 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~noble_amd64.deb
postgresql-15-pg-tokenizer 0.1.1 u24.aarch64 pigsty 12.0 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~noble_arm64.deb
postgresql-15-pg-tokenizer 0.1.1 u26.x86_64 pigsty 12.1 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~resolute_amd64.deb
postgresql-15-pg-tokenizer 0.1.1 u26.aarch64 pigsty 12.0 MiB postgresql-15-pg-tokenizer_0.1.1-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_tokenizer_14 0.1.1 el8.x86_64 pigsty 13.3 MiB pg_tokenizer_14-0.1.1-3PIGSTY.el8.x86_64.rpm
pg_tokenizer_14 0.1.1 el8.aarch64 pigsty 13.0 MiB pg_tokenizer_14-0.1.1-3PIGSTY.el8.aarch64.rpm
pg_tokenizer_14 0.1.1 el9.x86_64 pigsty 12.4 MiB pg_tokenizer_14-0.1.1-3PIGSTY.el9.x86_64.rpm
pg_tokenizer_14 0.1.1 el9.aarch64 pigsty 12.4 MiB pg_tokenizer_14-0.1.1-3PIGSTY.el9.aarch64.rpm
pg_tokenizer_14 0.1.1 el10.x86_64 pigsty 12.3 MiB pg_tokenizer_14-0.1.1-3PIGSTY.el10.x86_64.rpm
pg_tokenizer_14 0.1.1 el10.aarch64 pigsty 12.3 MiB pg_tokenizer_14-0.1.1-3PIGSTY.el10.aarch64.rpm
postgresql-14-pg-tokenizer 0.1.1 d12.x86_64 pigsty 11.1 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~bookworm_amd64.deb
postgresql-14-pg-tokenizer 0.1.1 d12.aarch64 pigsty 10.9 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~bookworm_arm64.deb
postgresql-14-pg-tokenizer 0.1.1 d13.x86_64 pigsty 11.1 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~trixie_amd64.deb
postgresql-14-pg-tokenizer 0.1.1 d13.aarch64 pigsty 10.9 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~trixie_arm64.deb
postgresql-14-pg-tokenizer 0.1.1 u22.x86_64 pigsty 12.2 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~jammy_amd64.deb
postgresql-14-pg-tokenizer 0.1.1 u22.aarch64 pigsty 12.0 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~jammy_arm64.deb
postgresql-14-pg-tokenizer 0.1.1 u24.x86_64 pigsty 12.1 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~noble_amd64.deb
postgresql-14-pg-tokenizer 0.1.1 u24.aarch64 pigsty 12.0 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~noble_arm64.deb
postgresql-14-pg-tokenizer 0.1.1 u26.x86_64 pigsty 12.1 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~resolute_amd64.deb
postgresql-14-pg-tokenizer 0.1.1 u26.aarch64 pigsty 12.0 MiB postgresql-14-pg-tokenizer_0.1.1-3PIGSTY~resolute_arm64.deb

Source

github.com/supervc-stack/pg_tokenizer.rs

pig build pkg pg_tokenizer;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_tokenizer;		# install via package name, for the active PG version

pig install pg_tokenizer -v 18;   # install for PG 18
pig install pg_tokenizer -v 17;   # install for PG 17
pig install pg_tokenizer -v 16;   # install for PG 16
pig install pg_tokenizer -v 15;   # install for PG 15
pig install pg_tokenizer -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_tokenizer';

Create this extension with:

CREATE EXTENSION pg_tokenizer;

Usage

Sources:

pg_tokenizer converts text to token IDs for search applications, commonly with VectorChord-BM25. A tokenizer combines text analysis with a vocabulary model. It requires shared preloading and installs its SQL objects in the fixed tokenizer_catalog schema.

Enable and Tokenize

Add the library to the existing preload list and restart PostgreSQL:

shared_preload_libraries = 'pg_tokenizer'
CREATE EXTENSION pg_tokenizer;
SET search_path = public, tokenizer_catalog;

SELECT create_tokenizer('english', $$
model = "llmlingua2"
$$);
SELECT tokenize('PostgreSQL full text search', 'english');

tokenize(text, text) returns integer token IDs, not a relevance score or one row per token. With the BM25 companion installed, the returned array can be converted to its sparse vector type.

Analyze Chinese Text

Jieba is a pre-tokenizer, not a built-in vocabulary model named jieba. Build a text analyzer and a custom model for the corpus:

CREATE TABLE documents (
    id bigserial PRIMARY KEY,
    passage text,
    token_ids integer[]
);
SELECT create_text_analyzer('chinese', $$
[pre_tokenizer.jieba]
$$);
SELECT create_custom_model_tokenizer_and_trigger(
    tokenizer_name => 'zh_tokenizer',
    model_name => 'zh_model',
    text_analyzer_name => 'chinese',
    table_name => 'documents',
    source_column => 'passage',
    target_column => 'token_ids'
);
INSERT INTO documents(passage) VALUES ('PostgreSQL全文检索');
SELECT tokenize('数据库', 'zh_tokenizer');

The helper learns a vocabulary from the source column and creates a trigger to maintain token IDs. Use the same tokenizer/model for documents and queries. Japanese uses an explicitly created Lindera model with a configured dictionary; a bare model name from another tokenizer API is not interchangeable.

Object and Configuration Index

  • create_tokenizer, drop_tokenizer, tokenize: manage and execute tokenizers.
  • create_text_analyzer, apply_text_analyzer: run character filters, pre-tokenization, and token filters.
  • create_custom_model_tokenizer_and_trigger, create_lindera_model, create_huggingface_model: create corpus or imported models.
  • create_stopwords, create_synonym: manage dictionaries.
  • Built-in models include llmlingua2, bert_base_uncased, wiki_tocken, and gemma2b.
  • Version 0.1.1 adds the ngram token filter; min_gram and max_gram range from 1 to 255, while preserve_original defaults to false. Configurations use TOML.

Upgrade and Cache Boundaries

ALTER EXTENSION pg_tokenizer UPDATE TO '0.1.1';

After replacing a preloaded library, restart PostgreSQL before updating database objects. The 0.1.0-to-0.1.1 migration adds no SQL objects; behavior changes are in the library. Analyzer, model, and tokenizer objects are cached per connection, and this cache does not follow transaction isolation or rollback. Reconnect or use the relevant drop helper to clear an object retained after rollback. The extension is not relocatable after creation. It supplies tokenization; ranking and search indexes belong to its consumers.