The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
trying ignore blocks
Copple0e99fa41b58f
diff --git a/apps/www/_blog/2023-02-03-openai-embeddings-postgres-vector.mdx b/apps/www/_blog/2023-02-03-openai-embeddings-postgres-vector.mdxindex 685fda7d0a6..9eaaf62c332 100644--- a/apps/www/_blog/2023-02-03-openai-embeddings-postgres-vector.mdx+++ b/apps/www/_blog/2023-02-03-openai-embeddings-postgres-vector.mdx@@ -86,6 +86,7 @@ create extension vector;Next let's create a table to store our documents and their embeddings:+<!-- prettier-ignore-start -->```sqlcreate table documents (id bigserial primary key,@@ -93,6 +94,7 @@ create table documents (embedding vector (1536));```+<!-- prettier-ignore-end -->`pgvector` introduces a new data type called `vector`. In the code above, we create a column named `embedding` with the `vector` data type. The size of the vector defines how many dimensions the vector holds. OpenAI's `text-embedding-ada-002` model outputs 1536 dimensions, so we will use that for our vector size.@@ -100,6 +102,7 @@ We also create a `text` column named `content` to store the original document teSoon we're going to need to perform a similarity search over these embeddings. Let's create a function to do that:+<!-- prettier-ignore-start -->```sqlcreate or replace function match_documents (query_embedding vector(1536),@@ -126,6 +129,7 @@ beginend;$$;```+<!-- prettier-ignore-end -->`pgvector` introduces 3 new operators that can be used to calculate similarity:@@ -145,11 +149,13 @@ Once your table starts to grow with embeddings, you will likely want to add an iEach distance operator requires a different type of index. We expect to order by cosine distance, so we need `vector_cosine_ops` index. A good starting number of lists is 4 \* sqrt(table_rows):+<!-- prettier-ignore-start -->```sqlcreate index on documentsusing ivfflat (embedding vector_cosine_ops)with (lists = 100);```+<!-- prettier-ignore-end -->You can read more about indexing on `pgvector`'s GitHub page [here](https://github.com/pgvector/pgvector#indexing).