Moss.Session (moss v1.1.0)

Copy Markdown

Local in-session index — index documents in memory during a session and query them with no cloud round trips.

Sessions are opened via Moss.Client.session/3, which handles credentials and auto-loading from the cloud:

{:ok, session} = Moss.Client.session(client, "session-abc", model_id: "moss-minilm")

docs = [%Moss.DocumentInfo{id: "1", text: "hello"}]
{:ok, {1, 0}} = Moss.Session.add_docs(session, docs)

{:ok, result} = Moss.Session.query(session, "hello")
{:ok, push_result} = Moss.Session.push_index(session)

For model_id: "custom", each document must have .embedding set and query/3 requires embedding: [...] in opts.

Summary

Functions

Add documents to the session index.

Delete documents by IDs. Returns the count deleted.

Number of documents in the session index.

Get documents from the index.

Load an existing cloud index into this session.

The index name.

Push the local session index to the cloud.

Query the session index.

Functions

add_docs(pid, docs, opts \\ [])

@spec add_docs(GenServer.server(), list(), keyword()) ::
  {:ok, {non_neg_integer(), non_neg_integer()}} | {:error, String.t()}

Add documents to the session index.

For built-in models ("moss-minilm", "moss-mediumlm"), embeddings are computed automatically in Rust. For model_id: "custom", each document must have .embedding set.

Options:

  • :upsert (boolean, default true)

Returns {:ok, {added, updated}} or {:error, reason}.

delete_docs(pid, doc_ids)

@spec delete_docs(GenServer.server(), [String.t()]) :: non_neg_integer()

Delete documents by IDs. Returns the count deleted.

doc_count(pid)

@spec doc_count(GenServer.server()) :: non_neg_integer()

Number of documents in the session index.

get_docs(pid, opts \\ [])

@spec get_docs(
  GenServer.server(),
  keyword()
) :: [Moss.DocumentInfo.t()]

Get documents from the index.

Options:

  • :doc_ids (list of strings)

load_index(pid, index_name)

@spec load_index(GenServer.server(), String.t()) ::
  {:ok, non_neg_integer()} | {:error, String.t()}

Load an existing cloud index into this session.

Returns {:ok, doc_count} or {:error, reason}.

name(pid)

@spec name(GenServer.server()) :: String.t()

The index name.

push_index(pid)

@spec push_index(GenServer.server()) ::
  {:ok, Moss.PushIndexResult.t()} | {:error, String.t()}

Push the local session index to the cloud.

Returns {:ok, Moss.PushIndexResult.t()} or {:error, reason}.

query(pid, query_text, opts \\ [])

@spec query(GenServer.server(), String.t(), keyword()) ::
  {:ok, Moss.SearchResult.t()} | {:error, String.t()}

Query the session index.

For built-in models, the query is embedded automatically in Rust. For model_id: "custom", pass the query embedding via embedding: [...].

Options:

  • :top_k (integer, default 5)
  • :alpha (float, default 0.8)
  • :filter (map)
  • :embedding (list of floats, required for model_id: "custom")

Returns {:ok, Moss.SearchResult.t()} or {:error, reason}.