Natural language processing extensions for the Postgresql database. It uses a number of pretrained language models to perform common tasks such as translation, classification, sentance embeddings and much more.
select babel('Hallo','nl','en');
Hello
select sbert('...');
'[...]'
The output of sbert
is supported by pgvector.
select vector(sbert('...'));
[...]
It supports the operators for the L2 product <->
, the cosine distance <=>
or the inner product <#>
.
select summary('...');
...
select ask_question('Hallo','context');
Hello
Classify text with a pretrained language transformer.
select zero_shot('text',['amsterdam','berlin','copenhagen']);
'berlin'
Make sure to install both pgx
and rust-bert
correctly
and config your environment variables to be able to find the libtorch
shared library.
Run example:
LD_LIBRARY_PATH=${HOME}/Code/libtorch/lib:$LD_LIBRARY_PATH cargo pgx run
Install package
LD_LIBRARY_PATH=${HOME}/Code/libtorch/lib:$LD_LIBRARY_PATH sudo cargo pgx install
- Nix: TODO
- Source: TODO
- Ubuntu:
sudo apt install build-essential libclang-dev libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache postgresql-server-dev-15 -y
- Install libtorch
https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.13.1%2Bcpu.zip cargo install --locked cargo-pgx
cargo pgx init
- Install libtorch
This extension can be used together with the pgvector extension. Pgvector must be compiled from source and to copied to the pgx test installation of postgresql.
cp vector.so ~/.pgx/15.2/pgx-install/lib/postgresql/x
cp vector.control ~/.pgx/15.2/pgx-install/share/postgresql/extension/
cp sql/vector*.sql ~/.pgx/15.2/pgx-install/share/postgresql/extension/
RUSTBERT_CACHE
location of language models defaults to~/.cache/.rustbert
PGX_IGNORE_RUST_VERSIONS
- Postgresql Internals
- The Wonders of Postgres Logical Decoding Messages
- Neural Networks: Zero to Hero, ML course by Andrej Karpathy