From dd9ca71fc71a3cc609f7cd291c85233a14a86fa0 Mon Sep 17 00:00:00 2001 From: Tangent Date: Thu, 17 Sep 2026 01:56:35 -0600 Subject: [PATCH] config default set utility --- lib/utility.lua | 28 ++++++++++++++++++++++++++-- refresh_sources.lua | 13 +++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/utility.lua b/lib/utility.lua index cd6406c..e8db06f 100644 --- a/lib/utility.lua +++ b/lib/utility.lua @@ -375,10 +375,10 @@ end +local config_path = utility.path .. "config.json" local config, config_lock utility.get_config = function(skip_lock) if not config then - local config_path = utility.path .. "config.json" if utility.is_file(config_path) then if not skip_lock then config_lock = utility.get_lock(config_path) @@ -396,7 +396,6 @@ end utility.save_config = function() if config then - local config_path = utility.path .. "config.json" if not config_lock then print("Warning: A config lock file was not established.") end @@ -412,6 +411,31 @@ utility.save_config = function() end end +utility.get_config_with_defaults = function(defaults) + local config = utility.get_config() + + local loop, changes_made + loop = function(config_level, default_level) + for k,v in pairs(default_level) do + if not config_level[k] then + config_level[k] = v + changes_made = true + elseif type(v) == "table" then + loop(config_level[k], v) + end + end + end + loop(config, defaults) + + if changes_made then + utility.save_config() + else + utility.release_lock(config_path) + end + + return config +end + local data_file_locations = {} diff --git a/refresh_sources.lua b/refresh_sources.lua index 4396148..1c628fe 100755 --- a/refresh_sources.lua +++ b/refresh_sources.lua @@ -8,19 +8,16 @@ local log = utility.require("log") local text_processing = utility.require("text_processing") local timing = utility.require("timing") --- TODO make utility have a function for getting/setting defaults where locking is only used to set defaults if they aren't present -- TODO there should be a check function for a lock so a warning/error can be dumped? -local config = utility.get_config("no-lock") -if not config.models then - config.models = { +local config = utility.get_config_with_defaults{ + models = { embedding = { model = "qwen3-embedding:0.6b", max_chunk_size = 32768, }, initialized_sources = {}, - } - utility.save_config() -end + }, +} log{ info = true, @@ -257,7 +254,7 @@ local refresh_sources = function() if embeddings.vectors[sha512sum] then log("debug", file_name .. "\n has already been embedded, skipping.") - -- add file reference if it was missing + -- add file reference if it was missing (also handles recognition of duplicate files) if not embeddings.files[file_name] then embeddings.files[file_name] = { sha512sum } end