Persistent ordered maps with optional embedding and semantic search. Available in CLI (hot run), event handlers, scheduled functions, and tasks.

Handlers can run at the same time, so a get followed by a put can lose another handler's write. Change a shared entry with the atomic writes instead: put-if-missing creates it once, put-if replaces it only if it still holds the value you read, and increment counts.

Functions

all

fn (store: Map, predicate: Fn): Bool

Return true if all entries match predicate. Mirrors ::hot::coll/all.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
all-reviewed ::store/all(kb, (k, v) { v.reviewed })

clear

fn (store: Map): Bool

Remove all entries from a store but keep the store itself.

Example

::store ::hot::store
settings ::store/Map({name: "settings"})
::store/clear(settings)

delete

fn (store: Map, key: Any): Bool

Delete an entry by key. Returns true if the key existed.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
::store/delete(kb, "refund-policy")

destroy

fn (store: Map): Bool

Delete the store entirely (schema + data).

Example

::store ::hot::store
old-store ::store/Map({name: "old-store"})
::store/destroy(old-store)

filter

fn (store: Map, predicate: Fn): Vec

Filter entries by a predicate fn(key, value) -> Bool. Returns a Vec of matching entries. Mirrors ::hot::coll/filter. It reads every entry; to read the keys that share a prefix, use list or keys with the prefix option, which reads only those from an index.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
billing-docs ::store/filter(kb, (k, v) { eq(v.category, "billing") })

find-first

fn (store: Map, predicate: Fn): Any

Return the first entry matching predicate, or null. Mirrors ::hot::coll/find-first.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
urgent ::store/find-first(kb, (k, v) { eq(v.priority, "urgent") })

first

fn (store: Map): Any

Return the first entry (by insertion order) as {key: ..., value: ...}, or null. Mirrors ::hot::coll/first.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
entry ::store/first(kb)
entry.key

get

fn (store: Map, key: Any): Any
fn (store: Map, key: Any, default: Any): Any

Get a value by key. Returns null if not found (2-arity) or default (3-arity). Mirrors ::hot::coll/get.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
doc ::store/get(kb, "refund-policy")
doc ::store/get(kb, "missing", {title: "default"})

increment

fn (store: Map, key: Any): Int
fn (store: Map, key: Any, by: Int): Int

Atomically add by (default 1) to the Int stored at a key and return the new value. A missing key counts from 0, so the first call returns by. The database reads and writes the counter in one transaction that holds the entry's lock, so concurrent increments are never lost.

by may be negative. A stored value that is not an Int, or a result beyond the Int range, is an error and leaves the counter unchanged. Counters are not embedded, even in stores with embeddings.

An increment is not idempotent: a retried or redelivered event increments again.

Example

::store ::hot::store
counters ::store/Map({name: "counters"})
case-id "case-1"
seq ::store/increment(counters, `case:${case-id}:seq`)
::store/increment(counters, "tickets-closed", 3)

is-empty

fn (store: Map): Bool

Return true if the store has no entries. Mirrors ::hot::coll/is-empty.

Example

::store ::hot::store
settings ::store/Map({name: "settings"})
empty ::store/is-empty(settings)

keys

fn (store: Map): Vec
fn (store: Map, opts: Map): Vec

Return all keys in insertion order. Mirrors ::hot::coll/keys.

With options, return the keys list would for the same options, without reading values: prefix keeps the Str keys that start with it (read from an index), and limit/offset page through them. Unlike list, there is no default limit.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
all-keys ::store/keys(kb)
case-id "case-1"
fact-keys ::store/keys(kb, {prefix: `case:${case-id}:`})

last

fn (store: Map): Any

Return the last entry (by insertion order) as {key: ..., value: ...}, or null. Mirrors ::hot::coll/last.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
entry ::store/last(kb)
entry.value

length

fn (store: Map): Int

Return the number of entries. Mirrors ::hot::coll/length.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
count ::store/length(kb)

list

fn (store: Map): Vec
fn (store: Map, opts: Map): Vec

Paginated listing of {key, value} entries in insertion order.

Options

  • limit — Most entries to return (default: 1000)
  • offset — Entries to skip first (default: 0)
  • prefix — Only entries whose key is a Str starting with this prefix. The database reads the matching keys from an index, not by scanning the store, and limit/offset page through the matches.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
page ::store/list(kb, {limit: 20, offset: 0})
case-id "case-1"
facts ::store/list(kb, {prefix: `case:${case-id}:`, limit: 100})

merge

fn (store: Map, entries: Map): Int

Merge a map of key-value pairs into the store. Mirrors ::hot::coll/merge. The entries are written together: if the write fails, none of them is stored.

Example

::store ::hot::store
settings ::store/Map({name: "settings"})
::store/merge(settings, {
  "smtp-host": "mail.example.com",
  "smtp-port": 587
})

put

fn (store: Map, key: Any, value: Any): Any

Write a key-value pair to a store. Auto-embeds if the store has embedding enabled. If the key already exists, the value is updated but insertion order is preserved.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
::store/put(kb, "refund-policy", {
  title: "Refund Policy",
  content: "Refunds are available within 30 days..."
})

put-if

fn (store: Map, key: Any, expected: Any, value: Any): Bool

Atomically replace a key's value only if it still holds expected (compare-and-set). Returns true when this call wrote value and false when the stored value had changed, leaving it untouched.

