libmoss API is split across two opaque handles, MossClient and
MossSession. Every fallible function returns a MossResult code and writes
its output through an out-parameter. See Getting started
for build and link instructions.
Include the header and link against libmoss:
MossClient
The entry point. Construct it with your project credentials, then manage cloud indexes, load an index for querying, or open sessions.Signatures
Load before you query.
moss_client_query runs against an index that is
already loaded into memory. Call moss_client_load_index first, then
moss_client_query. Querying a cloud index that has not been loaded is not
supported.moss_client_unload_index. To pick up changes pushed since the index was
loaded, call moss_client_refresh_index.
model_id on create
moss_client_create_index takes a model_id argument. Pass NULL for the
default model, or a model id such as "moss-mediumlm". The "custom" model is
not supported for cloud index creation.
MossSession
A local index. Add and query documents on the same machine, persist them, and sync with the cloud. Session queries run locally on the session, so no load step is needed before querying.Signatures
moss_session_name returns a pointer owned by the session - it is valid for the
lifetime of the session and must not be freed.
moss_session_load_index accepts an optional MossLoadIndexOptions. When
opts.auto_refresh is set, the session polls the cloud index every
opts.polling_interval_secs and pulls newer versions in on the next
moss_session_query, moss_session_get_docs, or moss_session_doc_count.
Auto-refresh pauses while the session has un-pushed local edits (after
moss_session_add_docs / moss_session_delete_docs, until
moss_session_push_index), so it never clobbers local work. Pass NULL for the
default behavior (no auto-refresh).
Memory management
These rules govern literal C memory (malloc / free) ownership across the C
ABI.
Rule: every pointer returned by libmoss through an out-parameter must be
freed with the matching moss_free_*() function.
Free signatures:
MossClient and MossSession
handles themselves are freed with moss_client_free and moss_session_free.
Error handling
Every fallible function returns aMossResult (int32_t):
OK(0) means success.- Negative values are errors.
moss_last_error() to get a human-readable message for the most recent
failed moss_* call on the current thread. The returned pointer is valid until
the next moss_* call on the same thread, and is NULL if no error is stored.
Do not free it.
Thread safety
MossClient and MossSession handles are internally mutex-protected and may be
shared across threads safely. Concurrent calls on the same handle serialize.
Do not free a MossClient or MossSession handle while another thread is still
using it.
Metadata filters
Pass filters as a JSON string throughMossQueryOptions.filter_json. A
single-field filter has the shape:
$and / $or:
Operators
The same filter format applies to
moss_session_query and moss_client_query.
See Examples for runnable filter usage.
Query options
MossQueryOptions controls result count, the semantic/keyword blend, and
filtering:
NULL for the whole options struct to use defaults. alpha blends dense
(semantic) and sparse (keyword) scoring; 1.0 is pure semantic, 0.0 is pure
keyword. Set embedding / embedding_dim only when the session or index uses
the custom model.