pg_bestmatch Documentation
pg_bestmatch (pg_bestmatch.rs) is a PostgreSQL extension for servicing Okapi BM25 text queries inside PostgreSQL by converting documents and queries into BM25-weighted sparse vectors compatible with pgvector (sparsevec) and pgvecto.rs (svector).
vchord_bm25 + pg_tokenizerpg_bestmatch.rs was TensorChord’s first-generation BM25 extension built on sparse vector dot products. For new production deployments, we recommend vchord_bm25 paired with pg_tokenizer, which replaces HNSW sparse-vector approximation with a native Block-WeakAnd (WAND) inverted index for 100% exact Top-K BM25 scoring and up to 3x higher throughput.
Key Capabilities
- In-Database BM25 Sparse Vector Generation: Maintains document frequency, term frequency, and document length statistics inside
bm25_catalogand emits BM25-weighted sparse vectors for both documents and queries. - Native
pgvector&pgvecto.rsIntegration: Outputs standardsparsevec(pgvector 0.7.0+) orsvector(pgvecto.rs) values so you can score documents with<#>(negative inner product) and accelerate search with HNSW indexes. - Built-in Tokenization: Ships with a built-in HuggingFace
bert-base-uncasedWordPiece vocabulary (30,522dimensions) and a standalonetokenize(text)SQL function.
Documentation Sections
How pg_bestmatch converts BM25 scoring into sparse vector inner products, installation from packages or source, and quickstart setup.
End-to-end BM25 retrieval workflow on the Stanford LoCo benchmark using pgvector sparsevec or pgvecto.rs svector.
Complete reference for bm25_create, bm25_refresh, bm25_drop, bm25_document_to_svector, bm25_query_to_svector, and tokenize.