The database compares and writes in one transaction that holds the entry's lock, so two writers that read the same value cannot both replace it. Values compare as Hot values, so pass expected exactly as the 2-arity get returned it. An expected of null also matches a missing key, as get returns null for one, and then put-if creates the entry.

To change a value safely while other handlers change it too, read it, compute the new value, and retry while put-if returns false. The computation must be pure, since it can run more than once. Each retry means another writer changed the value first; give the loop a budget so a bug, such as an expected that is not what get returned, fails instead of spinning.

Example

::store ::hot::store
cases ::store/Map({name: "cases"})

// Add one answer to a case's records; a concurrent answer is never lost
add-answer fn (case-id: Str, answer-id: Str, answer: Any, attempts: Int): Map {
    current ::store/get(cases, case-id)  // null while the case has none
    next assoc(if(is-null(current), {}, current), answer-id, answer)
    wrote ::store/put-if(cases, case-id, current, next)
    cond {
        wrote => { next }
        lte(attempts, 1) => { err(`case ${case-id} kept changing`) }
        => { add-answer(case-id, answer-id, answer, sub(attempts, 1)) }  // changed: retry
    }
}

add-answer("case-1", "answer-1", {score: 4}, 20)

put-if-missing

fn (store: Map, key: Any, value: Any): Bool

Atomically create a key-value pair without replacing an existing entry.

put sets a key, replacing its value when it already exists. put-if-missing returns true when this call created the entry and false when the key already existed, leaving the stored value and insertion order unchanged.

Stores with embeddings avoid a known-unnecessary embedding call when the key already exists. Concurrent losing calls may still compute an unused embedding before the database chooses the single winner.

Example

::store ::hot::store
settings ::store/Map({name: "settings"})
created ::store/put-if-missing(settings, "initialized", true)

put-many

fn (store: Map, entries: Map): Int

Batch write from a map of key-value pairs. Returns the count of entries written. The entries are written together: if the write fails, none of them is stored.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
::store/put-many(kb, {
  "doc-1": {title: "Returns", content: "Return within 30 days..."},
  "doc-2": {title: "Shipping", content: "We ship worldwide..."}
})

reduce

fn (store: Map, reducer: Fn, initial: Any): Any

Reduce over all entries. The reducer receives (acc, key, value). Mirrors ::hot::coll/reduce.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
total ::store/reduce(kb, (acc, k, v) { add(acc, v.amount) }, 0)
fn (store: Map, query: Str): Vec
fn (store: Map, query: Str, opts: Map): Vec

Semantic and/or keyword search. Returns a Vec of {key, value, score}.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
results ::store/search(kb, "how do I get my money back", {limit: 5, min-score: 0.7})

slice

fn (store: Map, start: Int): Vec
fn (store: Map, start: Int, end: Int): Vec

Return a range of entries by insertion position. Mirrors ::hot::coll/slice.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
first-ten ::store/slice(kb, 0, 10)

some

fn (store: Map, predicate: Fn): Bool

Return true if any entry matches predicate. Mirrors ::hot::coll/some.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
has-urgent ::store/some(kb, (k, v) { eq(v.priority, "urgent") })

vals

fn (store: Map): Vec

Return all values in insertion order. Mirrors ::hot::coll/vals.

Example

::store ::hot::store
kb ::store/Map({name: "kb"})
all-vals ::store/vals(kb)

Types

Embedding core

Embedding type {
    provider: Str?,
    model: Str?,
    dimensions: Int?,
    field: Str?,
    text-search: Bool?,
    embed-fn: Fn?,
    embed-batch-fn: Fn?,
    on-error: Str?
}

Custom embedding provider options for a store Map.

Fields

  • provider — Provider label used for compatibility checks (e.g. "local", "qwen")
  • model — Override the embedding model (e.g. "bge-base-en-v1.5", "text-embedding-3-small")
  • dimensions — Expected vector length. Required for custom embed-fn values.
  • field — Which field of the value to embed (default: "content")
  • text-search — Also enable keyword search (default: false)
  • embed-fn — Custom Hot function (text: Str) -> Vec<Dec | Int>
  • embed-batch-fn — Optional batch custom Hot function (texts: Vec<Str>) -> Vec<Vec<Dec | Int>>
  • on-error — Custom embed failure policy: "fail" (default for embed-fn) or "skip"

EmbeddingOptions core

Explicit embedding mode for a store Map.

  • EmbeddingOptions.Default — use system embedding defaults
  • EmbeddingOptions.Off — disable embeddings
  • EmbeddingOptions.Embedding(Embedding({...})) — use explicit provider/model/hooks
  • Embedding({...}) — shorthand for EmbeddingOptions.Embedding(Embedding({...}))

Map

Map type {
    name: Str,
    embedding: EmbeddingOptions?
}

A persistent, insertion-ordered map with optional embeddings and search.

Fields

  • name — Unique store name (e.g. "settings", "kb", "support:${stream-id}")
  • embedding — EmbeddingOptions.Off/null = off, EmbeddingOptions.Default = system defaults, Embedding({...}) = override

Example

::store ::hot::store
Embedding ::store/Embedding
EmbeddingOptions ::store/EmbeddingOptions

// Plain persistent map
settings ::store/Map({name: "settings"})

// With semantic search
kb ::store/Map({name: "kb", embedding: EmbeddingOptions.Default})

// With custom overrides
docs ::store/Map({name: "docs", embedding: Embedding({
    provider: "openai",
    model: "text-embedding-3-small",
    dimensions: 1536,
    field: "body",
    text-search: true,
})})