Skip to content

Commit

Permalink
database optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Aug 2, 2024
1 parent 2043b8d commit 57d985d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 16 additions & 0 deletions lumni/src/apps/builtin/llm/prompt/src/chat/db/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ impl DatabaseConnector {

pub fn new(sqlite_file: &PathBuf) -> Result<Self, SqliteError> {
let connection = rusqlite::Connection::open(sqlite_file)?;

// Set PRAGMA settings that need to be set outside of a transaction
connection.execute_batch(
"PRAGMA auto_vacuum = INCREMENTAL;
PRAGMA page_size = 4096;
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;
PRAGMA mmap_size = 134217728;
PRAGMA cache_size = -16000;
PRAGMA temp_store = MEMORY;
PRAGMA busy_timeout = 5000;
PRAGMA wal_autocheckpoint = 1000;
PRAGMA journal_size_limit = 67108864;"
)?;

let operation_queue = Arc::new(Mutex::new(VecDeque::new()));

let mut conn = DatabaseConnector {
Expand Down
11 changes: 6 additions & 5 deletions lumni/src/apps/builtin/llm/prompt/src/chat/db/schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PRAGMA foreign_keys = ON;

CREATE TABLE metadata (
key TEXT PRIMARY KEY,
Expand All @@ -14,7 +13,7 @@ CREATE TABLE models (
);

CREATE TABLE conversations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id INTEGER PRIMARY KEY,
name TEXT,
info TEXT, -- JSON string including description and other metadata
completion_options TEXT, -- JSON string
Expand All @@ -36,7 +35,7 @@ CREATE TABLE conversations (
);

CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id INTEGER PRIMARY KEY,
conversation_id INTEGER NOT NULL,
role TEXT NOT NULL CHECK(role IN ('user', 'assistant', 'system')),
message_type TEXT NOT NULL,
Expand All @@ -55,7 +54,7 @@ CREATE TABLE messages (
);

CREATE TABLE attachments (
attachment_id INTEGER PRIMARY KEY AUTOINCREMENT,
attachment_id INTEGER PRIMARY KEY,
message_id INTEGER NOT NULL,
conversation_id INTEGER NOT NULL,
file_uri TEXT,
Expand Down Expand Up @@ -87,4 +86,6 @@ CREATE INDEX idx_conversation_is_deleted_updated ON conversations(is_deleted, up
CREATE INDEX idx_message_conversation_created ON messages(conversation_id, created_at);
CREATE INDEX idx_message_previous ON messages(previous_message_id);
CREATE INDEX idx_attachment_conversation ON attachments(conversation_id);
CREATE INDEX idx_conversation_pinned_updated ON conversations(is_pinned DESC, updated_at DESC);
CREATE INDEX idx_conversation_pinned_updated ON conversations(is_pinned DESC, updated_at DESC);


0 comments on commit 57d985d

Please sign in to comment.