You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: lazily initialize engines from saved settings (#10)
Reuse persisted provider/model settings by creating missing local, remote, or custom engines on first embedding use instead of requiring memory_set_model on every connection.
Keep memory_set_model eager so callers can preload and validate engines explicitly, while memory_set_apikey remains connection-scoped and lazy for saved remote models.
Update API/README documentation and add regression coverage for saved local, remote, and custom provider settings.
Verification: build/unittest with TEST_SQLITE_EXTENSION passed 157 tests.
Copy file name to clipboardExpand all lines: API.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,8 +136,9 @@ Configures the embedding model to use.
136
136
- When `provider` is `"local"`, the extension uses the built-in llama.cpp engine and verifies the model file exists
137
137
- When `provider` is anything other than `"local"`, the extension uses the [vectors.space](https://vectors.space) remote embedding service
138
138
- Remote embedding requires a free API key from [vectors.space](https://vectors.space) (set via `memory_set_apikey`)
139
-
- Settings are persisted in `dbmem_settings` table
140
-
- For local models, the embedding engine is initialized immediately
139
+
- Provider/model settings are persisted in the `dbmem_settings` table and reused by new connections
140
+
- Calling `memory_set_model()` initializes the embedding engine immediately, which can be used to preload and validate the engine
141
+
- When provider/model settings are loaded by a new connection, the engine is initialized lazily on first embedding use
141
142
-**Automatic reindex**: If a model was previously configured and the new provider/model differs, all existing content is automatically re-embedded with the new model. File-based entries are re-read from disk; text-based entries are re-embedded from stored content. Errors on individual entries are silently skipped (best-effort)
142
143
143
144
**Example:**
@@ -164,7 +165,7 @@ Sets the API key for the [vectors.space](https://vectors.space) remote embedding
164
165
**Returns:** INTEGER - 1 on success
165
166
166
167
**Notes:**
167
-
- API key is stored in memory only, not persisted to disk
168
+
- API key is stored in memory only, not persisted to disk, and must be set per connection for remote embeddings
168
169
- Required when using any provider other than `"local"`
169
170
- Get a free API key by creating an account at [vectors.space](https://vectors.space)
170
171
@@ -623,7 +624,7 @@ Generates or refreshes local embeddings for stored content.
623
624
**Returns:** INTEGER - Number of content rows reindexed or realigned
624
625
625
626
**Notes:**
626
-
- Requires an embedding model configured with `memory_set_model()`
627
+
- Requires an embedding model configured with `memory_set_model()` or loaded from persisted provider/model settings
627
628
- Processes rows in `dbmem_content` that have stored `value`
628
629
- Skips rows whose `dbmem_content.hash` already matches `value` and whose local `dbmem_vault` entries already exist
629
630
- After sync merges remote changes into `dbmem_content.value`, recomputes stale hashes, refreshes missing embeddings, and removes old local index rows
@@ -714,7 +715,7 @@ int sqlite3_memory_register_provider(
714
715
);
715
716
```
716
717
717
-
Registers a custom embedding engine for a specific database connection. Once registered, calling `memory_set_model(provider_name, model)` from SQL will use your engine instead of the built-in local or remote engines.
718
+
Registers a custom embedding engine for a specific database connection. Once registered, calling `memory_set_model(provider_name, model)` from SQL will use your engine instead of the built-in local or remote engines. If provider/model settings were already loaded from `dbmem_settings`, the custom engine is initialized lazily on first embedding use after registration.
718
719
719
720
**Parameters:**
720
721
| Parameter | Type | Description |
@@ -728,7 +729,8 @@ Registers a custom embedding engine for a specific database connection. Once reg
728
729
**`dbmem_provider_t` struct:**
729
730
```c
730
731
typedefstruct {
731
-
// Called when memory_set_model(provider_name, model) is executed.
732
+
// Called when memory_set_model(provider_name, model) is executed, or lazily
733
+
// on first embedding use when provider/model were loaded from settings.
732
734
// api_key is the value set via memory_set_apikey() (may be NULL).
733
735
// xdata is the user pointer from this struct.
734
736
// Return an opaque engine pointer on success, or NULL on error (fill err_msg).
0 commit comments