forked from mckaywrigley/repo-chat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
33 lines (32 loc) · 1.08 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
create table repo_chat (
id bigserial primary key,
content text, -- corresponds to Document.pageContent
metadata jsonb, -- corresponds to Document.metadata
embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);
CREATE FUNCTION repo_chat_search(query_embedding vector(1536), match_count int)
RETURNS TABLE(
id bigint,
content text,
metadata jsonb,
-- we return matched vectors to enable maximal marginal relevance searches
embedding vector(1536),
similarity float)
LANGUAGE plpgsql
AS $$
# variable_conflict use_column
BEGIN
RETURN query
SELECT
id,
content,
metadata,
embedding,
1 -(repo_chat.embedding <=> query_embedding) AS similarity
FROM
repo_chat
ORDER BY
repo_chat.embedding <=> query_embedding
LIMIT match_count;
END;
$$;