-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02-phase2-pgvector.sql
More file actions
30 lines (26 loc) · 1.09 KB
/
Copy path02-phase2-pgvector.sql
File metadata and controls
30 lines (26 loc) · 1.09 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
-- agent-memory-hub — Phase 2: semantic search (pgvector + gte-small)
-- Run in the Supabase SQL Editor (or via psql) after 01-schema.sql.
create extension if not exists vector;
alter table public.sessions add column if not exists embedding vector(384); -- gte-small = 384 dims
create index if not exists sessions_embedding_idx
on public.sessions using hnsw (embedding vector_cosine_ops);
-- Similarity search RPC. Called with the secret key (bypasses RLS).
create or replace function public.match_sessions(
query_embedding vector(384),
match_count int default 5,
filter_project text default null
)
returns table (
id uuid, session_id text, tool text, machine text, project text,
started_at timestamptz, content text, similarity float
)
language sql stable
as $$
select s.id, s.session_id, s.tool, s.machine, s.project, s.started_at, s.content,
1 - (s.embedding <=> query_embedding) as similarity
from public.sessions s
where s.embedding is not null
and (filter_project is null or s.project = filter_project)
order by s.embedding <=> query_embedding
limit match_count;
$$;