# migrations

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
);


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: 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;


# embeddings_queue

created_at: 2025-07-09 22:14:55
topic: persistent://default/default/8bb05f79-83eb-4b94-acfc-0e97aae9eb04
id: ae9b095d-2e98-4bb3-bd59-9c1254b111ef
encoding: FLOAT32
metadata:
{"original_content": "Obesity that persists beyond early childhood makes weight loss in later life\nmore difficult. Drugs, including corticosteroids, lithium, traditional antidepressants (tricyclics, tetracyclics, and\nmonoamine oxidase inhibitors [MAOIs]), benzodiazepines, and antipsychotic drugs, often cause weight\ngain. Uncommonly, weight gain is caused by one of the following disorders:\nThe Merck Manual of Diagnosis & Therapy, 19th Edition Chapter 6.", "source": "Nutritional Medical Reference/Nutritional Disorders.pdf", "page": 55, "type": "text", "chroma:document": "1. How does early childhood obesity impact the likelihood of successful weight loss in adulthood?  \n2. What role do certain medications, such as antipsychotics and antidepressants, play in contributing to weight gain?  \n3. What are some uncommon disorders that can lead to weight gain, and how might they be related to nutritional imbalances?  "}


created_at: 2025-07-09 22:14:55
topic: persistent://default/default/8bb05f79-83eb-4b94-acfc-0e97aae9eb04
id: 637372bc-dcd5-4393-9d99-179eb7168ee5
encoding: FLOAT32
metadata:
{"original_content": "Obesity & the Metabolic Syndrome\n108", "source": "Nutritional Medical Reference/Nutritional Disorders.pdf", "page": 55, "type": "text", "chroma:document": "1. What dietary changes can help manage obesity and reduce the risk of developing metabolic syndrome?  \n2. How do specific nutrient deficiencies contribute to the progression of metabolic disorders associated with obesity?  \n3. What role do vitamins and minerals play in the prevention and management of obesity-related health conditions?  "}


created_at: 2025-07-09 22:14:57
topic: persistent://default/default/8bb05f79-83eb-4b94-acfc-0e97aae9eb04
id: 8d895b32-bea3-471d-85b7-eb039a5ddfbe
encoding: FLOAT32
metadata:
{"original_content": "[['Food', 'Glycemic Index'], ['Glucose', '100'], ['Sucrose', '65'], ['Starches', ''], ['Fiber', '']]", "source": "Nutritional Disorders.pdf", "page": 1, "type": "table", "chroma:document": "1. How does the glycemic index of sucrose compare to that of glucose in terms of potential impact on blood sugar levels for individuals with diabetes?  \n2. What role does the glycemic index of starches play in managing obesity and weight loss efforts?  \n3. How might a diet high in foods with a high glycemic index, like glucose, affect individuals with insulin resistance?  "}


created_at: 2025-07-09 22:14:57
topic: persistent://default/default/8bb05f79-83eb-4b94-acfc-0e97aae9eb04
id: 4b2f1c1a-6ac9-440c-8d29-4c437686f8b8
encoding: FLOAT32
metadata:
{"original_content": "[]", "source": "Nutritional Disorders.pdf", "page": 4, "type": "table", "chroma:document": "[]"}


created_at: 2025-07-09 22:14:57
topic: persistent://default/default/8bb05f79-83eb-4b94-acfc-0e97aae9eb04
id: 48407b44-f7a6-4618-aa3a-87f9ce7bc46d
encoding: FLOAT32
metadata:
{"original_content": "[['Inadequate absorption', 'Blind loop syndrome', 'Fish tapeworm infestation'], ['Chronic pancreatitis', 'Gastric surgery', 'Malabsorption syndromes'], ['AIDS', 'Use of certain drugs (eg, antacids, metformin)', 'Repeated exposure to nitrous oxide'], ['Genetic disorder causing malabsorption in the ileum (Imerslund-Graesbeck syndrome)', '', '']]", "source": "Nutritional Disorders.pdf", "page": 35, "type": "table", "chroma:document": "1. What are some causes of inadequate absorption of nutrients in the gastrointestinal tract?\n2. How can chronic pancreatitis affect nutrient absorption and lead to dietary deficiencies?\n3. What nutritional deficiencies might arise from genetic disorders such as Imerslund-Graesbeck syndrome?"}


