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
| Parameter | Type | Description |
|---|---|---|
projectId | string | Your project identifier. |
projectKey | string | Your project authentication key. |
options? | MossClientOptions | Optional configuration. See Options. |
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
| Parameter | Type | Description |
|---|---|---|
projectId | string | Your project identifier. |
projectKey | string | Your project authentication key. |
options? | MossClientOptions | Optional configuration. See Options. |
Returns
Promise<MossClient>
Promise that resolves to a ready MossClient.
Example
Options
| Option | Type | Description |
|---|---|---|
model | "moss-minilm" | "moss-mediumlm" | Embedding model. Defaults to "moss-minilm" (fast, for most use-cases). Use "moss-mediumlm" for higher quality. |
baseUrl | string | Custom API base URL, for self-hosted Moss instances. |
Index management
createIndex()
createIndex(Creates a new index with the provided documents.name,docs,options?):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to create. |
docs | DocumentInfo[] | Documents to index. |
options? | CreateIndexOptions | Optional configuration. |
Example
createIndexFromFiles()
createIndexFromFiles(Creates a new index from files.name,files,options?):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to create. |
files | File[] | Files to index. |
options? | CreateIndexOptions | Optional configuration. |
Example
addDocs()
addDocs(Adds or updates documents in an index.name,docs,options?):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the target index. |
docs | DocumentInfo[] | Documents to add or update. |
options? | MutationOptions | Optional configuration. |
Example
deleteDocs()
deleteDocs(Deletes documents from an index by their IDs.name,docIds,options?):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the target index. |
docIds | string[] | Document IDs to delete. |
options? | MutationOptions | Optional configuration. |
Example
getIndex()
getIndex(Gets metadata about a specific index.name):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to retrieve. |
Example
listIndexes()
listIndexes(): Promise
Lists all available indexes.
Example
deleteIndex()
deleteIndex(Deletes an index and all its data.name):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to delete. |
Example
getDocs()
getDocs(Retrieves documents from an index.name,options?):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the target index. |
options? | GetDocumentsOptions | Optional configuration for retrieval. |
Example
getJobStatus()
getJobStatus(Gets the current status of an async operation.jobId):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
jobId | string | The job ID returned by an async operation. |
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
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to load. |
options? | LoadIndexOptions | Optional configuration. |
Example
hasIndex()
hasIndex(Checks whether an index is loaded locally in the browser.name):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to check. |
Example
getIndexInfo()
getIndexInfo(Gets info about a locally loaded index.name):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the loaded index. |
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
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the target index to search. |
queryText | string | The search query text. |
options? | QueryOptions | Optional query configuration, such as topK. |
Example
refreshIndex()
refreshIndex(Refreshes a loaded index from the server, picking up the latest changes.name):Promise
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the loaded index to refresh. |
Example
unloadIndex()
unloadIndex(Unloads an index from the browser, freeing its resources. Querying it again requires callingname):Promise
loadIndex first.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the index to unload. |
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.