SessionIndex
A local-first, in-process index for real-time indexing and querying. All operations (addDocs, deleteDocs, query) run in process memory with no cloud round-trip per
operation. Call pushIndex() to persist the session to the cloud.
Construct a session with MossClient.session(); the constructor is
not used directly.
Example
Accessors
Methods
addDocs()
addDocs(Adds or updates documents in the local session index. For built-in models, embeddings are generated locally. Fordocs,options?):Promise<{added:number;updated:number}>
modelId: "custom", each document must carry an embedding.
Parameters
Returns
Promise<{ added: number; updated: number }>
deleteDocs()
deleteDocs(Deletes documents from the local session by id. Returns the number removed.docIds):Promise<number>
Parameters
Returns
Promise<number>
getDocs()
getDocs(Fetches documents currently in the local session.options?):Promise<DocumentInfo[]>
Parameters
Returns
Promise<DocumentInfo[]>
query()
query(Hybrid (keyword + semantic) search over the local session index, entirely in-memory. Forquery,options?):Promise<SearchResult>
modelId: "custom", an explicit options.embedding is required.
Parameters
Returns
Promise<SearchResult>
loadIndex()
loadIndex(Loads an existing cloud index into the session by name. A session starts empty, so this is how it resumes the cloud index it is named after. WithindexName,options?):Promise<number>
options.autoRefresh = true,
the SDK polls the cloud index and pulls newer versions in on subsequent reads (paused while
the session has un-pushed local edits). Returns the number of documents loaded, 0 when no
cloud index has that name.
Parameters
Returns
Promise<number>
pushIndex()
pushIndex():Uploads the session to the cloud, creating or replacing the index with the same name. For a built-in model the service re-embeds the text with that model, so the index loads and answers text queries like one built withPromise<PushIndexResult>
createIndex. A custom-model session keeps its own
embeddings.
Returns
Promise<PushIndexResult>
saveToDisk()
saveToDisk(Persists the session tocachePath):Promise<void>
<cachePath>/<name>/ for offline reuse without a cloud round-trip.
Parameters
loadFromDisk()
loadFromDisk(Restores a session previously written bycachePath):Promise<number>
saveToDisk. Returns the number of documents loaded.
Parameters
Returns
Promise<number>
close()
close():Sends the final usage report, then releases the session’s native resources: its auto-refresh poller, its in-memory index and its reference to the shared embedding model. Resolves once the report arrives or 2 seconds pass. Safe to call more than once. AfterwardsPromise<void>
name and modelId still read; docCount and every method throw.
MossClient.close() also closes every session the client opened.
SessionIndex also implements Symbol.asyncDispose, so await using closes it when the
enclosing block ends (Node.js 24 or later).
Returns
Promise<void>