mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-02 08:40:53 +03:00
6ed4248d35
fixed public brains avaiable # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
35 lines
854 B
PL/PgSQL
35 lines
854 B
PL/PgSQL
create type "public"."thumbs" as enum ('up', 'down');
|
|
|
|
drop function if exists "public"."match_brain"(query_embedding vector, match_count integer);
|
|
|
|
alter table "public"."chat_history" add column "user_feedback" thumbs;
|
|
|
|
set check_function_bodies = off;
|
|
|
|
CREATE OR REPLACE FUNCTION public.match_brain(query_embedding vector, match_count integer, p_user_id uuid)
|
|
RETURNS TABLE(id uuid, name text, similarity double precision)
|
|
LANGUAGE plpgsql
|
|
AS $function$
|
|
BEGIN
|
|
RETURN QUERY
|
|
SELECT
|
|
b.brain_id,
|
|
b.name,
|
|
1 - (b.meaning <=> query_embedding) as similarity
|
|
FROM
|
|
brains b
|
|
LEFT JOIN
|
|
brains_users bu ON b.brain_id = bu.brain_id
|
|
WHERE
|
|
(b.status = 'public') OR
|
|
(bu.user_id = p_user_id AND bu.rights IN ('Owner', 'Editor', 'Viewer'))
|
|
ORDER BY
|
|
b.meaning <=> query_embedding
|
|
LIMIT
|
|
match_count;
|
|
END;
|
|
$function$
|
|
;
|
|
|
|
|