mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 04:16:17 +01:00 
			
		
		
		
	update schema with our new tables
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
				
			|||||||
-- Add tables for vector embeddings storage and management
 | 
					-- Add tables for vector embeddings storage and management
 | 
				
			||||||
 | 
					-- This migration adds embedding support to the main document.db database
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Store embeddings for notes
 | 
					-- Store embeddings for notes
 | 
				
			||||||
CREATE TABLE IF NOT EXISTS "note_embeddings" (
 | 
					CREATE TABLE IF NOT EXISTS "note_embeddings" (
 | 
				
			||||||
@@ -44,7 +45,11 @@ CREATE TABLE IF NOT EXISTS "embedding_providers" (
 | 
				
			|||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Add default embedding provider options
 | 
					-- Add default embedding provider options
 | 
				
			||||||
INSERT INTO options (name, value, isSynced) VALUES ('embeddingAutoUpdateEnabled', 'true', 1);
 | 
					INSERT INTO options (name, value, isSynced, utcDateModified) 
 | 
				
			||||||
INSERT INTO options (name, value, isSynced) VALUES ('embeddingUpdateInterval', '5000', 1); -- 5 seconds
 | 
					VALUES ('embeddingAutoUpdateEnabled', 'true', 1, strftime('%Y-%m-%d %H:%M:%f', 'now'));
 | 
				
			||||||
INSERT INTO options (name, value, isSynced) VALUES ('embeddingBatchSize', '10', 1);
 | 
					INSERT INTO options (name, value, isSynced, utcDateModified) 
 | 
				
			||||||
INSERT INTO options (name, value, isSynced) VALUES ('embeddingDefaultDimension', '1536', 1); 
 | 
					VALUES ('embeddingUpdateInterval', '5000', 1, strftime('%Y-%m-%d %H:%M:%f', 'now')); -- 5 seconds
 | 
				
			||||||
 | 
					INSERT INTO options (name, value, isSynced, utcDateModified) 
 | 
				
			||||||
 | 
					VALUES ('embeddingBatchSize', '10', 1, strftime('%Y-%m-%d %H:%M:%f', 'now'));
 | 
				
			||||||
 | 
					INSERT INTO options (name, value, isSynced, utcDateModified) 
 | 
				
			||||||
 | 
					VALUES ('embeddingDefaultDimension', '1536', 1, strftime('%Y-%m-%d %H:%M:%f', 'now')); 
 | 
				
			||||||
@@ -132,3 +132,43 @@ CREATE INDEX IDX_attachments_ownerId_role
 | 
				
			|||||||
CREATE INDEX IDX_notes_blobId on notes (blobId);
 | 
					CREATE INDEX IDX_notes_blobId on notes (blobId);
 | 
				
			||||||
CREATE INDEX IDX_revisions_blobId on revisions (blobId);
 | 
					CREATE INDEX IDX_revisions_blobId on revisions (blobId);
 | 
				
			||||||
CREATE INDEX IDX_attachments_blobId on attachments (blobId);
 | 
					CREATE INDEX IDX_attachments_blobId on attachments (blobId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS "note_embeddings" (
 | 
				
			||||||
 | 
					    "embedId" TEXT NOT NULL PRIMARY KEY,
 | 
				
			||||||
 | 
					    "noteId" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "providerId" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "modelId" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "dimension" INTEGER NOT NULL,
 | 
				
			||||||
 | 
					    "embedding" BLOB NOT NULL,
 | 
				
			||||||
 | 
					    "version" INTEGER NOT NULL DEFAULT 1,
 | 
				
			||||||
 | 
					    "dateCreated" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "utcDateCreated" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "dateModified" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "utcDateModified" TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX "IDX_note_embeddings_noteId" ON "note_embeddings" ("noteId");
 | 
				
			||||||
 | 
					CREATE INDEX "IDX_note_embeddings_providerId_modelId" ON "note_embeddings" ("providerId", "modelId");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS "embedding_queue" (
 | 
				
			||||||
 | 
					    "noteId" TEXT NOT NULL PRIMARY KEY,
 | 
				
			||||||
 | 
					    "operation" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "dateQueued" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "utcDateQueued" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "priority" INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    "attempts" INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    "lastAttempt" TEXT NULL,
 | 
				
			||||||
 | 
					    "error" TEXT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE IF NOT EXISTS "embedding_providers" (
 | 
				
			||||||
 | 
					    "providerId" TEXT NOT NULL PRIMARY KEY,
 | 
				
			||||||
 | 
					    "name" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "isEnabled" INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    "priority" INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					    "config" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "dateCreated" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "utcDateCreated" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "dateModified" TEXT NOT NULL,
 | 
				
			||||||
 | 
					    "utcDateModified" TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,9 +90,16 @@ const ALLOWED_OPTIONS = new Set([
 | 
				
			|||||||
    "ollamaEnabled",
 | 
					    "ollamaEnabled",
 | 
				
			||||||
    "ollamaBaseUrl",
 | 
					    "ollamaBaseUrl",
 | 
				
			||||||
    "ollamaDefaultModel",
 | 
					    "ollamaDefaultModel",
 | 
				
			||||||
 | 
					    "ollamaEmbeddingModel",
 | 
				
			||||||
    "aiProviderPrecedence",
 | 
					    "aiProviderPrecedence",
 | 
				
			||||||
    "aiTemperature",
 | 
					    "aiTemperature",
 | 
				
			||||||
    "aiSystemPrompt"
 | 
					    "aiSystemPrompt",
 | 
				
			||||||
 | 
					    // Embedding options
 | 
				
			||||||
 | 
					    "embeddingAutoUpdate",
 | 
				
			||||||
 | 
					    "embeddingAutoUpdateEnabled",
 | 
				
			||||||
 | 
					    "embeddingBatchSize",
 | 
				
			||||||
 | 
					    "embeddingUpdateInterval",
 | 
				
			||||||
 | 
					    "embeddingDefaultDimension"
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getOptions() {
 | 
					function getOptions() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user