Skip to main content
A session is a local index you read and write in real time, with no cloud round trip on any operation. Sessions are how Moss indexes data during a live interaction - indexing transcript turns mid-call, building a per-user working set, or accumulating context that is handed off between agents. A session is a SessionIndex, created from client.session(). It works with a client built with either a projectKey or a custom authenticator. A project key goes to the session directly, and a custom authenticator supplies the session’s tokens through the same bridge as loadIndex.

Create or resume

client.session(name) returns a SessionIndex that starts empty, even when a cloud index with that name exists. To resume that index, call session.loadIndex(name): it pulls the documents in without re-embedding and resolves to the number loaded, 0 when no cloud index has that name. name is also the target when pushIndex() is called, and a push replaces that cloud index with the session’s documents, so load it first to add to an existing index.

Short-term vs. long-term context

A session is short-term context - the working set for the current interaction. A persistent cloud index loaded with client.loadIndex() is long-term context - durable knowledge shared across interactions. Most real-time apps query both: load a cloud index for long-term knowledge, open a session for the live turns, and query each.

Loading a cloud index into a session

loadIndex() can pull any cloud index into the session’s local store, not only the one named after the session. With autoRefresh: true the SDK polls the cloud and pulls newer versions in on subsequent reads (paused while the session has un-pushed local edits).

Behavior notes

  • Every session operation (addDocs, deleteDocs, getDocs, query) runs in process memory with no per-operation cloud round trip.
  • The embedding model is set by the optional second argument to session() (default "moss-minilm"; also "moss-mediumlm" or "custom"). loadIndex() and loadFromDisk() move the session to the model of the index or snapshot they load, and session.modelId reports the model in use. After a custom-model load, addDocs takes the documents’ embeddings and query without an embedding rejects with code INVALID_ARGUMENT. (@moss-js/moss 1.17.0+) All participants resuming the same index must use the same model.
  • With modelId: 'custom', each added document must carry an embedding and every query must pass an embedding. See Custom embeddings.
  • pushIndex() uploads the session’s documents. For a built-in model the service re-embeds the text with that model, and a custom-model session keeps its own embeddings.
  • close() sends the final usage report and frees the session’s memory, and await using session = await client.session(name) calls it for you on Node.js 24 or later. client.close() also closes every session the client opened. See Releasing resources.