-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
53 lines (50 loc) · 1.06 KB
/
schema.sql
File metadata and controls
53 lines (50 loc) · 1.06 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
-- RUN 1st
CREATE EXTENSION vector;
-- RUN 2nd
CREATE TABLE chunks (
id BIGSERIAL PRIMARY KEY,
url TEXT,
title TEXT,
content TEXT,
length BIGINT,
tokens BIGINT,
embedding VECTOR(1536)
);
-- RUN 3rd after running the scripts
CREATE OR REPLACE FUNCTION search_chunks (
query_embedding VECTOR(1536),
similarity_threshold FLOAT,
match_count INT
)
RETURNS TABLE (
id BIGINT,
url TEXT,
title TEXT,
content TEXT,
length BIGINT,
tokens BIGINT,
similarity FLOAT
)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT
chunks.id,
chunks.url,
chunks.title,
chunks.content,
chunks.length,
chunks.tokens,
1 - (chunks.embedding <=> query_embedding) AS similarity
FROM chunks
WHERE 1 - (chunks.embedding <=> query_embedding) > similarity_threshold
ORDER BY chunks.embedding <=> query_embedding
LIMIT match_count;
END;
$$;
-- RUN 4th
CREATE INDEX ON chunks
USING IVFFLAT (embedding VECTOR_COSINE_OPS)
WITH (lists = 100);-- Create the necessary tables for the Express Entry Chatbot
-- You can define your database schema here