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(Creates a client with lazy initialization. The WebAssembly module and embedding model load on the first API call.projectId,projectKey,options?):MossClient
Parameters
Returns
MossClient
create() (eager)
MossClient.create(Creates a client with eager initialization. The WebAssembly module and embedding model load immediately, before the returned promise resolves.projectId,projectKey,options?):Promise<MossClient>
Parameters
Returns
Promise<MossClient>
Promise that resolves to a ready MossClient.
Example
Options
Index management
createIndex()
createIndex(Creates a new index with the provided documents.name,docs,options?):Promise
Parameters
Example
addDocs()
addDocs(Adds or updates documents in an index.name,docs,options?):Promise
Parameters
Example
deleteDocs()
deleteDocs(Deletes documents from an index by their IDs.name,docIds,options?):Promise
Parameters
Example
getIndex()
getIndex(Gets metadata about a specific index.name):Promise
Parameters
Example
listIndexes()
listIndexes(): Promise
Lists all available indexes.
Example
deleteIndex()
deleteIndex(Deletes an index and all its data.name):Promise
Parameters
Example
getDocs()
getDocs(Retrieves documents from an index.name,options?):Promise
Parameters
Example
getJobStatus()
getJobStatus(Gets the current status of an async operation.jobId):Promise
Parameters
Example
Local search
Queries run against an index that has been loaded into the browser. Always callloadIndex before query.
loadIndex()
loadIndex(Loads an index into the browser for fast local querying. Call this beforename,options?):Promise
query.
Parameters
Example
hasIndex()
hasIndex(Checks whether an index is loaded locally in the browser.name):Promise
Parameters
Example
getIndexInfo()
getIndexInfo(Gets info about a locally loaded index.name):Promise
Parameters
Example
query()
query(Performs a semantic similarity search against a loaded index. The index must be loaded withname,queryText,options?):Promise
loadIndex first; the search then runs entirely in the browser.
Parameters
Example
refreshIndex()
refreshIndex(Refreshes a loaded index from the server, picking up the latest changes.name):Promise
Parameters
Example
unloadIndex()
unloadIndex(Unloads an index from the browser, freeing its resources. Querying it again requires callingname):Promise
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.