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
| Property | Type | Description |
|---|---|---|
name | string | The session index name. Identifies the cloud index on pushIndex / loadIndex. |
docCount | number | Number of documents currently in the local session. |
modelId | MossModel | The embedding model the session is configured for. |
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
| Parameter | Type | Description |
|---|---|---|
docs | DocumentInfo[] | Documents to add or update. |
options? | MutationOptions | Mutation options (e.g. upsert). |
Returns
Promise<{ added: number; updated: number }>
deleteDocs()
deleteDocs(Deletes documents from the local session by id. Returns the number removed.docIds):Promise<number>
Parameters
| Parameter | Type | Description |
|---|---|---|
docIds | string[] | Document ids to delete. |
Returns
Promise<number>
getDocs()
getDocs(Fetches documents currently in the local session.options?):Promise<DocumentInfo[]>
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | GetDocumentsOptions | Pass docIds to filter. |
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
| Parameter | Type | Description |
|---|---|---|
query | string | The search query text. |
options? | QueryOptions | Query options (topK, alpha, embedding, filter). |
Returns
Promise<SearchResult>
loadIndex()
loadIndex(Loads an existing cloud index into the session by name. 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
indexName | string | Name of the cloud index to load into the session. |
options? | LoadSessionOptions | Auto-refresh settings. |
Returns
Promise<number>
pushIndex()
pushIndex():Uploads the session to the cloud, creating or replacing the index with the same name. Documents are pushed with their locally-computed embeddings; no server-side re-embedding.Promise<PushIndexResult>
Returns
Promise<PushIndexResult>
saveToDisk()
saveToDisk(Persists the session tocachePath):Promise<void>
<cachePath>/<name>/ for offline reuse without a cloud round-trip.
Parameters
| Parameter | Type | Description |
|---|---|---|
cachePath | string | Directory to write the session to. |
loadFromDisk()
loadFromDisk(Restores a session previously written bycachePath):Promise<number>
saveToDisk. Returns the number of documents loaded.
Parameters
| Parameter | Type | Description |
|---|---|---|
cachePath | string | Directory a session was saved to. |
Returns
Promise<number>