Moss.Client (moss v1.1.0)

Copy Markdown

High-level entry point for the moss Elixir SDK.

Counterpart to MossClient in the Python SDK.

Example:

{:ok, client} = Moss.Client.new("project-id", "project-key")

# Cloud CRUD
{:ok, result} = Moss.Client.create_index(client, "my-index", docs)
{:ok, info}   = Moss.Client.get_index(client, "my-index")

# Load and query a cloud index locally
{:ok, _}       = Moss.Client.load_index(client, "faq-index")
{:ok, results} = Moss.Client.query(client, "faq-index", "cancel")

# Session workflow with built-in embeddings
{:ok, session} = Moss.Client.session(client, "session-abc")
{:ok, {2, 0}}  = Moss.Session.add_docs(session, docs)
{:ok, result}  = Moss.Session.query(session, "billing issue")
{:ok, _}       = Moss.Session.push_index(session)

# Custom models still use explicit embeddings
{:ok, custom_session} = Moss.Client.session(client, "custom-session", model_id: "custom")
{:ok, {1, 0}} = Moss.Session.add_docs(custom_session, docs)
{:ok, custom_result} = Moss.Session.query(custom_session, "billing issue", embedding: my_vec)

Summary

Functions

Add documents to an existing cloud index.

Create a cloud index with initial documents.

Create an index from raw files via the server-side parse pipeline.

Delete documents by IDs from a cloud index.

Delete a cloud index.

Get documents from a cloud index.

Get metadata for a cloud index.

Get metadata for a loaded index.

Poll the status of an async job.

Check if an index is loaded.

List all cloud indexes for this project.

Load a cloud index into memory.

Create a new Moss.Client.

Query a locally loaded index.

Force an immediate refresh of a loaded index from the cloud.

Create or resume a local session index.

Unload an index from memory.

Types

t()

@type t() :: %Moss.Client{
  client_id: String.t(),
  device_id: String.t() | nil,
  manage_ref: reference(),
  manager_pid: pid(),
  project_id: String.t(),
  project_key: String.t()
}

Functions

add_docs(client, name, docs, opts \\ [])

@spec add_docs(t(), String.t(), [Moss.DocumentInfo.t()], keyword()) ::
  {:ok, Moss.MutationResult.t()} | {:error, String.t()}

Add documents to an existing cloud index.

Options:

  • :upsert (boolean, default nil — use server default)

create_index(client, name, docs, model_id \\ "moss-minilm")

@spec create_index(t(), String.t(), [Moss.DocumentInfo.t()], String.t()) ::
  {:ok, Moss.MutationResult.t()} | {:error, String.t()}

Create a cloud index with initial documents.

create_index_from_files(client, name, files, model_id \\ "moss-minilm", parse_options \\ nil)

@spec create_index_from_files(
  t(),
  String.t(),
  [map()],
  String.t(),
  map() | nil
) :: {:ok, Moss.MutationResult.t()} | {:error, String.t()}

Create an index from raw files via the server-side parse pipeline.

Each file in files is a map with all three keys required:

  • :path — filesystem path
  • :name — filename sent to the server
  • :content_type — MIME type

model_id defaults to "moss-minilm". Must be a built-in model. "custom" is not supported because the parse pipeline generates embeddings server-side.

At most 20 files per call.

parse_options is an optional map controlling extraction. Omitted keys use the server defaults:

  • :ocr_mode: "auto_ocr" or "full_ocr". Use "full_ocr" for scanned documents with no text layer.
  • :segmentation_method: "smart_layout_detection" or "page_by_page"
  • :use_high_resolution: boolean, slower but better on dense tables
  • :merge_tables: boolean, join tables split across a page break

Supported content types: "application/pdf" and the DOCX MIME "application/vnd.openxmlformats-officedocument.wordprocessingml.document".

Example:

{:ok, result} = Moss.Client.create_index_from_files(
  client,
  "my-index",
  [
    %{
      name: "report.pdf",
      content_type: "application/pdf",
      path: "/docs/report.pdf"
    },
    %{
      name: "manual.docx",
      content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
      path: "/docs/manual.docx"
    }
  ],
  "moss-minilm",
  %{ocr_mode: "full_ocr"}
)

delete_docs(client, name, doc_ids)

@spec delete_docs(t(), String.t(), [String.t()]) ::
  {:ok, Moss.MutationResult.t()} | {:error, String.t()}

Delete documents by IDs from a cloud index.

delete_index(client, name)

@spec delete_index(t(), String.t()) :: {:ok, boolean()} | {:error, String.t()}

Delete a cloud index.

get_docs(client, name, opts \\ [])

@spec get_docs(t(), String.t(), keyword()) ::
  {:ok, [Moss.DocumentInfo.t()]} | {:error, String.t()}

Get documents from a cloud index.

Options:

  • :doc_ids (list of strings) — if provided, only fetch those docs

get_index(client, name)

@spec get_index(t(), String.t()) :: {:ok, Moss.IndexInfo.t()} | {:error, String.t()}

Get metadata for a cloud index.

get_index_info(client, name)

@spec get_index_info(t(), String.t()) ::
  {:ok, Moss.IndexInfo.t()} | {:error, String.t()}

Get metadata for a loaded index.

get_job_status(client, job_id)

@spec get_job_status(t(), String.t()) ::
  {:ok, Moss.JobStatusResponse.t()} | {:error, String.t()}

Poll the status of an async job.

has_index(client, name)

@spec has_index(t(), String.t()) :: boolean()

Check if an index is loaded.

list_indexes(client)

@spec list_indexes(t()) :: {:ok, [Moss.IndexInfo.t()]} | {:error, String.t()}

List all cloud indexes for this project.

load_index(client, name, opts \\ [])

@spec load_index(t(), String.t(), keyword()) ::
  {:ok, Moss.IndexInfo.t()} | {:error, String.t()}

Load a cloud index into memory.

Options:

  • :auto_refresh (boolean, default false)
  • :polling_interval (integer seconds, default 600)

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

new(project_id, project_key, opts \\ [])

@spec new(String.t(), String.t(), keyword()) :: {:ok, t()} | {:error, String.t()}

Create a new Moss.Client.

The index API URL is resolved from the MOSS_INDEX_URL environment variable (falls back to the default cloud endpoint). No URL option is needed.

query(client, name, query_text, opts \\ [])

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

Query a locally loaded index.

For built-in models, the query is embedded automatically. For indexes created with 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}.

refresh_index(client, name)

@spec refresh_index(t(), String.t()) ::
  {:ok, Moss.RefreshResult.t()} | {:error, String.t()}

Force an immediate refresh of a loaded index from the cloud.

session(client, index_name, opts \\ [])

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

Create or resume a local session index.

If a cloud index with index_name already exists, it is silently loaded into the session. If not, the session starts empty.

Options:

  • :model_id (String.t(), default "moss-minilm")
  • :server_name — GenServer name for the Session process

Returns {:ok, pid} on success.

unload_index(client, name)

@spec unload_index(t(), String.t()) :: {:ok, :ok} | {:error, String.t()}

Unload an index from memory.