Skip to main content
Swift SDK / Querying MossSession.query takes a QueryOptions that controls result count, the semantic/keyword blend, and metadata filtering.

Result count

topK caps how many documents come back (default 5).

Hybrid search (alpha)

alpha blends dense (semantic) and sparse (keyword) scoring:
  • 1.0 - pure semantic
  • 0.0 - pure keyword
  • 0.8 - default (semantic-heavy)
Sweep alpha against your eval set to find the blend that maximizes recall for your data.

Metadata filtering

Attach metadata when you add documents:
Prefer the typed Filter DSL over hand-written JSON — set QueryOptions.filter (e.g. .equals("category", "shoes")) and skip the escaping. See the Filter DSL. The filterJson string below remains supported as an escape hatch.
Then restrict a query to matching documents with filterJson - a JSON string describing the filter. A single-field filter has the shape:
Combine clauses with $and / $or:

Operators

Examples

Swift raw string literals (#"..."#) let you write the JSON without escaping quotes:
Each hit’s metadata is returned on QueryResult.metadata, so you can inspect or post-process the matched fields.

Custom embeddings

To use your own embedding model instead of the on-device one, open the session with modelId: "custom". Moss then skips on-device embedding and you supply the vectors yourself - both when adding documents and when querying:
All embeddings must share the same dimension, and query vectors must match it.

Fetch by id

To pull specific documents back (for example, to follow references between records), use getDocs:
For deterministic retrieval — exact fetch in a guaranteed order, metadata-only filtering, parent grouping, and verbatim payloads — see the Exact / Graph Retrieval guide.