morphik-core/init.sql

46 lines
1.4 KiB
MySQL
Raw Normal View History

2025-01-09 15:47:25 +05:30
-- Enable pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Create documents table
CREATE TABLE IF NOT EXISTS documents (
external_id VARCHAR PRIMARY KEY,
owner JSONB,
content_type VARCHAR,
filename VARCHAR,
doc_metadata JSONB DEFAULT '{}',
storage_info JSONB DEFAULT '{}',
system_metadata JSONB DEFAULT '{}',
additional_metadata JSONB DEFAULT '{}',
access_control JSONB DEFAULT '{}',
chunk_ids JSONB DEFAULT '[]'
);
-- Create indexes for documents table
CREATE INDEX IF NOT EXISTS idx_owner_id ON documents USING gin(owner);
CREATE INDEX IF NOT EXISTS idx_access_control ON documents USING gin(access_control);
CREATE INDEX IF NOT EXISTS idx_system_metadata ON documents USING gin(system_metadata);
-- Create vector_embeddings table
CREATE TABLE IF NOT EXISTS vector_embeddings (
id SERIAL PRIMARY KEY,
document_id VARCHAR(255),
chunk_number INTEGER,
content TEXT,
chunk_metadata TEXT,
embedding vector(768),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
-- Create caches table
CREATE TABLE IF NOT EXISTS caches (
name TEXT PRIMARY KEY,
metadata JSON NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
2025-01-09 15:47:25 +05:30
-- Create vector index
CREATE INDEX IF NOT EXISTS vector_idx
2025-01-09 15:47:25 +05:30
ON vector_embeddings USING ivfflat (embedding vector_l2_ops)
WITH (lists = 100);