Repository navigation
Expand file tree
/
Copy pathschema.sql
More file actions
66 lines (60 loc) · 1.45 KB
/
Copy pathschema.sql
File metadata and controls
66 lines (60 loc) · 1.45 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
-- Supabase AI is experimental and may produce incorrect answers
-- Always verify the output before executing
create table if not exists
chapters (
id SERIAL primary key,
video_title text,
chapter_title text,
video_date text,
video_id text,
start_time float,
end_time float,
conversation JSONB,
conversation_length integer,
conversation_tokens bigint,
embedding vector (1536)
);
create or replace function chapter_search(
query_embedding vector(1536),
similarity_threshold float,
match_count int
)
returns table (
id bigint,
video_title text,
chapter_title text,
video_date text,
video_id text,
start_time float,
end_time float,
conversation JSONB,
conversation_length integer,
conversation_tokens bigint,
similarity float
)
language plpgsql
as $$
begin
return query
select
chapters.id,
chapters.video_title,
chapters.chapter_title,
chapters.video_date,
chapters.video_id,
chapters.start_time,
chapters.end_time,
chapters.conversation,
chapters.conversation_length,
chapters.conversation_tokens,
1 - (chapters.embedding <=> query_embedding) as similarity
from chapters
where 1 - (chapters.embedding <=> query_embedding) > similarity_threshold
order by chapters.embedding <=> query_embedding
limit match_count;
end;
$$;
create index on chapters
using ivfflat (embedding vector_cosine_ops)
with (lists = 100);
-- RUN 1st create extension vector;