Skip to main content
Glama
init-db.sql3.45 kB
-- Инициализация базы данных AI Ops Hub -- Создание таблиц для RAG системы -- Таблица документов CREATE TABLE IF NOT EXISTS docs ( id INTEGER PRIMARY KEY AUTOINCREMENT, uri TEXT UNIQUE NOT NULL, title TEXT NOT NULL, mtime INTEGER NOT NULL, hash TEXT NOT NULL, metadata TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP ); -- Таблица чанков CREATE TABLE IF NOT EXISTS chunks ( id INTEGER PRIMARY KEY AUTOINCREMENT, doc_id INTEGER NOT NULL, text TEXT NOT NULL, section TEXT, offset INTEGER NOT NULL, lang TEXT, hash TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (doc_id) REFERENCES docs(id) ON DELETE CASCADE ); -- FTS5 индекс для полнотекстового поиска CREATE VIRTUAL TABLE IF NOT EXISTS chunks_fts USING fts5( text, section, content='chunks', content_rowid='id' ); -- Триггер для автоматического обновления FTS CREATE TRIGGER IF NOT EXISTS chunks_ai AFTER INSERT ON chunks BEGIN INSERT INTO chunks_fts(rowid, text, section) VALUES (new.id, new.text, new.section); END; CREATE TRIGGER IF NOT EXISTS chunks_ad AFTER DELETE ON chunks BEGIN INSERT INTO chunks_fts(chunks_fts, rowid, text, section) VALUES('delete', old.id, old.text, old.section); END; CREATE TRIGGER IF NOT EXISTS chunks_au AFTER UPDATE ON chunks BEGIN INSERT INTO chunks_fts(chunks_fts, rowid, text, section) VALUES('delete', old.id, old.text, old.section); INSERT INTO chunks_fts(rowid, text, section) VALUES (new.id, new.text, new.section); END; -- Таблица для векторных эмбеддингов CREATE TABLE IF NOT EXISTS chunk_vecs ( chunk_id INTEGER PRIMARY KEY, dim INTEGER NOT NULL, vec BLOB NOT NULL, model TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (chunk_id) REFERENCES chunks(id) ON DELETE CASCADE ); -- Индекс для быстрого поиска по модели CREATE INDEX IF NOT EXISTS idx_chunk_vecs_model ON chunk_vecs(model); -- Таблица аудита вызовов CREATE TABLE IF NOT EXISTS calls ( run_id TEXT PRIMARY KEY, ts DATETIME DEFAULT CURRENT_TIMESTAMP, actor TEXT NOT NULL, tool TEXT NOT NULL, input TEXT, output TEXT, status TEXT NOT NULL ); -- Таблица задач CREATE TABLE IF NOT EXISTS tasks ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, project TEXT, due TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, completed_at DATETIME ); -- Индексы для производительности CREATE INDEX IF NOT EXISTS idx_docs_uri ON docs(uri); CREATE INDEX IF NOT EXISTS idx_chunks_doc_id ON chunks(doc_id); CREATE INDEX IF NOT EXISTS idx_chunks_hash ON chunks(hash); CREATE INDEX IF NOT EXISTS idx_calls_ts ON calls(ts); CREATE INDEX IF NOT EXISTS idx_tasks_project ON tasks(project); CREATE INDEX IF NOT EXISTS idx_tasks_due ON tasks(due); -- Вставка тестовых данных INSERT OR IGNORE INTO docs (uri, title, mtime, hash) VALUES ('file:///test/readme.md', 'Test README', strftime('%s', 'now'), 'test-hash-1'); INSERT OR IGNORE INTO chunks (doc_id, text, section, offset, lang, hash) VALUES (1, 'This is a test document for AI Ops Hub.', 'main', 0, 'en', 'chunk-hash-1');

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Galiusbro/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server