OpenAI
This guide will walk you through an example integration of the OpenAI API with the vecs Python library. We will create embeddings using OpenAI’s text-embedding-ada-002
model, insert these embeddings into a PostgreSQL database using vecs, and then query vecs to find the most similar sentences to a given query sentence.
Create an Environment
First, you need to set up your environment. You will need Python 3.7+ with the vecs
and openai
libraries installed.
You can install the necessary Python libraries using pip:
You’ll also need:
Create Embeddings
Next, we will use OpenAI’s text-embedding-ada-002
model to create embeddings for a set of sentences.
Store the Embeddings with vecs
Now that we have our embeddings, we can insert them into a PostgreSQL database using vecs.
Querying for Most Similar Sentences
Finally, we can query vecs to find the most similar sentences to a given query sentence. We will first need to create an embedding for the query sentence using the text-embedding-ada-002
model.
Returns the most similar 3 records and their distance to the query vector.