-- =============================================================================
--  ai_rag_collection
--
--  A named RAG knowledge base. Each collection is a logical grouping of
--  text chunks + their embeddings. The Nibiru AI module's `Rag` plugin
--  reads / writes this table via the auto-generated model in
--  application/model/ai_rag_collection.php.
-- =============================================================================

CREATE TABLE IF NOT EXISTS ai_rag_collection (
    ai_rag_collection_id          INT(11) NOT NULL AUTO_INCREMENT,
    ai_rag_collection_name        VARCHAR(64)  NOT NULL,
    ai_rag_collection_embed_model VARCHAR(128) NOT NULL,
    ai_rag_collection_embed_dim   INT(11)      NOT NULL,
    ai_rag_collection_chunk_count INT(11)      NOT NULL DEFAULT 0,
    ai_rag_collection_created_at  TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ai_rag_collection_updated_at  TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (ai_rag_collection_id),
    UNIQUE KEY ai_rag_collection_name_uk (ai_rag_collection_name)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
