Skip to main content
@moss-dev/moss-web / MossClient

MossClient

MossClient is the entry point for the Moss Browser/WASM SDK. It manages indexes and documents and runs semantic search locally in the browser. Once an index is loaded with loadIndex, queries run entirely in-browser with no server round-trips. This is the in-browser client. For server-side (Node.js) code, use the Node MossClient instead. See Browser vs Node for guidance. This client does not have sessions.

Example

Creating a client

Constructor (lazy)

new MossClient(projectId, projectKey, options?): MossClient
Creates a client with lazy initialization. The WebAssembly module and embedding model load on the first API call.

Parameters

Returns

MossClient

create() (eager)

MossClient.create(projectId, projectKey, options?): Promise<MossClient>
Creates a client with eager initialization. The WebAssembly module and embedding model load immediately, before the returned promise resolves.

Parameters

Returns

Promise<MossClient> Promise that resolves to a ready MossClient.

Example

Options

Index management

createIndex()

createIndex(name, docs, options?): Promise
Creates a new index with the provided documents.

Parameters

Example


addDocs()

addDocs(name, docs, options?): Promise
Adds or updates documents in an index.

Parameters

Example


deleteDocs()

deleteDocs(name, docIds, options?): Promise
Deletes documents from an index by their IDs.

Parameters

Example


getIndex()

getIndex(name): Promise
Gets metadata about a specific index.

Parameters

Example


listIndexes()

listIndexes(): Promise
Lists all available indexes.

Example


deleteIndex()

deleteIndex(name): Promise
Deletes an index and all its data.

Parameters

Example


getDocs()

getDocs(name, options?): Promise
Retrieves documents from an index.

Parameters

Example


getJobStatus()

getJobStatus(jobId): Promise
Gets the current status of an async operation.

Parameters

Example

Queries run against an index that has been loaded into the browser. Always call loadIndex before query.

loadIndex()

loadIndex(name, options?): Promise
Loads an index into the browser for fast local querying. Call this before query.

Parameters

Example


hasIndex()

hasIndex(name): Promise
Checks whether an index is loaded locally in the browser.

Parameters

Example


getIndexInfo()

getIndexInfo(name): Promise
Gets info about a locally loaded index.

Parameters

Example


query()

query(name, queryText, options?): Promise
Performs a semantic similarity search against a loaded index. The index must be loaded with loadIndex first; the search then runs entirely in the browser.

Parameters

Example


refreshIndex()

refreshIndex(name): Promise
Refreshes a loaded index from the server, picking up the latest changes.

Parameters

Example


unloadIndex()

unloadIndex(name): Promise
Unloads an index from the browser, freeing its resources. Querying it again requires calling loadIndex first.

Parameters

Example

Cleanup

dispose()

dispose(): void
Releases all resources held by the client, including loaded indexes and the WebAssembly runtime. Call this when the client is no longer needed.

Example