We’re pleased to introduce the pgvector extension on Heroku Postgres. In an era where large language models (LLMs) and AI applications are paramount, pgvector provides the essential capability for performing high-dimensional vector similarity searches. This allows Heroku Postgres to quickly find similar data points in complex data, which is great for applications like recommendation systems and prompt engineering for LLMs. As of today, pgvector is fully compatible with all Production-tier databases running Postgres 15 at no additional charge and you can get started with a simple CREATE EXTENSION vector;
command in your client session. In this post, we look at how you can use pgvector and its potential applications to enhance your business operations.
Understanding pgvector and Its Significance
Heroku Postgres has evolved well beyond being “just” a relational database. It’s become an adaptable platform enriched with a range of extensions that add new functionalities. Like how we introduced PostGIS for efficient geospatial data handling, we now introduce pgvector, an innovative extension that turns your Heroku Postgres instance into a robust vector database. This enhancement allows you to effectively store vectorized data and execute advanced similarity searches, a capability that can drive innovation in your business.
Complex data can be reduced and represented as vectors. These vectors serve as coordinates in a multi-dimensional space, with hundreds or even thousands of dimensions to represent the data. Datasets that are similar are translated as vectors that are close together, making mathematical similarity calculations simple. For example, characterizing fruits through vectors based on attributes such as color, shape, size, and taste. Vectors that are close to each other share substantial similarities in fruit characteristics, a powerful insight enabled by pgvector.
For AI inference applications, data transformed into its vector representation is called an "embedding". An AI embedding model commonly creates the embeddings. A vector database is a specialized system designed to store these "vectors" or "embeddings". It can quickly find vectors that are close in direction and magnitude across a spectrum of attributes.
Building on this concept, imagine you have a database full of various fruits, each embedded with its unique vector through a machine learning model. Now, let’s say you’re on a quest to find the perfect substitutes for red apples in your fruit salad, with emphasis on their taste and texture. By deploying a vector similarity search, you’ll find alternatives such as green apples and pears, but not fruits like bananas and tomatoes.
Potential Use Cases for pgvector Extension
Using pgvector lets you:
Run Prompt Engineering with Retrieval Augmented Generation (RAG): You can populate the database with embedded text segments, such as the latest product documentation for a specific domain, like your business. Given a prompt, RAG can retrieve the most relevant text segments, which are then augmented or “pasted” into the prompt for generative AI. The AI can then generate responses that are both accurate and contextually relevant.
Recommend Products: With a vector database containing various attributes, searching for alternatives based on the search criteria is simple. For example in the world of fashion, you can make recommendations based on similar products like dresses or shirts, or match the style and color to offer pants or shoes. You can further extend this with collaborative filtering where the similar preferences of other shoppers enhance the recommendations.
Search Salesforce Data: Use Heroku Connect to synchronize Salesforce data into Heroku, then create a new table with the embeddings since Heroku Connect can’t synchronize vector data types. This unlocks a whole new possibility to extend Salesforce like searching for similar support cases with embeddings from Service Cloud cases.
Search Multimedia : Search across multimedia contents, like image, audio, and video. You can embed the content directly or work with transcriptions and other attributes to perform your search. For example, generating a music playlist by finding similar tracks based on embedded features like tempo, mood, genre, and lyrics.
Categorize and Segment Data: In a variety of fields, from healthcare to manufacturing, data segmentation and categorization are key to successful data analysis. For example, by converting patient records, diagnostic data, or genomic sequences into vectors, you can identify similar cases, aiding in rare disease diagnosis and personalized treatment recommendations.
Detect Anomalies: Detect anomalies in your data by comparing vectors that don’t fit the regular pattern. This can be useful in analyzing and detecting problematic or suspicious patterns in areas such as network traffic data, industrial sensor data, transactions data, or online behavior.
For more details on how to actually prepare a database for vector search, look for a post coming soon on our engineering blog!
A Glimpse into the AI Future of Heroku
The pgvector extension adds a whole new dimension to Heroku Postgres. We hope this post was helpful in sparking your interest to start experimenting with vector databases. This introduction to pgvector marks the first step in our journey towards AI-enabled offerings on Heroku. We plan on unveiling much more in the near future, so stay tuned for upcoming innovations that we hope will continue to transform how you build and deploy applications.
We extend our appreciation to the community for their support in advocating for the significance of pgvector. Your engagement has played a vital role in prioritizing this addition to Heroku Postgres. If you have questions, challenges, or require assistance, our dedicated Support team is available to assist you on your journey into this exciting new frontier.