Фаза 1: скелет MCP-сервера пам'яті

- TypeScript + @modelcontextprotocol/sdk, Streamable HTTP (stateless), API-ключ
- Схема БД: projects, memories (FTS + vector 1024), memory_links, sessions
- Інструменти: memory_* (save/query/get/update/delete/link/graph), project_* (list/create/get_state/save_state)
- EmbeddingProvider абстракція (Null у фазі 1, Ollama bge-m3 у фазі 2)
- Dockerfile + compose.yml (ai-memory-server + ai-memory-db pgvector/pgvector:pg18)
- Оновлено нотатки: PostgreSQL 18 як сервіс у stack'у проекту

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
sages-ds
2026-07-14 15:16:20 +03:00
parent 6b8989098a
commit b1e73cc2c0
15 changed files with 3070 additions and 8 deletions
+54
View File
@@ -0,0 +1,54 @@
-- Початкова схема ai_memory (див. нотатку "Модель даних")
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS projects (
id bigserial PRIMARY KEY,
name text NOT NULL UNIQUE,
summary text,
status text NOT NULL DEFAULT 'active',
metadata jsonb NOT NULL DEFAULT '{}',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS memories (
id bigserial PRIMARY KEY,
project_id bigint REFERENCES projects(id) ON DELETE CASCADE,
type text NOT NULL DEFAULT 'note',
title text NOT NULL,
content text NOT NULL DEFAULT '',
content_tsv tsvector GENERATED ALWAYS AS (
to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(content, ''))
) STORED,
embedding vector(1024),
metadata jsonb NOT NULL DEFAULT '{}',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS memories_tsv_idx ON memories USING gin (content_tsv);
CREATE INDEX IF NOT EXISTS memories_project_idx ON memories (project_id);
CREATE INDEX IF NOT EXISTS memories_type_idx ON memories (type);
CREATE TABLE IF NOT EXISTS memory_links (
source_id bigint NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
target_id bigint NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
link_type text NOT NULL DEFAULT 'related',
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (source_id, target_id, link_type)
);
CREATE INDEX IF NOT EXISTS memory_links_target_idx ON memory_links (target_id);
CREATE TABLE IF NOT EXISTS sessions (
id bigserial PRIMARY KEY,
project_id bigint NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
session_summary text,
todo_json jsonb NOT NULL DEFAULT '{"tasks": []}',
changes text,
bugs text,
architecture_notes text,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS sessions_project_idx ON sessions (project_id, created_at DESC);