-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
60 lines (54 loc) · 1.48 KB
/
schema.sql
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
-- https://supabase.com/blog/openai-embeddings-postgres-vector ❤️
-- one to one with DemoDaySubmission struct
create table demoday_submission (
id serial primary key,
title text not null,
niche text not null,
description text not null,
youtube_url text not null,
youtube_transcript text not null,
social text not null,
season text not null,
embedding vector(1536)
);
-- requests are only going to made on the server at the moment
-- might change later
alter table demoday_submission enable row level security;
--
create index on demoday_submission using ivfflat (embedding vector_cosine_ops)
with
(lists = 500);
-- function
create or replace function match_person (
query_embedding vector(1536),
match_threshold float,
match_count int
)
returns table (
id bigint,
title text,
niche text,
description text,
youtube_url text,
youtube_transcript text,
social text,
season text,
similarity float
)
language sql stable
as $$
select
demoday_submission.id,
demoday_submission.title,
demoday_submission.niche,
demoday_submission.description,
demoday_submission.youtube_url,
demoday_submission.youtube_transcript,
demoday_submission.social,
demoday_submission.season,
1 - (demoday_submission.embedding <=> query_embedding) as similarity
from demoday_submission
where demoday_submission.embedding <=> query_embedding < 1 - match_threshold
order by demoday_submission.embedding <=> query_embedding
limit match_count;
$$;