SessionIndex
A local, in-session index for real-time indexing and querying. All operations (add_docs, delete_docs, query) run entirely in-memory with no
cloud round trips (~1-10 ms). Open a session with
MossClient.session(), which auto-loads an
existing cloud index by name or starts empty. Call push_index() at the end of the
session to persist the index to the cloud for future retrieval.
Properties
- name (
str): The index name. - doc_count (
int): Number of documents in the local session index.
Methods
add_docs(docs, options)
Add or update documents in the local session index. Embeddings are generated locally
via the Rust core - no cloud round trip. When the session uses model_id="custom", each
document must have .embedding set.
Parameters
- docs (List[
DocumentInfo]) - options (Optional[
MutationOptions] =None)
Returns
Tuple[int, int] - (added_count, updated_count)
delete_docs(doc_ids)
Delete documents from the local session index by their IDs.
Parameters
- doc_ids (
List[str])
Returns
int - the number of documents deleted.
get_docs(options)
Retrieve documents from the local session index.
Parameters
- options (Optional[
GetDocumentsOptions] =None)
Returns
List[DocumentInfo]
query(query, options)
Perform a semantic search over the local session index. Runs entirely in-memory
(~1-10 ms) with no cloud call. Supports the same metadata filter syntax as
MossClient.query().
When the session uses model_id="custom", provide a query embedding via
QueryOptions.embedding.
Parameters
- query (
str) - options (Optional[
QueryOptions] =None)
Returns
SearchResult
push_index()
Push the local session index to the cloud. Sends all documents with their
locally-computed embeddings to the backend; the cloud index is created or replaced if
one already exists with the same name. No server-side re-embedding occurs.
Returns
PushIndexResult