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 withclient.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()andloadFromDisk()move the session to the model of the index or snapshot they load, andsession.modelIdreports the model in use. After a custom-model load,addDocstakes the documents’ embeddings andquerywithout anembeddingrejects with codeINVALID_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 anembeddingand everyquerymust pass anembedding. 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, andawait 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.
Related
- SessionIndex reference - every session method.
- MossClient.session() - open an empty session.
- Metadata filtering - filter inside a session query.
- SDK reference - the full JavaScript SDK overview.