Skip to content

Instantly share code, notes, and snippets.

@kenny-io
Created January 8, 2024 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenny-io/37ebdc6552b4a94b70185063c9f67a9f to your computer and use it in GitHub Desktop.
Save kenny-io/37ebdc6552b4a94b70185063c9f67a9f to your computer and use it in GitHub Desktop.
vector-search sql
-- 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