Files
accounted/supabase/migrations/20240101000038_fix_match_documents_search_path.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

38 lines
878 B
PL/PgSQL

-- Migration 038: Fix match_documents search_path
-- The function needs the extensions schema in search_path to use pgvector operators.
create or replace function public.match_documents(
query_embedding extensions.vector,
match_count int default 5,
match_threshold float default 0.7
)
returns table (
id uuid,
source_file text,
title text,
section_title text,
content text,
metadata jsonb,
similarity float
)
language plpgsql
security definer
set search_path = public, extensions
as $$
begin
return query
select
kd.id,
kd.source_file,
kd.title,
kd.section_title,
kd.content,
kd.metadata,
1 - (kd.embedding <=> query_embedding)::float as similarity
from public.knowledge_documents kd
where 1 - (kd.embedding <=> query_embedding) >= match_threshold
order by kd.embedding <=> query_embedding
limit match_count;
end;
$$;