bpg_vectorize: A VectorDB for Postgres

Feb 5, 2021 | Educational

pg_vectorize

A Quick Overview

bpg_vectorize is a Postgres extension designed to automate the transformation and orchestration of text into embeddings. This dynamic tool simplifies vector searches and allows for the development of applications powered by large language models (LLMs) using just two function calls.

Features

  • Workflows for both vector search and RAG.
  • Integrations with OpenAI’s embeddings and chat-completion endpoints.
  • Automated creation of Postgres triggers to keep your embeddings up to date.
  • High-level API – just one function to initialize embedding transformations and another to search.

Installation Guide

To jump right in, the quickest method is to run the Tembo Docker container using Docker Compose:

docker compose up -d

Then connect to Postgres:

docker compose exec -it postgres psql

Next, enable the extension and its dependencies:

CREATE EXTENSION vectorize CASCADE;

If you’re installing this into an existing Postgres instance, ensure you have the following dependencies:

Using bpg_vectorize

Let’s think of embedding transformation like preparing a gourmet dish. You need to first gather your ingredients (the text), mix them perfectly (transform them into embeddings), and finally serve them in a delightful manner (searching through vectors).

Vector Search Example

Start by setting up a products table:

CREATE TABLE products (LIKE vectorize.example_products INCLUDING ALL);
INSERT INTO products SELECT * FROM vectorize.example_products;

To create a job that vectorizes the products table, run:

SELECT vectorize.table(
    job_name    = product_search_hf,
    table       = products,
    primary_key = product_id,
    columns     = ARRAY[product_name, description],
    transformer = sentence-transformers/all-MiniLM-L6-v2,
    schedule    = realtime);

Next, search for relevant products:

SELECT * FROM vectorize.search(
    job_name        = product_search_hf,
    query           = 'accessories for mobile devices',
    return_columns  = ARRAY[product_id, product_name],
    num_results     = 3);

RAG Example

Here’s how you can ask raw text questions and receive chat responses:

ALTER SYSTEM SET vectorize.openai_key TO 'your api key';
SELECT pg_reload_conf();

Updating Embeddings

To ensure your embeddings remain current, you can set the update schedule according to your data needs. Using a cron-like value or schedule = realtime can optimize your updates.

Troubleshooting

If issues arise during installation or operation, consider these troubleshooting ideas:

  • Check that all required dependencies are installed and properly configured.
  • Ensure that the Docker container is running as expected.
  • Review any error messages for specific dependencies that may be missing or misconfigured.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Words

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions.
Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox