quivr/supabase/migrations/20240119070124_search.sql
Stan Girard d0b8b797f6
feat(search): new way to interact with Quivr (#2026)
Co-authored-by: Zewed <dewez.antoine2@gmail.com>
Co-authored-by: Antoine Dewez <44063631+Zewed@users.noreply.github.com>
2024-01-19 20:34:30 -08:00

28 lines
701 B
PL/PgSQL

alter table "public"."brains" add column "meaning" vector;
alter table "public"."brains" alter column "description" set default 'This needs to be changed'::text;
alter table "public"."brains" alter column "description" set not null;
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.match_brain(query_embedding vector, match_count integer)
RETURNS TABLE(id uuid, name text, similarity double precision)
LANGUAGE plpgsql
AS $function$
#variable_conflict use_column
begin
return query
select
brain_id,
name,
1 - (brains.meaning <=> query_embedding) as similarity
from brains
order by brains.meaning <=> query_embedding
limit match_count;
end;
$function$
;