created_at: 2025-07-09 22:14:57
topic: persistent://default/default/8bb05f79-83eb-4b94-acfc-0e97aae9eb04
id: 1761180e-00d1-4d25-8eb0-51fb9a3ac569
encoding: FLOAT32
metadata:
{"original_content": "[['Age Group', 'Prevalence'], ['20', 'Low'], ['55', 'High']]", "source": "Nutritional Disorders.pdf", "page": 56, "type": "table", "chroma:document": "1. How does the prevalence of nutritional disorders vary between younger adults aged 20 and older adults aged 55?\n2. What dietary deficiencies are more common in individuals aged 55 compared to those aged 20?\n3. Are older adults aged 55 at a higher risk for obesity-related health conditions than younger adults aged 20?"}


# embedding_metadata

key: original_content
string_value:
Obesity that persists beyond early childhood makes weight loss in later life
more difficult. Drugs, including corticosteroids, lithium, traditional antidepressants (tricyclics, tetracyclics, and
monoamine oxidase inhibitors [MAOIs]), benzodiazepines, and antipsychotic drugs, often cause weight
gain. Uncommonly, weight gain is caused by one of the following disorders:
The Merck Manual of Diagnosis & Therapy, 19th Edition Chapter 6.


key: chroma:document
string_value:
1. How does early childhood obesity impact the likelihood of successful weight loss in adulthood?  
2. What role do certain medications, such as antipsychotics and antidepressants, play in contributing to weight gain?  
3. What are some uncommon disorders that can lead to weight gain, and how might they be related to nutritional imbalances?  


key: chroma:document
string_value:
1. What dietary changes can help manage obesity and reduce the risk of developing metabolic syndrome?  
2. How do specific nutrient deficiencies contribute to the progression of metabolic disorders associated with obesity?  
3. What role do vitamins and minerals play in the prevention and management of obesity-related health conditions?  


key: original_content
string_value:
[['Food', 'Glycemic Index'], ['Glucose', '100'], ['Sucrose', '65'], ['Starches', ''], ['Fiber', '']]


key: chroma:document
string_value:
1. How does the glycemic index of sucrose compare to that of glucose in terms of potential impact on blood sugar levels for individuals with diabetes?  
2. What role does the glycemic index of starches play in managing obesity and weight loss efforts?  
3. How might a diet high in foods with a high glycemic index, like glucose, affect individuals with insulin resistance?  


key: original_content
string_value:
[['Inadequate absorption', 'Blind loop syndrome', 'Fish tapeworm infestation'], ['Chronic pancreatitis', 'Gastric surgery', 'Malabsorption syndromes'], ['AIDS', 'Use of certain drugs (eg, antacids, metformin)', 'Repeated exposure to nitrous oxide'], ['Genetic disorder causing malabsorption in the ileum (Imerslund-Graesbeck syndrome)', '', '']]


key: chroma:document
string_value:
1. What are some causes of inadequate absorption of nutrients in the gastrointestinal tract?
2. How can chronic pancreatitis affect nutrient absorption and lead to dietary deficiencies?
3. What nutritional deficiencies might arise from genetic disorders such as Imerslund-Graesbeck syndrome?


key: chroma:document
string_value:
1. How does the prevalence of nutritional disorders vary between younger adults aged 20 and older adults aged 55?
2. What dietary deficiencies are more common in individuals aged 55 compared to those aged 20?
3. Are older adults aged 55 at a higher risk for obesity-related health conditions than younger adults aged 20?


