-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
70 lines (66 loc) · 1.75 KB
/
schema.sql
File metadata and controls
70 lines (66 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
-- Enable pgvector extension
create extension if not exists vector;
-- Stores every PR that was reviewed
create table reviews (
id uuid primary key default gen_random_uuid(),
repo text not null,
pr_number integer not null,
pr_title text,
author text,
created_at timestamptz default now()
);
-- Stores every issue found, with its embedding
create table issues (
id uuid primary key default gen_random_uuid(),
review_id uuid references reviews(id) on delete cascade,
repo text not null,
pr_number integer not null,
file text not null,
line integer,
severity text not null,
type text not null,
message text not null,
suggestion text,
embedding vector(1024),
created_at timestamptz default now()
);
-- Index for fast similarity search
create index on issues using ivfflat (embedding vector_cosine_ops)
with (lists = 100);
-- Function: find similar past issues using cosine similarity
create or replace function find_similar_issues(
query_embedding vector(1024),
match_threshold float,
match_count int,
filter_repo text default null
)
returns table (
id uuid,
repo text,
pr_number integer,
file text,
severity text,
type text,
message text,
suggestion text,
similarity float
)
language sql stable
as $$
select
i.id,
i.repo,
i.pr_number,
i.file,
i.severity,
i.type,
i.message,
i.suggestion,
1 - (i.embedding <=> query_embedding) as similarity
from issues i
where
(filter_repo is null or i.repo = filter_repo)
and 1 - (i.embedding <=> query_embedding) > match_threshold
order by i.embedding <=> query_embedding
limit match_count;
$$;