Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: openai-pgvector embedding example function

nathan0699a74dc3e5
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.mdx
index 46001ec1f17..5a689d9de29 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
@@ -104,7 +104,7 @@ Soon we're going to need to perform a similarity search over these embeddings. L
```sql
create or replace function match_documents (
query_embedding vector(1536),
- similarity_threshold float,
+ match_threshold float,
match_count int
)
returns table (
@@ -117,12 +117,12 @@ as $$
begin
return query
select
- id,
- content,
+ documents.id,
+ documents.content,
1 - (documents.embedding <=> query_embedding) as similarity
from documents
- where 1 - (documents.embedding <=> query_embedding) > similarity_threshold
- order by documents.embedding <=> query_embedding
+ where 1 - (documents.embedding <=> query_embedding) > match_threshold
+ order by similarity desc
limit match_count;
end;
$$;