Pgai Brings Your ML Workload To The Database
Written by Nikos Vaggalis   
Monday, 15 July 2024

Extensions like pgai are targeted at the "AI Engineers", a new breed of developers who unlike researchers are concerned with practically applying AI (models, tools, and APIs) to build software.

These engineers don't want to leave their favorite tools for other tools dedicated to AI. Replace "tool" with Postgres and you'll see where this is going.

In "Azure AI And Pgvector Run Generative AI Directly On Postgres" we witnessed the exact case in point. The Azure AI extension enables the database to call into various Azure AI services like Azure OpenAI.

In short, what this means is that you can generate text embeddings by using SQL queries to call into both Azure OpenAI services without needing a separate application layer. It's all about making the developer's life easy by shifting the Machine Learning workload onto the database. That is, you provided with the ability to run ML models on your live data, without leaving the database.

The new pgai open-source extension by Timescale does that exactly. It brings embedding and generation models closer to the database, making PostgreSQL an even better database for AI applications, catering for the needs of AI Engineers as stated in its official announcement:

We spoke to a Timescale customer who was tasked with building a RAG application at their company. This engineer had decades of database and C experience but complained to us about fumbling around trying to learn Python to quickly build a proof-of-concept (PoC) to validate the core idea. “I wish I could do more of this in SQL” was a common refrain we heard from this and many other engineers we spoke to, ultimately sparking the idea for pgai.

Wish granted!

With pgai, you can now do the following directly from within PostgreSQL in a SQL query:

  • Create embeddings for your data.
  • Retrieve LLM chat completions from models like OpenAI GPT4o and Llama 3.
  • Generate responses for models such as Ollama.
  • Reason over your data and facilitate use cases like classification, summarization, and data enrichment on your existing relational data in PostgreSQL.

For instance, doing Chat completion to return the content as text from a specific message :

The data returned looks like:

Many examples to get you started can be found on the extension's Github repo, like using pgai with OpenAI.

The initial release of pgai supports creating OpenAI embeddings and getting OpenAI chat completions from models like GPT4o directly from your PostgreSQL database. The plan is to add support for more models in the future such as Claude and Cohere.

At this point I'd like to note down that there's another extension, PostgresML, which shares a very similar if not the same purpose. As we examined in which we examined in "PostgresML - Bring Your ML Workload To The Database", PostgresML is a machine learning extension for PostgreSQL that enables you to perform training and inference on text and tabular data using SQL queries. So make sure to check that article out to figure out which of the two extensions fits your purpose best.

The gist, however, is that with extensions like this you can utilize PostgreSQL for AI as well without going out of your way. AI Engineers rejoice!

 

More Information

pgai Github

Pgai: Giving PostgreSQL Developers AI Engineering Superpowers
 

Related Articles

PostgresML - Bring Your ML Workload To The Database

Azure AI And Pgvector Run Generative AI Directly On Postgres

 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Apache Releases Tomcat 11
07/11/2024

Apache has announced the release of Tomcat 11, as well as marking the 25th anniversary of the first commit to the Apache Tomcat source code repository since becoming an ASF project.



Microsoft Introduces Vector Abstractions Library For .NET
21/11/2024

Microsoft has announced a preview release of the Microsoft Extensions VectorData Abstractions library, which can be used to help integrate vector stores into .NET applications and libraries.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Monday, 15 July 2024 )