MossClient
The entry point for the Swift SDK. Construct it with your project credentials (or a customAuthenticator), then open on-device
sessions and track push jobs.
All methods are async throws and dispatch native work onto a background
thread. The underlying native client is thread-safe.
Example
Constructors
init(projectId:projectKey:)
| Parameter | Type | Description |
|---|---|---|
projectId | String | Your project identifier. |
projectKey | String | Your project authentication key. Prefer the Authenticator form for shipped apps so the key never ships in the binary. |
init(projectId:authenticator:baseUrl:)
Authenticator. Use this in shipped apps so the
long-lived project key stays on your backend.
| Parameter | Type | Description |
|---|---|---|
projectId | String | Your project identifier. |
authenticator | any Authenticator | Supplies a short-lived bearer token from your backend. |
baseUrl | String? | Optional override for the API base URL. |
Statics
sdkVersion
setModelCacheDir(_:)
<Library/Caches>/moss-models/ automatically
on first init. Call it before constructing your first client if you need a
custom location (e.g. a shared App Group container).
Methods
close()
deinit.
session(_:options:)
MossSession. Documents are embedded
locally with the bundled model (default moss-litelm on iOS) and queried
without a network round-trip. Configure with
SessionOptions.
createIndex(_:docs:modelId:)
modelId is nil the server picks a default ("custom" when documents
carry pre-computed embeddings). Returns a MutationResult.
| Parameter | Type | Description |
|---|---|---|
name | String | Name of the index to create. |
docs | [DocumentInfo] | Documents to index, optionally with pre-computed embeddings. |
modelId | String? | Embedding model id. nil selects the server default. |
getIndex(_:)
IndexInfo. Throws if the index does not exist.
listIndexes()
IndexInfo.
refreshIndex(_:)
RefreshResult describing
whether an update was applied.
loadIndex(_:options:)
LoadIndexOptions. Throws if the index does not
exist or loading fails.
| Parameter | Type | Description |
|---|---|---|
name | String | Name of the index to load. |
options | LoadIndexOptions | Cache path and auto-refresh configuration. |
query(::options:)
loadIndex(_:options:) first; querying an index that has
not been loaded throws. Configure with QueryOptions
and read matches from the returned SearchResult.
| Parameter | Type | Description |
|---|---|---|
indexName | String | Name of the loaded index to search. |
query | String | Search query text. |
options | QueryOptions | topK, alpha, and metadata filter. |
unloadIndex(_:)
query(_:_:options:) calls for that index throw until it is
loaded again.
addDocs(_:docs:upsert:)
MutationResult.
| Parameter | Type | Description |
|---|---|---|
name | String | Name of the target index. |
docs | [DocumentInfo] | Documents to add or update. |
upsert | Bool | Update documents that already share an id. Default true. |
getDocs(_:docIds:)
docIds to fetch specific
documents; omit it to fetch all of them. Returns an array of
DocumentInfo.
deleteDocs(_:docIds:)
MutationResult.
| Parameter | Type | Description |
|---|---|---|
name | String | Name of the target index. |
docIds | [String] | Ids of the documents to delete. |
getJobStatus(_:)
MossSession.pushIndex. Poll until status is
ready. Returns a JobStatus.
deleteIndex(_:)
MossSession.pushIndex) and all its data. Returns
true if deleted.
onMemoryPressure(_:)
UIApplication.didReceiveMemoryWarningNotification. Returns the
number of indexes freed. See MemoryPressureLevel.