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 semantic0.0- pure keyword0.8- default (semantic-heavy)
alpha against your eval set to find the blend that maximizes recall for
your data.
Metadata filtering
Attach metadata when you add documents:filterJson - a JSON string
describing the filter. A single-field filter has the shape:
$and / $or:
Operators
| Operator | Meaning | Example value |
|---|---|---|
$eq / $ne | equals / not equals | "shoes" |
$gt / $gte / $lt / $lte | numeric comparisons (values are strings) | "100" |
$in / $nin | in / not in a list | ["new-york", "seattle"] |
$near | within a radius of a point, "lat,lng,radiusMeters" | "40.7580,-73.9855,5000" |
$and / $or | combine clauses | array of clauses |
Examples
Swift raw string literals (#"..."#) let you write the JSON without escaping
quotes:
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 withmodelId: "custom". Moss then skips on-device embedding and you supply the
vectors yourself - both when adding documents and when querying:
Fetch by id
To pull specific documents back (for example, to follow references between records), usegetDocs: