# migrations

dir: sysdb
filename: 00001-collections.sqlite.sql
hash: 38352d725ad1c16074fac420b22b4633
sql:
CREATE TABLE collections (
    id TEXT PRIMARY KEY,
    name TEXT NOT NULL,
    topic TEXT NOT NULL,
    UNIQUE (name)
);

CREATE TABLE collection_metadata (
    collection_id TEXT REFERENCES collections(id) ON DELETE CASCADE,
    key TEXT NOT NULL,
    str_value TEXT,
    int_value INTEGER,
    float_value REAL,
    PRIMARY KEY (collection_id, key)
);


dir: sysdb
filename: 00002-segments.sqlite.sql
hash: 2913cb6a503055a95f625448037e8912
sql:
CREATE TABLE segments (
    id TEXT PRIMARY KEY,
    type TEXT NOT NULL,
    scope TEXT NOT NULL,
    topic TEXT,
    collection TEXT REFERENCES collection(id)
);

CREATE TABLE segment_metadata (
    segment_id TEXT  REFERENCES segments(id) ON DELETE CASCADE,
    key TEXT NOT NULL,
    str_value TEXT,
    int_value INTEGER,
    float_value REAL,
    PRIMARY KEY (segment_id, key)
);


dir: sysdb
filename: 00004-tenants-databases.sqlite.sql
hash: 048867ce8fcdefe4023c7110e4433591
sql:
CREATE TABLE IF NOT EXISTS tenants (
    id TEXT PRIMARY KEY,
    UNIQUE (id)
);

CREATE TABLE IF NOT EXISTS databases (
    id TEXT PRIMARY KEY, -- unique globally
    name TEXT NOT NULL, -- unique per tenant
    tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
    UNIQUE (tenant_id, name) -- Ensure that a tenant has only one database with a given name
);

CREATE TABLE IF NOT EXISTS collections_tmp (
    id TEXT PRIMARY KEY, -- unique globally
    name TEXT NOT NULL, -- unique per database
    topic TEXT NOT NULL,
    dimension INTEGER,
    database_id TEXT NOT NULL REFERENCES databases(id) ON DELETE CASCADE,
    UNIQUE (name, database_id)
);

-- Create default tenant and database
INSERT OR REPLACE INTO tenants (id) VALUES ('default_tenant'); -- The default tenant id is 'default_tenant' others are UUIDs
INSERT OR REPLACE INTO databases (id, name, tenant_id) VALUES ('00000000-0000-0000-0000-000000000000', 'default_database', 'default_tenant');

INSERT OR REPLACE INTO collections_tmp (id, name, topic, dimension, database_id)
    SELECT id, name, topic, dimension, '00000000-0000-0000-0000-000000000000' FROM collections;
DROP TABLE collections;
ALTER TABLE collections_tmp RENAME TO collections;


dir: sysdb
filename: 00005-remove-topic.sqlite.sql
hash: b1367c826b8fba5f96f27befdc1d42d2
sql:
-- Remove the topic column from the Collections and Segments tables

ALTER TABLE collections DROP COLUMN topic;
ALTER TABLE segments DROP COLUMN topic;


dir: sysdb
filename: 00006-collection-segment-metadata.sqlite.sql
hash: 4eea7468935bf25d4604a0fed2366116
sql:
-- SQLite does not support adding check with alter table, as a result, adding a check
-- involve creating a new table and copying the data over. It is over kill with adding
-- a boolean type column. The application write to the table needs to ensure the data
-- integrity.
ALTER TABLE collection_metadata ADD COLUMN bool_value INTEGER;
ALTER TABLE segment_metadata ADD COLUMN bool_value INTEGER;


dir: sysdb
filename: 00007-collection-config.sqlite.sql
hash: 1c7e63bba346a42a18b6ab7f1c989bed
sql:
-- Stores collection configuration dictionaries.
ALTER TABLE collections ADD COLUMN config_json_str TEXT;


dir: sysdb
filename: 00008-maintenance-log.sqlite.sql
hash: 0a0e7e93111a01789addf64961c6127c
sql:
-- Records when database maintenance operations are performed.
-- At time of creation, this table is only used to record vacuum operations.
CREATE TABLE maintenance_log (
  id INT PRIMARY KEY,
  timestamp INT NOT NULL,
  operation TEXT NOT NULL
);


dir: sysdb
filename: 00009-segment-collection-not-null.sqlite.sql
hash: 054355aef9e63702bf54ea29e61563f1
sql:
-- This makes segments.collection non-nullable.
CREATE TABLE segments_temp (
    id TEXT PRIMARY KEY,
    type TEXT NOT NULL,
    scope TEXT NOT NULL,
    collection TEXT REFERENCES collection(id) NOT NULL
);

INSERT INTO segments_temp SELECT * FROM segments;
DROP TABLE segments;
ALTER TABLE segments_temp RENAME TO segments;


dir: sysdb
filename: 00010-collection-schema.sqlite.sql
hash: 5c3a5ac4b79df76799b4721827ed5e1d
sql:
-- Stores collection schema as stringified json
ALTER TABLE collections ADD COLUMN schema_str TEXT;


dir: metadb
filename: 00001-embedding-metadata.sqlite.sql
hash: 2b4cf52c4bb2676e21d6860a4409f856
sql:
CREATE TABLE embeddings (
    id INTEGER PRIMARY KEY,
    segment_id TEXT NOT NULL,
    embedding_id TEXT NOT NULL,
    seq_id BLOB NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE (segment_id, embedding_id)
);

CREATE TABLE embedding_metadata (
    id INTEGER REFERENCES embeddings(id),
    key TEXT NOT NULL,
    string_value TEXT,
    int_value INTEGER,
    float_value REAL,
    PRIMARY KEY (id, key)
);

CREATE TABLE max_seq_id (
    segment_id TEXT PRIMARY KEY,
    seq_id BLOB NOT NULL
);

CREATE VIRTUAL TABLE embedding_fulltext USING fts5(id, string_value);


dir: metadb
filename: 00002-embedding-metadata.sqlite.sql
hash: 12a570f7121b3a8ce750a2a7c36da20f
sql:
-- SQLite does not support adding check with alter table, as a result, adding a check
-- involve creating a new table and copying the data over. It is over kill with adding
-- a boolean type column. The application write to the table needs to ensure the data
-- integrity.
ALTER TABLE embedding_metadata ADD COLUMN bool_value INTEGER


dir: metadb
filename: 00003-full-text-tokenize.sqlite.sql
hash: f97ad6334aeaa8f419f01110b648b97a
sql:
CREATE VIRTUAL TABLE embedding_fulltext_search USING fts5(string_value, tokenize='trigram');
INSERT INTO embedding_fulltext_search (rowid, string_value) SELECT rowid, string_value FROM embedding_metadata;
DROP TABLE embedding_fulltext;


dir: metadb
filename: 00004-metadata-indices.sqlite.sql
hash: fb36603a45ee2cd0254cef3ef86585e8
sql:
CREATE INDEX IF NOT EXISTS embedding_metadata_int_value ON embedding_metadata (key, int_value) WHERE int_value IS NOT NULL;
CREATE INDEX IF NOT EXISTS embedding_metadata_float_value ON embedding_metadata (key, float_value) WHERE float_value IS NOT NULL;
CREATE INDEX IF NOT EXISTS embedding_metadata_string_value ON embedding_metadata (key, string_value) WHERE string_value IS NOT NULL;


dir: metadb
filename: 00005-max-seq-id-int.sqlite.sql
hash: 0e9de46758761b373ce682925edcc326
sql:
ALTER TABLE max_seq_id ADD COLUMN int_seq_id INTEGER;

-- Convert 8 byte wide big-endian integer as blob to native 64 bit integer.
-- Adapted from https://stackoverflow.com/a/70296198.
UPDATE max_seq_id SET int_seq_id = (
  SELECT (
       (instr('123456789ABCDEF', substr(hex(seq_id), -1 , 1)) <<  0)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -2 , 1)) <<  4)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -3 , 1)) <<  8)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -4 , 1)) << 12)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -5 , 1)) << 16)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -6 , 1)) << 20)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -7 , 1)) << 24)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -8 , 1)) << 28)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -9 , 1)) << 32)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -10, 1)) << 36)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -11, 1)) << 40)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -12, 1)) << 44)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -13, 1)) << 48)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -14, 1)) << 52)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -15, 1)) << 56)
     | (instr('123456789ABCDEF', substr(hex(seq_id), -16, 1)) << 60)
    )
);

ALTER TABLE max_seq_id DROP COLUMN seq_id;
ALTER TABLE max_seq_id RENAME COLUMN int_seq_id TO seq_id;


dir: embeddings_queue
filename: 00001-embeddings.sqlite.sql
hash: d3755dfd232be8e8301f4d7fcfb3a486
sql:
CREATE TABLE embeddings_queue (
    seq_id INTEGER PRIMARY KEY,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    operation INTEGER NOT NULL,
    topic TEXT NOT NULL,
    id TEXT NOT NULL,
    vector BLOB,
    encoding TEXT,
    metadata TEXT
);


# collections

id: 4b5801dc-a563-45bf-a0a0-c7fec5f50c25
name: langchain
database_id: 00000000-0000-0000-0000-000000000000
config_json_str: {}
schema_str:
{"defaults":{"string":{"fts_index":{"enabled":false,"config":{}},"string_inverted_index":{"enabled":true,"config":{}}},"float_list":{"vector_index":{"enabled":false,"config":{"space":"l2","hnsw":{"ef_construction":100,"max_neighbors":16,"ef_search":100,"num_threads":10,"batch_size":100,"sync_threshold":1000,"resize_factor":1.2}}}},"sparse_vector":{"sparse_vector_index":{"enabled":false,"config":{"embedding_function":{"type":"unknown"},"bm25":false}}},"int":{"int_inverted_index":{"enabled":true,"config":{}}},"float":{"float_inverted_index":{"enabled":true,"config":{}}},"bool":{"bool_inverted_index":{"enabled":true,"config":{}}}},"keys":{"document_id":{"string":{"fts_index":{"enabled":false,"config":{}},"string_inverted_index":{"enabled":true,"config":{}}}},"#embedding":{"float_list":{"vector_index":{"enabled":true,"config":{"space":"l2","source_key":"#document","hnsw":{"ef_construction":100,"max_neighbors":16,"ef_search":100,"num_threads":10,"batch_size":100,"sync_threshold":1000,"resize_factor":1.2}}}}},"chunk_id":{"string":{"fts_index":{"enabled":false,"config":{}},"string_inverted_index":{"enabled":true,"config":{}}}},"chunk_index":{"int":{"int_inverted_index":{"enabled":true,"config":{}}}},"knowledge_base_id":{"int":{"int_inverted_index":{"enabled":true,"config":{}}}},"#document":{"string":{"fts_index":{"enabled":true,"config":{}},"string_inverted_index":{"enabled":false,"config":{}}}},"source":{"string":{"fts_index":{"enabled":false,"config":{}},"string_inverted_index":{"enabled":true,"config":{}}}}}}


