Changeset 0.21.2 (#88)
This commit is contained in:
58
server/database/migrations/011_v0212_workspace_chunks.sql
Normal file
58
server/database/migrations/011_v0212_workspace_chunks.sql
Normal file
@@ -0,0 +1,58 @@
|
||||
-- v0.21.2: Workspace indexing + semantic search
|
||||
--
|
||||
-- New: workspace_chunks table for text embeddings per workspace file
|
||||
-- Alter: workspace_files gains index_status and chunk_count columns
|
||||
-- Alter: workspaces gains indexing_enabled column
|
||||
|
||||
-- =========================================
|
||||
-- 1. workspace_files additions
|
||||
-- =========================================
|
||||
|
||||
ALTER TABLE workspace_files
|
||||
ADD COLUMN IF NOT EXISTS index_status VARCHAR(20) DEFAULT 'pending'
|
||||
CHECK (index_status IN ('pending', 'indexing', 'ready', 'error', 'skipped'));
|
||||
|
||||
ALTER TABLE workspace_files
|
||||
ADD COLUMN IF NOT EXISTS chunk_count INT NOT NULL DEFAULT 0;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspace_files_index_status
|
||||
ON workspace_files(workspace_id, index_status)
|
||||
WHERE index_status IN ('pending', 'indexing');
|
||||
|
||||
-- =========================================
|
||||
-- 2. workspaces addition
|
||||
-- =========================================
|
||||
|
||||
ALTER TABLE workspaces
|
||||
ADD COLUMN IF NOT EXISTS indexing_enabled BOOLEAN NOT NULL DEFAULT true;
|
||||
|
||||
-- =========================================
|
||||
-- 3. workspace_chunks table
|
||||
-- =========================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS workspace_chunks (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
workspace_id UUID NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
||||
file_id UUID NOT NULL REFERENCES workspace_files(id) ON DELETE CASCADE,
|
||||
chunk_index INT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
token_count INT NOT NULL DEFAULT 0,
|
||||
embedding vector(3072),
|
||||
metadata JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspace_chunks_file
|
||||
ON workspace_chunks(file_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspace_chunks_workspace
|
||||
ON workspace_chunks(workspace_id);
|
||||
|
||||
-- Note: No vector index created here. pgvector IVFFlat/HNSW indexes are
|
||||
-- limited to 2000 dimensions, but our embeddings are 3072-dim (zero-padded).
|
||||
-- Sequential scan with <=> is adequate at workspace scale (thousands of
|
||||
-- chunks, not millions). Add a partial/quantized index later if needed.
|
||||
|
||||
COMMENT ON TABLE workspace_chunks IS 'Text chunks with vector embeddings for workspace file semantic search';
|
||||
COMMENT ON COLUMN workspace_chunks.embedding IS 'Vector embedding (3072-dim, zero-padded) for cosine similarity';
|
||||
COMMENT ON COLUMN workspace_chunks.metadata IS 'Extensible: line_start, heading, language, etc.';
|
||||
@@ -0,0 +1,31 @@
|
||||
-- v0.21.2: Workspace indexing + semantic search (SQLite)
|
||||
|
||||
-- workspace_files additions
|
||||
ALTER TABLE workspace_files ADD COLUMN index_status TEXT DEFAULT 'pending';
|
||||
ALTER TABLE workspace_files ADD COLUMN chunk_count INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspace_files_index_status
|
||||
ON workspace_files(workspace_id, index_status);
|
||||
|
||||
-- workspaces addition
|
||||
ALTER TABLE workspaces ADD COLUMN indexing_enabled INTEGER NOT NULL DEFAULT 1;
|
||||
|
||||
-- workspace_chunks table
|
||||
-- Embeddings stored as JSON text for app-level cosine similarity.
|
||||
CREATE TABLE IF NOT EXISTS workspace_chunks (
|
||||
id TEXT PRIMARY KEY,
|
||||
workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
||||
file_id TEXT NOT NULL REFERENCES workspace_files(id) ON DELETE CASCADE,
|
||||
chunk_index INTEGER NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
token_count INTEGER NOT NULL DEFAULT 0,
|
||||
embedding TEXT, -- JSON array of floats
|
||||
metadata TEXT DEFAULT '{}', -- JSON object
|
||||
created_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspace_chunks_file
|
||||
ON workspace_chunks(file_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspace_chunks_workspace
|
||||
ON workspace_chunks(workspace_id);
|
||||
Reference in New Issue
Block a user