Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

4.4 KB
Raw Blame
"""
Database configuration environment settings.

These settings control SQLite and SQLCipher database parameters
that must be set before opening the database connection.

Each setting has a canonical env var name (auto-generated from the key,
e.g. db_config.kdf_iterations -> LDR_DB_CONFIG_KDF_ITERATIONS) and an
optional deprecated alias for backward compatibility with older env var
names (e.g. LDR_DB_KDF_ITERATIONS).
"""

from ..env_settings import (
    IntegerSetting,
    EnumSetting,
)


# Database configuration settings
DB_CONFIG_SETTINGS = [
    # Performance settings
    IntegerSetting(
        key="db_config.cache_size_mb",
        description="SQLite cache size in MB",
        min_value=1,
        max_value=10000,
        default=64,
        deprecated_env_var="LDR_DB_CACHE_SIZE_MB",
    ),
    EnumSetting(
        key="db_config.journal_mode",
        description="SQLite journal mode",
        allowed_values={
            "DELETE",
            "TRUNCATE",
            "PERSIST",
            "MEMORY",
            "WAL",
            "OFF",
        },
        default="WAL",
        case_sensitive=False,
        deprecated_env_var="LDR_DB_JOURNAL_MODE",
    ),
    EnumSetting(
        key="db_config.synchronous",
        description="SQLite synchronous mode",
        allowed_values={"OFF", "NORMAL", "FULL", "EXTRA"},
        default="NORMAL",
        case_sensitive=False,
        deprecated_env_var="LDR_DB_SYNCHRONOUS",
    ),
    IntegerSetting(
        key="db_config.wal_autocheckpoint",
        description="WAL frames threshold for automatic PASSIVE checkpoint at commit. Lower = smaller WAL high-water-mark, faster recovery on open, slightly more frequent fsyncs.",
        min_value=10,
        max_value=10000,
        default=250,
    ),
    IntegerSetting(
        key="db_config.busy_timeout_ms",
        description=(
            "SQLite busy_timeout in milliseconds -- how long a writer waits "
            "for the database lock before giving up with 'database is locked'. "
            "Set above the p99 latency of in-flight transactions (the background "
            "document scheduler can hold a session across multi-second PDF "
            "downloads; 30s gives the rate-limit tracker and other short writers "
            "enough headroom to land their commit instead of swallowing the error)."
        ),
        # Lower bound 100 ms: anything below that is effectively a no-op
        # anyway (the holder's transaction has to release the lock in the
        # 100 ms window), and tests need to drop it further to keep the
        # negative-control timeout test fast.
        min_value=100,
        max_value=300000,
        default=30000,
        deprecated_env_var="LDR_DB_BUSY_TIMEOUT_MS",
    ),
    # Storage settings
    IntegerSetting(
        key="db_config.page_size",
        description="SQLite page size (must be power of 2)",
        min_value=512,
        max_value=65536,
        default=16384,
        deprecated_env_var="LDR_DB_PAGE_SIZE",
    ),
    # Encryption settings
    IntegerSetting(
        key="db_config.kdf_iterations",
        description="Number of KDF iterations for key derivation",
        min_value=1000,
        max_value=1000000,
        default=256000,
        deprecated_env_var="LDR_DB_KDF_ITERATIONS",
    ),
    EnumSetting(
        key="db_config.kdf_algorithm",
        description="Key derivation function algorithm",
        allowed_values={
            "PBKDF2_HMAC_SHA512",
            "PBKDF2_HMAC_SHA256",
            "PBKDF2_HMAC_SHA1",  # DevSkim: ignore DS126858 — backwards compat for existing databases; default is SHA512
        },
        default="PBKDF2_HMAC_SHA512",
        case_sensitive=False,
        deprecated_env_var="LDR_DB_KDF_ALGORITHM",
    ),
    EnumSetting(
        key="db_config.hmac_algorithm",
        description="HMAC algorithm for database integrity",
        allowed_values={
            "HMAC_SHA512",
            "HMAC_SHA256",
            "HMAC_SHA1",  # DevSkim: ignore DS126858 — backwards compat for existing databases; default is SHA512
        },
        default="HMAC_SHA512",
        case_sensitive=False,
        deprecated_env_var="LDR_DB_HMAC_ALGORITHM",
    ),
    # Runtime security settings
    EnumSetting(
        key="db_config.cipher_memory_security",
        description="SQLCipher memory security (ON=clear memory after use + mlock, OFF=faster). ON requires IPC_LOCK in Docker.",
        allowed_values={"ON", "OFF"},
        default="OFF",
        case_sensitive=False,
    ),
]