# embedding_metadata

key: source
string_value:
/Users/eason/Desktop/work/hyf-backend/data/uploads/kb_2/4ec6cba6-737f-4e6e-b1f3-261d393eef4a_knowledge.txt


key: chroma:document
string_value:
低空飞行相关文档涵盖政策法规、技术规范等多种类型，以下是一些重要文档介绍：
《无人驾驶航空器飞行管理暂行条例》：由国务院、中央军委于 2023 年发布，自 2024 年 1 月 1 日起施行。该条例对无人驾驶航空器飞行以及有关活动进行了规范，明确了无人驾驶航空器的定义、分类，规定了民用无人驾驶航空器及操控员管理要求，包括适航许可、实名登记、运营合格证等相关内容，是低空飞行管理的重要政策性文件。
《国家空域基础分类方法》：中国民用航空局 2023 年 12 月发布，依据航空器飞行规则和性能要求等要素，将空域划分为 A、B、C、D、E、G、W 等 7 类。首次明确提出我国 G、W 类非管制空域，将真高 120 米以下部分空域划设为 W 类空域，为低空飞行空域管理提供了依据。
《国家级和省、市级低空飞行综合监管服务平台功能要求 (1.0 版)》《国家级和省、市级低空飞行综合监管服务平台信息交互规范 (1.0 版)》：由中央空管办制定出台，对低空管理系统建设加强规范，推动低空管理系统建设向 “规范有序、安全可控” 的高质量发展新阶段转变。


# embeddings_queue

created_at: 2026-01-22 08:13:10
topic: persistent://default/default/4b5801dc-a563-45bf-a0a0-c7fec5f50c25
id: a24e35aa-f7ad-402b-b9db-7b207e8b43b7
encoding: FLOAT32
metadata:
{"source":"/Users/eason/Desktop/work/hyf-backend/data/uploads/kb_2/65ba1b6c-96ee-4061-88c6-095b73deeec8_test_document.txt","document_id":"3","chroma:document":"这是一个测试文档。\n\n用于测试文档处理和向量化功能。\n\n文档内容包含多个段落，用于测试文档分割功能。\n\n每个段落都会被分割成不同的文档块（chunks）。\n\n这些文档块会被向量化并存储到向量数据库中。\n\n然后可以通过向量搜索找到相关的文档内容。","chunk_index":0,"knowledge_base_id":2,"chunk_id":"2_3_0"}


created_at: 2026-01-22 08:17:53
topic: persistent://default/default/4b5801dc-a563-45bf-a0a0-c7fec5f50c25
id: 7e9fe5d1-b303-44d3-a543-3aae70c45153
encoding: FLOAT32
metadata:
{"source":"/Users/eason/Desktop/work/hyf-backend/data/uploads/kb_2/4ec6cba6-737f-4e6e-b1f3-261d393eef4a_knowledge.txt","chunk_index":0,"knowledge_base_id":2,"document_id":"4","chunk_id":"2_4_0","chroma:document":"低空飞行相关文档涵盖政策法规、技术规范等多种类型，以下是一些重要文档介绍：\n《无人驾驶航空器飞行管理暂行条例》：由国务院、中央军委于 2023 年发布，自 2024 年 1 月 1 日起施行。该条例对无人驾驶航空器飞行以及有关活动进行了规范，明确了无人驾驶航空器的定义、分类，规定了民用无人驾驶航空器及操控员管理要求，包括适航许可、实名登记、运营合格证等相关内容，是低空飞行管理的重要政策性文件。\n《国家空域基础分类方法》：中国民用航空局 2023 年 12 月发布，依据航空器飞行规则和性能要求等要素，将空域划分为 A、B、C、D、E、G、W 等 7 类。首次明确提出我国 G、W 类非管制空域，将真高 120 米以下部分空域划设为 W 类空域，为低空飞行空域管理提供了依据。\n《国家级和省、市级低空飞行综合监管服务平台功能要求 (1.0 版)》《国家级和省、市级低空飞行综合监管服务平台信息交互规范 (1.0 版)》：由中央空管办制定出台，对低空管理系统建设加强规范，推动低空管理系统建设向 “规范有序、安全可控” 的高质量发展新阶段转变。"}


