feat(tools): implement CRUD operations for thoughts and projects
* Add tools for creating, retrieving, updating, and deleting thoughts. * Implement project management tools for creating and listing projects. * Introduce linking functionality between thoughts. * Add search and recall capabilities for thoughts based on semantic queries. * Implement statistics and summarization tools for thought analysis. * Create database migrations for thoughts, projects, and links. * Add helper functions for UUID parsing and project resolution.
This commit is contained in:
2
migrations/001_enable_vector.sql
Normal file
2
migrations/001_enable_vector.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
create extension if not exists vector;
|
||||
create extension if not exists pgcrypto;
|
||||
17
migrations/002_create_thoughts.sql
Normal file
17
migrations/002_create_thoughts.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
create table if not exists thoughts (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
content text not null,
|
||||
embedding vector(1536),
|
||||
metadata jsonb default '{}'::jsonb,
|
||||
created_at timestamptz default now(),
|
||||
updated_at timestamptz default now()
|
||||
);
|
||||
|
||||
create index if not exists thoughts_embedding_hnsw_idx
|
||||
on thoughts using hnsw (embedding vector_cosine_ops);
|
||||
|
||||
create index if not exists thoughts_metadata_gin_idx
|
||||
on thoughts using gin (metadata);
|
||||
|
||||
create index if not exists thoughts_created_at_idx
|
||||
on thoughts (created_at desc);
|
||||
13
migrations/003_add_projects.sql
Normal file
13
migrations/003_add_projects.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
create table if not exists projects (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
name text not null unique,
|
||||
description text,
|
||||
created_at timestamptz default now(),
|
||||
last_active_at timestamptz default now()
|
||||
);
|
||||
|
||||
alter table thoughts add column if not exists project_id uuid references projects(id);
|
||||
alter table thoughts add column if not exists archived_at timestamptz;
|
||||
|
||||
create index if not exists thoughts_project_id_idx on thoughts (project_id);
|
||||
create index if not exists thoughts_archived_at_idx on thoughts (archived_at);
|
||||
10
migrations/004_create_thought_links.sql
Normal file
10
migrations/004_create_thought_links.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
create table if not exists thought_links (
|
||||
from_id uuid references thoughts(id) on delete cascade,
|
||||
to_id uuid references thoughts(id) on delete cascade,
|
||||
relation text not null,
|
||||
created_at timestamptz default now(),
|
||||
primary key (from_id, to_id, relation)
|
||||
);
|
||||
|
||||
create index if not exists thought_links_from_idx on thought_links (from_id);
|
||||
create index if not exists thought_links_to_idx on thought_links (to_id);
|
||||
31
migrations/005_create_match_thoughts.sql
Normal file
31
migrations/005_create_match_thoughts.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
create or replace function match_thoughts(
|
||||
query_embedding vector(1536),
|
||||
match_threshold float default 0.7,
|
||||
match_count int default 10,
|
||||
filter jsonb default '{}'::jsonb
|
||||
)
|
||||
returns table (
|
||||
id uuid,
|
||||
content text,
|
||||
metadata jsonb,
|
||||
similarity float,
|
||||
created_at timestamptz
|
||||
)
|
||||
language plpgsql
|
||||
as $$
|
||||
begin
|
||||
return query
|
||||
select
|
||||
t.id,
|
||||
t.content,
|
||||
t.metadata,
|
||||
1 - (t.embedding <=> query_embedding) as similarity,
|
||||
t.created_at
|
||||
from thoughts t
|
||||
where 1 - (t.embedding <=> query_embedding) > match_threshold
|
||||
and t.archived_at is null
|
||||
and (filter = '{}'::jsonb or t.metadata @> filter)
|
||||
order by t.embedding <=> query_embedding
|
||||
limit match_count;
|
||||
end;
|
||||
$$;
|
||||
5
migrations/006_rls_and_grants.sql
Normal file
5
migrations/006_rls_and_grants.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Grant these permissions to the database role used by the application.
|
||||
-- Replace amcs_user with the actual role in your deployment before applying.
|
||||
grant select, insert, update, delete on table public.thoughts to amcs_user;
|
||||
grant select, insert, update, delete on table public.projects to amcs_user;
|
||||
grant select, insert, update, delete on table public.thought_links to amcs_user;
|
||||
Reference in New Issue
Block a user