mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 18:52:12 +03:00
ca93cb9062
# Description - Added package manager - Added precommit checks - Rewrote dependency injection of Services and Repositories - Integrate async SQL alchemy engine - Migrate Chat repository to SQLModel - Migrated ChatHistory repository to SQLModel - User SQLModel - Unit test methodology with db rollback - Unit tests ChatRepository - Test ChatService get_history - Brain entity SQL Model - Promp SQLModel - Rewrite chat/{chat_id}/question route - updated docker files and docker compose in dev and production Added `quivr_core` subpackages: - Refactored KnowledgebrainQa - Added Rag service to interface with non-rag dependencies --------- Co-authored-by: aminediro <aminediro@github.com>
33 lines
851 B
PL/PgSQL
33 lines
851 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$
|
|
;
|