kv-store

Public

A simple key-value store that gives tool-calling models a basic persistent storage capability. Based on Sqlite.

111 Downloads

README

KV Store

A simple key-value store that gives tool-calling models a basic persistent storage capability, backed by SQLite.

Parts of this implementation were originally inspired by dirty-data/persistent-memory, itself a fork of khtsly/persistent-memory.

I built this to evaluate how well small models can create their own schemes/protocols for using well-defined persistent storage tools to manage higher-order goals.

Notes and Tips

  • This plugin creates SQLite database files in the directory ~/.lmstudio/plugin-data/student489/kv-store/.
  • The database filename can be changed in plugin configuration (see below).
  • An optional utility tool makes the current system date/time available to the model. Disabled by default.
  • Smaller models can be sensitive to the content of tool descriptions. This plugin tries to provide very clear (but concise) tool descriptions, so that models can figure out how to use it effectively/correctly.
  • This is a toy implementation, which I built to experiment with how well small models can create their own schemes/protocols for using persistent storage tools, to support higher-order goals. Example prompt:
You have access to KV store tools, which allow you to store and retrieve data.
First, test these KV store tools.
Then, create a plan/scheme/protocol to describe how you would use these KV store tools to plan and track multi-step tasks.
Then, present the plan for review and refinement.

Tools

The plugin exposes the following tools to models:

ToolParametersBehavior
kv_setkey: string, value: stringSets or replaces a text (string) value. Key length must be 1 to 255 characters. Value length must be at most 10,240 characters (10 KB equivalent). Returns { ok: true, size } on success, { ok: false, error } on failure.
kv_getkey: stringReturns value for a key. If not found, returns found=false, value=null, and size=null. Returns { ok: true, found, value, size } on success, { ok: false, error } on failure.
kv_appendkey: string, value: stringAppends text to the current value for a key, creating the key if it does not already exist. Returns the post-append value in the same shape as kv_get: { ok: true, found, value, size } on success, { ok: false, error } on failure.
kv_get_manykeys: string[]Gets values for multiple keys (1 to 10 keys per call). Returns { ok: true, pairs } on success, where pairs is an array of { key, value, size }. Only keys that exist are returned. Returns { ok: false, error } on failure.
kv_deletekey: stringDeletes a key. No-op if it does not exist. Returns { ok: true } on success, { ok: false, error } on failure.
kv_delete_manykeys: string[]Deletes multiple keys in a single call (1 to 10 keys per call). Missing keys are ignored. Returns { ok: true } on success, { ok: false, error } on failure.
kv_renameoldKey: string, newKey: stringRenames a key while preserving its value. Fails if the source key does not exist or the destination key already exists. Returns { ok: true } on success, { ok: false, error } on failure.
kv_list_keyslimit?: number, offset?: numberLists keys in sorted order with optional pagination. Maximum 200 keys per call. Returns { ok: true, keys } on success, { ok: false, error } on failure.
kv_filter_keysmatch: string, limit?: number, offset?: numberLists keys containing match (case-insensitive), with optional pagination. Maximum 200 keys per call. Returns { ok: true, keys } on success, { ok: false, error } on failure.
kv_count_keysfilter?: stringCounts total keys. If filter is provided, counts only keys containing the filter substring (case-insensitive), like kv_filter_keys. Returns { ok: true, count } on success, { ok: false, error } on failure.
get_current_timestampnoneReturns the current UTC time in ISO 8601 format as { timestamp }. Disabled by default; enable via plugin setting.

Plugin settings

DB storage filename (dbStorageFilename)

  • Change the filename of the SQLite database file.
  • This is convenient for using different databases for different LM Studio model presets.
  • By design, this setting cannot modify the storage path/directory, which is ~/.lmstudio/plugin-data/student489/kv-store/.
  • Filename is validated to ensure it does not contain path separators or traversal patterns, or unsafe characters.

Enable timestamp utility tool (enableTimestampUtilityTool)

  • Controls whether the get_current_timestamp tool is exposed to models.
  • Allowed values: on or off.
  • Default: off.

Database

The plugin uses sql.js as the database engine, which is a JavaScript port of SQLite.

The database schema contains a single table kv_store with the following columns:

  • key (TEXT PRIMARY KEY): The key of the key-value pair.
  • value (TEXT): The value of the key-value pair, stored as string.
  • created_at (DATETIME): The timestamp when the key-value pair was created.
  • updated_at (DATETIME): The timestamp when the key-value pair was last updated.

License

MIT