Created
March 30, 2024 04:36
-
-
Save juliooa/96f579e30570146c6544a2fcedd7e1a0 to your computer and use it in GitHub Desktop.
Similarity function for embeddings, to use in Supabase
This file contains hidden or 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
CREATE OR REPLACE FUNCTION public.match_documents( | |
query_embedding vector, | |
match_threshold double precision, | |
match_count integer | |
) RETURNS TABLE( | |
id bigint, | |
content text, | |
similarity double precision, | |
metadata jsonb | |
) LANGUAGE sql STABLE AS $function$ | |
select documents.id, | |
documents.content, | |
1 - (documents.embedding <=> query_embedding) as similarity, | |
documents.metadata | |
from documents | |
where documents.embedding <=> query_embedding < 1 - match_threshold | |
order by documents.embedding <=> query_embedding | |
limit match_count; | |
$function$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should have a table called
documents
with columns: id, content, metadata, embedding.