Skip to main content
moss v1.4.0 moss / SessionIndex

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.
# Auto-loads from cloud if the index exists, starts fresh if not
session = await client.session(index_name="session-abc")

await session.add_docs([DocumentInfo(id="1", text="Customer asked about billing")])
results = await session.query("billing question")

result = await session.push_index()
# optionally: await client.get_job_status(result.job_id)

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

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

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

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