The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
use fully qualified references in sql in examples (#28393)
Raminder Singhdaebf486c14c
diff --git a/apps/www/_blog/2024-02-13-matryoshka-embeddings.mdx b/apps/www/_blog/2024-02-13-matryoshka-embeddings.mdxindex a8aa4ce713b..d937b3482f2 100644--- a/apps/www/_blog/2024-02-13-matryoshka-embeddings.mdx+++ b/apps/www/_blog/2024-02-13-matryoshka-embeddings.mdx@@ -325,13 +325,14 @@ Note that we are choosing to store all 3072 dimensions for each document - we'llNext we'll create a new Postgres function called `sub_vector` that can shorten embeddings:```sql-create or replace function sub_vector(v vector, dimensions int)-returns vector+create or replace function sub_vector(v extensions.vector, dimensions int)+returns extensions.vectorlanguage plpgsqlimmutable+set search_path = ''as $$begin- if dimensions > vector_dims(v) then+ if dimensions > extensions.vector_dims(v) thenraise exception 'dimensions must be less than or equal to the vector size';end if;@@ -347,7 +348,7 @@ beginunnormed)select- array_agg(u.elem / r.factor)::vector+ array_agg(u.elem / r.factor)::extensions.vectorfromnorm r, unnormed u);@@ -383,24 +384,25 @@ Finally we can create our Adaptive Retrieval match function:```sqlcreate or replace function match_documents_adaptive(- query_embedding vector(3072),+ query_embedding extensions.vector(3072),match_count int)-returns setof documents+returns setof public.documentslanguage sql+set search_path = ''as $$with shortlist as (select *- from documents+ from public.documentsorder by- sub_vector(embedding, 512)::vector(512) <#> (- select sub_vector(query_embedding, 512)::vector(512)+ public.sub_vector(embedding, 512)::extensions.vector(512) operator(extensions.<#>) (+ select public.sub_vector(query_embedding, 512)::extensions.vector(512)) asclimit match_count * 8)select *from shortlist-order by embedding <#> query_embedding asc+order by embedding operator(extensions.<#>) query_embedding asclimit least(match_count, 200);$$;```