Created
January 8, 2024 21:07
-
-
Save kenny-io/37ebdc6552b4a94b70185063c9f67a9f to your computer and use it in GitHub Desktop.
vector-search sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Supabase AI is experimental and may produce incorrect answers | |
-- Always verify the output before executing | |
create | |
or replace function vector_search ( | |
query_embedding vector (1536), | |
similarity_threshold float, | |
match_count int | |
) returns table ( | |
id bigint, | |
first_name text, | |
last_name text, | |
image text, | |
address jsonb, | |
occupation text, | |
age int2, | |
hobbies text[], | |
relationship_status text, | |
country_of_origin text, | |
email text, | |
bio text, | |
similarity float | |
) language plpgsql as $$ begin return query select celebrities.id, celebrities.first_name, celebrities.last_name, celebrities.image, celebrities.address, celebrities.occupation, celebrities.age, celebrities.hobbies, celebrities.relationship_status, celebrities.country_of_origin, celebrities.email, celebrities.bio, 1 - (celebrities.embeddings <=> query_embedding) as similarity from celebrities where 1 - (celebrities.embeddings <=> query_embedding) > similarity_threshold order by celebrities.embeddings <=> query_embedding limit match_count; end; $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment