UNPKG

mcard-js

Version:

MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers

7 lines 26.4 kB
/** * AUTO-GENERATED FILE - DO NOT EDIT * Generated by scripts/sync-schemas.js */ export declare const MCARD_SCHEMA_SQL = "-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- MCard Unified Database Schema (Monadic Core)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- \n-- STABILITY WARNING: This schema is the invariant \"seeding meta-language\" for all\n-- Domain Specific Languages (DSLs). It must remain as stable as possible.\n--\n-- THE UNIFICATION THESIS:\n-- This design unites three distinct namespaces into a single relational network\n-- by leveraging the power of cryptographic hash functions:\n-- 1. CONTENT SPACE (Intrinsic Identity): Content-Addressable Storage (CAS).\n-- 2. HANDLE SPACE (Reserved Words): Mapping human logic to content hashes.\n-- 3. VERSION SPACE (Temporal Evolution): Tracking state transitions via hash history.\n--\n-- TURING MACHINE ANALOGY (The Infinitely Long Tape):\n-- The `card` table stores content blobs with unique identities, emulating the \n-- \"Infinitely Long Tape\" of the Turing Machine formalism. By using relational \n-- queries, this tape can be dynamically constructed and traversed for different \n-- DSLs, providing a flexible substrate for practically all computable languages.\n--\n-- By using hash values as the universal primitives across content, handles, and \n-- time, we create a \"Wordless Book\" \u2014 a minimal substrate capable of seeding any \n-- domain-specific knowledge system without requiring schema changes.\n--\n-- Monadic Mapping (See: Monadic Justification for Schema Design.md):\n-- 1. Card = Monad (Perception/State/Exponent) - Intrinsic Identity\n-- 2. Handle = Registry (Appetition/Reader/Sum) - Mutable Reference\n-- 3. Version = History (Harmony/Writer/Product) - Coordinated Evolution\n--\n-- Version: 3.0.2 (Turing Tape Refinement)\n-- Last Updated: 2025-12-20\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- LAYER 1: CORE CONTENT-ADDRESSABLE STORAGE (The Monad / Exponent)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- The fundamental MCard storage: content-addressed by cryptographic hash.\n-- \"Each Monad ... mirrors the universe\"\n\n-- @table card\n-- @description Core content-addressable storage table (Monad/State)\n-- @column hash - SHA-256 hash of content (primary key)\n-- @column content - The actual content (BLOB for binary safety)\n-- @column g_time - Generation timestamp (ISO 8601)\nCREATE TABLE IF NOT EXISTS card (\n hash TEXT PRIMARY KEY,\n content BLOB NOT NULL,\n g_time TEXT NOT NULL\n);\n\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- LAYER 2: HANDLE SYSTEM (Appetition / Sum)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- The mutable pointer that \"desires\" to reference new content.\n-- \"Appetition: the tendency to move to new states\"\n\n-- @table handle_registry (Monadic Role: Handle)\n-- @description Maps human-readable handles to current content hashes\n-- @column handle - UTF-8 handle name (primary key)\n-- @column current_hash - FK to card.hash of current version\n-- @column created_at - When handle was first created\n-- @column updated_at - When handle was last updated\nCREATE TABLE IF NOT EXISTS handle_registry (\n handle TEXT PRIMARY KEY,\n current_hash TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n FOREIGN KEY (current_hash) REFERENCES card(hash)\n);\n\n-- @index idx_handle_current_hash\n-- @description Efficient reverse lookup from hash to handles\nCREATE INDEX IF NOT EXISTS idx_handle_current_hash \nON handle_registry(current_hash);\n\n-- @table handle_history (Monadic Role: Version / Product)\n-- @description Audit trail for handle pointer changes (Pre-Established Harmony)\n-- @column id - Auto-increment primary key\n-- @column handle - The handle that was updated\n-- @column previous_hash - Hash it pointed to before update\n-- @column changed_at - When the change occurred\nCREATE TABLE IF NOT EXISTS handle_history (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n handle TEXT NOT NULL,\n previous_hash TEXT NOT NULL,\n changed_at TEXT NOT NULL,\n FOREIGN KEY (handle) REFERENCES handle_registry(handle),\n FOREIGN KEY (previous_hash) REFERENCES card(hash)\n);\n\n-- @index idx_handle_history_handle\n-- @description Efficient lookup of history by handle\nCREATE INDEX IF NOT EXISTS idx_handle_history_handle \nON handle_history(handle);\n\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- LEGACY SUPPORT: FTS5 Documents Table\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- KEPT FOR BACKWARD COMPATIBILITY with existing codebase.\n-- New implementations should use mcard_vector_schema.sql -> mcard_fts\n\n-- @virtual_table documents\n-- @description Legacy FTS table for backward compatibility\n-- @note Synced with card table via triggers\nCREATE VIRTUAL TABLE IF NOT EXISTS documents USING fts5(content);\n\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- SCHEMA METADATA\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n-- @table schema_version\n-- @description Tracks schema version for migrations\nCREATE TABLE IF NOT EXISTS schema_version (\n version TEXT PRIMARY KEY,\n applied_at TEXT NOT NULL,\n description TEXT\n);\n\n-- Insert current schema version\nINSERT OR IGNORE INTO schema_version (version, applied_at, description)\nVALUES ('3.0.0', datetime('now'), 'Monadic Core Schema (split vectors to mcard_vector_schema.sql)');\n"; export declare const MCARD_VECTOR_SCHEMA_SQL = "-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- MCard Vector Database Schema (mcard_vectors.db)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- \n-- This schema defines the structure for \"Secondary Qualities\" (Extrinsic Embeddings).\n-- It is separated from the core mcard.db (Monadic Intrinsic Properties) to ensure:\n-- 1. Separation of Concerns (Intrinsic vs Extrinsic)\n-- 2. Linearity (Vectors are observer-dependent and large)\n-- 3. Upgradability (Embedding models change frequently)\n--\n-- See: Monadic Justification for Schema Design.md\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- LAYER 3: VECTOR STORAGE (Semantic Embeddings)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- Storage for vector embeddings enabling semantic search.\n-- Links to content via hash for content-addressing.\n\n-- @table mcard_vector_metadata\n-- @description Metadata for stored embeddings\n-- @column id - Auto-increment primary key\n-- @column hash - FK to card.hash\n-- @column model_name - Embedding model used (e.g., \"nomic-embed-text\")\n-- @column dimensions - Vector dimensions\n-- @column chunk_index - Index for chunked documents (0 = first/whole)\n-- @column chunk_total - Total chunks for this document\n-- @column chunk_text - Preview text for this chunk\n-- @column created_at - When embedding was created\nCREATE TABLE IF NOT EXISTS mcard_vector_metadata (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n hash TEXT NOT NULL,\n model_name TEXT NOT NULL,\n dimensions INTEGER NOT NULL,\n chunk_index INTEGER DEFAULT 0,\n chunk_total INTEGER DEFAULT 1,\n chunk_text TEXT,\n created_at TEXT NOT NULL,\n UNIQUE(hash, chunk_index)\n);\n\n-- @index idx_vector_metadata_hash\n-- @description Efficient lookup of embeddings by content hash\nCREATE INDEX IF NOT EXISTS idx_vector_metadata_hash \nON mcard_vector_metadata(hash);\n\n-- @table mcard_embeddings\n-- @description Fallback embedding storage when sqlite-vec is unavailable\n-- @column id - Auto-increment primary key\n-- @column metadata_id - FK to mcard_vector_metadata.id\n-- @column embedding - Serialized float32 vector as BLOB\nCREATE TABLE IF NOT EXISTS mcard_embeddings (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n metadata_id INTEGER NOT NULL,\n embedding BLOB NOT NULL,\n UNIQUE(metadata_id),\n FOREIGN KEY (metadata_id) REFERENCES mcard_vector_metadata(id)\n);\n\n-- @virtual_table mcard_fts\n-- @description Full-text search for hybrid retrieval\n-- @note Uses Porter stemming with Unicode support\nCREATE VIRTUAL TABLE IF NOT EXISTS mcard_fts USING fts5(\n hash,\n content,\n tokenize='porter unicode61'\n);\n\n-- Note: sqlite-vec virtual table is created dynamically with dimensions:\n-- CREATE VIRTUAL TABLE IF NOT EXISTS mcard_vec USING vec0(\n-- metadata_id INTEGER PRIMARY KEY,\n-- embedding float[${dimensions}]\n-- );\n\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- LAYER 4: SEMANTIC VERSIONING (Handle-Vector Bridge)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- Bridges handles to vector embeddings for semantic version comparison.\n-- Enables measuring semantic drift between document versions.\n\n-- @table handle_version_vectors\n-- @description Links handle versions to their semantic embeddings\n-- @column id - Auto-increment primary key\n-- @column handle - FK to handle_registry.handle\n-- @column hash - FK to card.hash (this version)\n-- @column parent_hash - FK to card.hash (previous version)\n-- @column version_order - 0 = current, 1 = previous, etc.\n-- @column is_current - TRUE if this is the current version\n-- @column embedding_id - FK to mcard_vector_metadata.id\n-- @column semantic_delta_from_parent - Cosine similarity to parent [-1, 1]\n-- @column upgrade_type - Classification: 'trivial' | 'minor' | 'major' | 'breaking'\n-- @column created_at - When this version was linked\nCREATE TABLE IF NOT EXISTS handle_version_vectors (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n handle TEXT NOT NULL,\n hash TEXT NOT NULL,\n parent_hash TEXT,\n version_order INTEGER NOT NULL,\n is_current BOOLEAN DEFAULT FALSE,\n embedding_id INTEGER,\n semantic_delta_from_parent REAL,\n upgrade_type TEXT,\n created_at TEXT NOT NULL,\n UNIQUE(handle, hash),\n FOREIGN KEY (embedding_id) REFERENCES mcard_vector_metadata(id)\n);\n\n-- @index idx_hvv_handle\n-- @description Efficient lookup of versions by handle\nCREATE INDEX IF NOT EXISTS idx_hvv_handle \nON handle_version_vectors(handle);\n\n-- @index idx_hvv_hash\n-- @description Efficient lookup of versions by hash\nCREATE INDEX IF NOT EXISTS idx_hvv_hash \nON handle_version_vectors(hash);\n\n-- @index idx_hvv_current\n-- @description Efficient lookup of current versions\nCREATE INDEX IF NOT EXISTS idx_hvv_current \nON handle_version_vectors(is_current);\n\n-- @index idx_hvv_parent\n-- @description Efficient lookup by parent hash\nCREATE INDEX IF NOT EXISTS idx_hvv_parent \nON handle_version_vectors(parent_hash);\n\n-- @table version_similarity_cache\n-- @description Precomputed pairwise similarities for performance\n-- @column id - Auto-increment primary key\n-- @column handle - Handle these versions belong to\n-- @column hash_a - First version hash\n-- @column hash_b - Second version hash\n-- @column similarity_score - Cosine similarity [-1, 1]\n-- @column distance_euclidean - L2 distance [0, \u221E)\n-- @column computed_at - When similarity was computed\nCREATE TABLE IF NOT EXISTS version_similarity_cache (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n handle TEXT NOT NULL,\n hash_a TEXT NOT NULL,\n hash_b TEXT NOT NULL,\n similarity_score REAL NOT NULL,\n distance_euclidean REAL,\n computed_at TEXT NOT NULL,\n UNIQUE(handle, hash_a, hash_b)\n);\n\n-- @index idx_vsc_handle\n-- @description Efficient lookup of cached similarities by handle\nCREATE INDEX IF NOT EXISTS idx_vsc_handle \nON version_similarity_cache(handle);\n\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- LAYER 5: KNOWLEDGE GRAPH (GraphRAG)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- Storage for extracted knowledge graph entities and relationships.\n\n-- @table graph_entities\n-- @description Nodes in the knowledge graph\n-- @column id - Auto-increment primary key\n-- @column name - Entity name\n-- @column type - Entity type (e.g., \"Person\", \"Organization\")\n-- @column description - Optional description\n-- @column source_hash - FK to card.hash where entity was extracted\n-- @column embedding - Optional entity embedding\n-- @column created_at - When entity was created\nCREATE TABLE IF NOT EXISTS graph_entities (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL,\n type TEXT NOT NULL,\n description TEXT,\n source_hash TEXT NOT NULL,\n embedding BLOB,\n created_at TEXT NOT NULL,\n UNIQUE(name, type, source_hash)\n);\n\n-- @index idx_entity_name\n-- @description Efficient entity lookup by name\nCREATE INDEX IF NOT EXISTS idx_entity_name \nON graph_entities(name);\n\n-- @index idx_entity_type\n-- @description Efficient entity lookup by type\nCREATE INDEX IF NOT EXISTS idx_entity_type \nON graph_entities(type);\n\n-- @index idx_entity_source\n-- @description Efficient entity lookup by source document\nCREATE INDEX IF NOT EXISTS idx_entity_source \nON graph_entities(source_hash);\n\n-- @table graph_relationships\n-- @description Edges in the knowledge graph\n-- @column id - Auto-increment primary key\n-- @column source_entity_id - FK to graph_entities.id (from)\n-- @column target_entity_id - FK to graph_entities.id (to)\n-- @column relationship - Relationship type/label\n-- @column description - Optional description\n-- @column weight - Relationship strength\n-- @column source_hash - FK to card.hash where relationship was extracted\n-- @column created_at - When relationship was created\nCREATE TABLE IF NOT EXISTS graph_relationships (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n source_entity_id INTEGER NOT NULL,\n target_entity_id INTEGER NOT NULL,\n relationship TEXT NOT NULL,\n description TEXT,\n weight REAL DEFAULT 1.0,\n source_hash TEXT NOT NULL,\n created_at TEXT NOT NULL,\n UNIQUE(source_entity_id, target_entity_id, relationship, source_hash),\n FOREIGN KEY (source_entity_id) REFERENCES graph_entities(id),\n FOREIGN KEY (target_entity_id) REFERENCES graph_entities(id)\n);\n\n-- @index idx_rel_source\n-- @description Efficient lookup of relationships by source entity\nCREATE INDEX IF NOT EXISTS idx_rel_source \nON graph_relationships(source_entity_id);\n\n-- @index idx_rel_target\n-- @description Efficient lookup of relationships by target entity\nCREATE INDEX IF NOT EXISTS idx_rel_target \nON graph_relationships(target_entity_id);\n\n-- @table graph_communities\n-- @description Hierarchical community summaries (GraphRAG)\n-- @column id - Auto-increment primary key\n-- @column level - Hierarchy level (0 = leaf)\n-- @column title - Community title\n-- @column summary - AI-generated summary\n-- @column embedding - Community embedding\n-- @column member_entity_ids - JSON array of entity IDs\n-- @column parent_community_id - FK to parent community\n-- @column created_at - When community was created\nCREATE TABLE IF NOT EXISTS graph_communities (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n level INTEGER NOT NULL DEFAULT 0,\n title TEXT,\n summary TEXT NOT NULL,\n embedding BLOB,\n member_entity_ids TEXT,\n parent_community_id INTEGER,\n created_at TEXT NOT NULL,\n FOREIGN KEY (parent_community_id) REFERENCES graph_communities(id)\n);\n\n-- @index idx_community_level\n-- @description Efficient lookup of communities by level\nCREATE INDEX IF NOT EXISTS idx_community_level \nON graph_communities(level);\n\n-- @table graph_extractions\n-- @description Tracks which documents have been processed for entity extraction\n-- @column hash - FK to card.hash (primary key)\n-- @column entity_count - Number of entities extracted\n-- @column relationship_count - Number of relationships extracted\n-- @column extracted_at - When extraction was performed\nCREATE TABLE IF NOT EXISTS graph_extractions (\n hash TEXT PRIMARY KEY,\n entity_count INTEGER DEFAULT 0,\n relationship_count INTEGER DEFAULT 0,\n extracted_at TEXT NOT NULL\n);\n\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n-- SCHEMA METADATA (Vector DB)\n-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n-- @table schema_version\n-- @description Tracks schema version for migrations\nCREATE TABLE IF NOT EXISTS vector_schema_version (\n version TEXT PRIMARY KEY,\n applied_at TEXT NOT NULL,\n description TEXT\n);\n\n-- Insert current schema version\nINSERT OR IGNORE INTO vector_schema_version (version, applied_at, description)\nVALUES ('1.0.0', datetime('now'), 'Initial MCard Vector Schema');\n"; //# sourceMappingURL=schema_constants.d.ts.map