-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
data/supabase/migrations/20230716205610_change_embedding_function_id_type.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
drop function if exists match_embeddings(vector(1536), int, jsonb); | ||
|
||
-- Create a function to search for embeddings | ||
create function match_embeddings ( | ||
query_embedding vector(1536), | ||
match_count int default null, | ||
filter jsonb DEFAULT '{}' | ||
) returns table ( | ||
id uuid, | ||
content text, | ||
metadata jsonb, | ||
similarity float | ||
) | ||
language plpgsql | ||
as $$ | ||
#variable_conflict use_column | ||
begin | ||
return query | ||
select | ||
id, | ||
content, | ||
metadata, | ||
1 - (embeddings.embedding <=> query_embedding) as similarity | ||
from embeddings | ||
where metadata @> filter | ||
order by embeddings.embedding <=> query_embedding | ||
limit match_count; | ||
end; | ||
$$; |