Add missing sql

This commit is contained in:
shaun 2023-05-21 23:47:49 -07:00
parent c38265a5f5
commit fcb108808a
3 changed files with 41 additions and 1 deletions

2
.gitignore vendored
View File

@ -4,7 +4,7 @@ secondbrain/
**/*.pyc
toto.txt
*.ipynb
log.txt

View File

@ -95,6 +95,8 @@ cp .frontend_env.example frontend/.env
[Migration Script 2](scripts/supabase_usage_table.sql)
[Migration Script 3](scripts/supabase_vector_store_summary.sql)
- **Step 5**: Launch the app
```bash

View File

@ -0,0 +1,38 @@
-- Create a table to store your summaries
create table if not exists summaries (
id bigserial primary key,
document_id bigint references documents(id),
content text, -- corresponds to the summarized content
metadata jsonb, -- corresponds to Document.metadata
embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);
CREATE OR REPLACE FUNCTION match_summaries(query_embedding vector(1536), match_count int, match_threshold float)
RETURNS TABLE(
id bigint,
document_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,
document_id,
content,
metadata,
embedding,
1 -(summaries.embedding <=> query_embedding) AS similarity
FROM
summaries
WHERE 1 - (summaries.embedding <=> query_embedding) > match_threshold
ORDER BY
summaries.embedding <=> query_embedding
LIMIT match_count;
END;
$$;