-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_supabase.sql
More file actions
58 lines (53 loc) · 1.54 KB
/
Copy pathsetup_supabase.sql
File metadata and controls
58 lines (53 loc) · 1.54 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
-- MOI Agent — Supabase setup
-- Run this in your Supabase SQL Editor (https://supabase.com/dashboard/project/qnchustgklovrtxbbnvp/sql)
-- Enable pgvector
CREATE EXTENSION IF NOT EXISTS vector;
-- Memories table
CREATE TABLE IF NOT EXISTS agent_memories (
id bigserial PRIMARY KEY,
content text NOT NULL,
metadata jsonb DEFAULT '{}',
embedding vector(768),
created_at timestamptz DEFAULT now()
);
-- Vector similarity search index
CREATE INDEX IF NOT EXISTS idx_agent_memories_embedding
ON agent_memories USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
-- Semantic search function
CREATE OR REPLACE FUNCTION match_memories(
query_embedding vector(768),
match_threshold float DEFAULT 0.7,
match_count int DEFAULT 5
)
RETURNS TABLE (
id bigint,
content text,
metadata jsonb,
similarity float
)
LANGUAGE sql STABLE
AS $$
SELECT
id,
content,
metadata,
1 - (embedding <=> query_embedding) AS similarity
FROM agent_memories
WHERE 1 - (embedding <=> query_embedding) > match_threshold
ORDER BY embedding <=> query_embedding
LIMIT match_count;
$$;
-- Task history table (for analytics / snowball tracking)
CREATE TABLE IF NOT EXISTS agent_task_history (
id bigserial PRIMARY KEY,
task_id text NOT NULL,
instruction text NOT NULL,
status text NOT NULL,
result text DEFAULT '',
source text DEFAULT 'dashboard',
steps jsonb DEFAULT '[]',
duration_ms int,
model_used text,
created_at timestamptz DEFAULT now()
);