SessionIndex,
created from MossClient.session().
Lifecycle
1
Create or resume
client.session(name) returns a SessionIndex. In Python, Elixir, Swift and C, a cloud
index with that name loads into the session by default if it exists (no re-embedding);
otherwise the session starts empty. Python and Elixir skip that load with
auto_load_on_init, and Swift with autoLoadOnInit, for example to restore a session saved
on disk. A JavaScript session always starts empty: call session.loadIndex(name) to pull the
cloud index in, which resolves to 0 when there is none. The rest of the workflow is the
same either way.2
Mutate locally
add_docs, delete_docs, and get_docs run in-memory. add_docs embeds locally via the
Rust core, with no network round trip. With model_id="custom", each document must carry its own
.embedding.3
Query locally
query runs entirely in-memory (~1-10 ms) and supports the same metadata filter syntax as
MossClient.query().4
Persist (optional)
push_index() uploads the session’s documents to the cloud under the session’s name,
creating or replacing that index. For a built-in model the service re-embeds the text with
that model, so the pushed index answers text queries like one built with create_index. A
custom-model session keeps its own embeddings.To keep the session on the device instead, save_to_disk(cache_path) writes it under
<cache_path>/<name>/, and load_from_disk(cache_path) restores it into a later session with
the same name (saveToDisk and loadFromDisk in JavaScript). See the
Python,
Elixir and
JavaScript references.5
Close
close() sends the final usage report and frees the session’s documents and vectors.
Closing the client also closes its sessions in Python and JavaScript. See
Releasing resources.Short-term vs. long-term context
A session is short-term context - the working set for the current interaction. A persistent cloud index loaded withload_index()
is long-term context - durable knowledge shared across interactions. Most real-time
apps query both; see Live-call context.
Models
The session’s embedding model is set by themodel_id argument to session() (default
"moss-minilm"; also "moss-mediumlm" or "custom"). A session takes the model of the cloud
index or disk snapshot it loads, and model_id (modelId in JavaScript) reports the model in
use. After a custom-model load, adding documents and querying need embeddings. When resuming
an existing cloud index in Python or Elixir, omit model_id to adopt the stored model:
passing a different one raises a ValueError in Python and returns an :invalid_argument
error in Elixir. All participants resuming the same index must use the same model.
Authentication
Project credentials are validated when the session is opened;session() raises if they’re
invalid. See Authentication.
Implementation
Runnable, per-language examples (create-or-resume, mutate, query, push) live in the SDK guides:Related
Real-time local indexing
Why sessions are sub-10 ms.
Cross-agent handoff
Resume a session on another agent or channel.
Releasing resources
Close sessions and clients, and close idle clients.