SQL Extension

Open Source Models

PostgresML integrates 🤗 Hugging Face Transformers to bring state-of-the-art models into the data layer. There are tens of thousands of pre-trained models with pipelines to turn raw inputs into useful results. Many LLMs have been published and made available for download. You will want to browse all the models available to find the perfect solution for your dataset and task. The pgml extension provides a few APIs for different use cases:

  • pgml.embed returns vector embeddings for nearest neighbor searches and other vector database use cases
  • pgml.generate returns streaming text responses for chatbots
  • pgml.transform allows you to perform dozens of natural language processing (NLP) tasks with thousands of models, like sentiment analysis, question and answering, translation, summarization and text generation
  • pgml.tune fine tunes an open source model on your own data

Train & deploy your own models

PostgresML also supports more than 50 machine learning algorithms to train your own models for classification, regression or clustering. We organize a family of Models in Projects that are intended to address a particular opportunity. Different algorithms can be used in the same Project, to test and compare the performance of various approaches, and track progress over time, all within your database.


Training creates a Model based on the data in your database.

content_copy link edit
SELECT pgml.train(
project_name = > 'Sales Forecast',
task => 'regression',
relation_name => 'hist_sales',
y_column_name => 'next_sales',
algorithm => 'xgboost'

See pgml.train for more information.


Deploy an active Model for a particular Project, using a deployment strategy to select the best model.

content_copy link edit
SELECT pgml.deploy(
project_name => 'Sales Forecast',
strategy => 'best_score',
algorithm => 'xgboost'

See pgml.deploy for more information.


Use your Model on novel data points not seen during training to infer a new data point.

content_copy link edit
SELECT pgml.predict(
project_name => 'Sales Forecast',
features => ARRAY[
) AS prediction
FROM new_sales
ORDER BY prediction DESC;

Seepgml.predict for more information.