Fix local embedding context rebuilds and batch safety#7
Open
andinux wants to merge 2 commits into
Open
Conversation
Prevent empty semantic chunks from reaching embedding providers, where they can produce invalid zero-dimensional results and pollute the vault or cache. The check lives in the parser callback path so all embedding providers and SQLite entry points share the same filtering behavior before provider-specific code runs.
Configure local llama contexts from max_tokens plus overlay_tokens so encoder inputs fit the chunk sizes produced by the parser. The local engine now sizes n_ctx, n_batch, n_ubatch, and token buffers together, caps the context to bounded/model-supported values, prepares reusable batches with sequence metadata, and truncates over-capacity tokenization explicitly instead of relying on llama.cpp assertions. Move llama diagnostics out of per-engine logger user_data because llama_log_set installs a process-global callback. Thread-local diagnostic capture keeps load/context errors useful without writing through stale engine pointers after another connection replaces or frees an engine. Rebuild the local engine when max_tokens or overlay_tokens changes because those options alter chunk sizes after memory_set_model. The option update now runs under a savepoint, rolls back in-memory and persisted settings on rebuild failure, and keeps the previous engine alive unless the replacement is fully ready. Invalidate cached embeddings for the active local provider/model after a successful context rebuild. The cache key does not include local context sizing, so clearing that provider/model avoids reusing stale embeddings, token counts, or truncation metadata generated under the previous context window. Add a logger regression test for stale global logger user_data and bump the extension version to 1.2.1.
marcobambini
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes local embedding stability and context handling for sqlmem / sqlite-memory.
Changes
Why
Local embedding models could crash or return stale results in several cases: