-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
76 lines (72 loc) · 2.15 KB
/
schema.sql
File metadata and controls
76 lines (72 loc) · 2.15 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
67
68
69
70
71
72
73
74
75
76
-- SignalDesk — Supabase Schema
-- Enable pgvector extension
create extension if not exists vector;
-- Sources table
-- Stores raw content from each upload (PDF, YouTube, text)
-- One row per document / video / paste
create table sources (
id uuid default gen_random_uuid() primary key,
source_id text unique, -- filename (PDF) or videoId (YouTube) for dedup
channel text, -- influencer / channel name
input_type text, -- 'pdf' | 'youtube' | 'text'
raw_content text, -- full raw text before extraction
created_at timestamp default now()
);
-- Signals table
-- Stores extracted investment signals with embeddings
-- One row per stock per document (not one row per document)
create table signals (
id bigserial primary key,
content text, -- formatted signal: stock + stance + verbatim quote + reasoning
metadata jsonb, -- stock_name, stance, channel, doc_date, verbatim_quote, reasoning
embedding vector(1536) -- OpenAI text-embedding-ada-002
);
-- Semantic search function
-- Used by query_knowledge_tool to retrieve relevant signals
create or replace function public.match_signals (
query_embedding vector(1536),
match_count int default null,
filter jsonb default '{}'
) returns table (
id bigint,
content text,
metadata jsonb,
similarity float
)
language plpgsql
security definer
as $$
begin
return query
select
signals.id,
signals.content,
signals.metadata,
1 - (signals.embedding <=> query_embedding) as similarity
from signals
where signals.metadata @> filter
order by signals.embedding <=> query_embedding
limit match_count;
end;
$$;
-- Dashboard function
-- Used by dashboard_tool to return all signals with a doc_date
-- Filtered to last 30 days and grouped by stance in the n8n Code node
create or replace function public.get_current_signals()
returns table (
stock_name text,
stance text,
channel text,
doc_date text
)
language sql
security definer
as $$
select
metadata->>'stock_name',
metadata->>'stance',
metadata->>'channel',
metadata->>'doc_date'
from public.signals
where metadata->>'doc_date' is not null;
$$;