Skip to main content
The Moss Elixir SDK (moss on Hex.pm) brings semantic search to Elixir applications. Documents are embedded and queried on-device through a high-performance Rust core, with optional cloud sync. The SDK ships built-in embedding models, hybrid (semantic + keyword) search, and per-session indexing for real-time workflows.

Requirements

  • Elixir 1.15 or higher
  • OTP 26 or higher
  • Valid Moss project credentials (project_id and project_key)

Install

Add moss to your dependencies in mix.exs:
Then fetch it:
Sign up at the Moss portal to get your project_id and project_key. The Elixir SDK exposes two entry points:
  • Moss.Client - the entry point. Construct it with your credentials, manage cloud indexes, and load indexes into memory for fast local querying.
  • Moss.Session - a local, in-session index. Index documents in memory during a live workflow with no cloud round trips, then push to the cloud when done.

Load before query

Querying always runs against an index that has been loaded into memory. Call Moss.Client.load_index/3 first, then Moss.Client.query/4. Queries run entirely in-memory with no network round trip. There is no query path that runs without first loading the index (or opening a session).

Quick start

Create a client, create and populate a cloud index, load it, and query:

Sessions

For real-time indexing during live workflows (voice AI agents, chat), open a session. Documents are indexed in memory with no cloud round trip, and you can push the index to the cloud when done:
To keep a session on the device, save it with Moss.Session.save_to_disk/2 and restore it in a later run with Moss.Session.load_from_disk/3. Open the restoring session with auto_load_on_init: false so it downloads no index. (Elixir moss 1.6.0+)

Models

Two built-in embedding models run entirely in the Rust core:
  • moss-minilm - lightweight, optimized for speed (the default).
  • moss-mediumlm - higher accuracy with reasonable performance.
Pass model_id: "custom" to supply your own pre-computed embeddings via DocumentInfo.embedding. With a custom model, each document must set embedding, and queries must pass an embedding: option.

Errors

Every {:error, reason} from the SDK carries a %Moss.Error{}. Match on its code atom, such as :not_found or :network, not on the message. detail holds the native error text for logs, and load_indexes/3 reports each failed name’s code in failed_codes. The one exception is Moss.Client.session/3 with a :server_name that is already registered, which returns GenServer’s {:error, {:already_started, pid}}. (Elixir moss 1.5.0+)
See Error codes.

Reference