Skip to main content
The Moss JavaScript SDK (@moss-js/moss) brings semantic search to Node.js. It wraps a high-performance Rust core and exposes an async, Promise-based API. Documents are embedded and queried locally, with optional cloud sync.

Requirements

  • Node.js 20.4 or higher

Install

Keep optional dependencies on. The native binary comes only from the @moss-js/moss-core-<platform> package that npm installs for your platform as an optional dependency. After npm install --omit=optional, optional=false in .npmrc or pnpm --no-optional, importing @moss-js/moss throws Cannot find native binding. The same happens on npm ci from a lockfile that npm older than 11.3 rebuilt while node_modules existed, because that lockfile keeps only that machine’s platform package. Before installing on another platform, such as Linux CI or Docker from a lockfile made on a Mac, regenerate the lockfile with node_modules removed, or with npm 11.3 or newer. (@moss-js/moss 1.17.0+)
Versions below 1.9.0 will stop loading models when the legacy download path is retired. Upgrade to 1.9.0+ before then.
Moss for Node moved from @moss-dev/moss to @moss-js/moss with 1.8.0. @moss-dev/moss is a frozen 1.7.1 package. Versions below 1.9.0 will stop loading models when the legacy download path is retired. Upgrade to @moss-js/moss 1.9.0+ before then. The date will be announced in the changelog. @moss-dev/moss-web is the browser SDK and is not this package.
Get your projectId and projectKey from the Moss portal.
  • MossClient - the entry point. Manage cloud indexes, load one into memory, and query it.
  • SessionIndex - a local, in-process index for real-time indexing during a live interaction; push to the cloud when done.

Quick start

Indexes

Create, inspect, and delete cloud indexes. Mutations run as async jobs and return a MutationResult with a jobId and docCount.

Index from files

Build an index straight from PDF and DOCX files - the server parses, chunks, and embeds them. Up to 20 files per call.
See Index from files.

Documents

Add, update, fetch, and remove documents on an existing index.

Load and query

Load an index into memory, then query it in-process. Call loadIndex before querying.
Blend semantic and keyword scoring with alpha (1.0 = semantic, 0.0 = keyword; default 0.8).
See Hybrid search.

Metadata filtering

Narrow results by document metadata on a loaded index.
Operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $near, composed with $and / $or. See Metadata filtering.

Custom embeddings

Supply your own vectors with modelId: 'custom' (each document carries embedding, and queries pass embedding).
See Custom embeddings.

Sessions

Index and query locally in real time with a SessionIndex, then push to the cloud. session() starts empty; session.loadIndex(name) resumes an existing cloud index.
See Sessions.

Keeping indexes fresh

Auto-refresh a loaded index (poll the cloud and hot-swap newer versions in automatically), and track async jobs.

Authentication

Construct the client with a projectKey for server-side use, or use a custom authenticator to mint short-lived tokens for untrusted clients (getAuthToken()).
See Custom Authenticator.

Errors

A failure from the native core rejects with an Error whose code is a stable MossErrorCode, such as NOT_FOUND or NETWORK. Branch on code, not on the message. isMossError narrows a caught value, and loadIndexes reports each failed name’s code in failedCodes. Some checks the SDK makes itself, such as a closed client, throw a plain Error with no code. (@moss-js/moss 1.16.0+)
See Error codes.

Models

  • moss-minilm (default) - fast, lightweight
  • moss-mediumlm - higher accuracy
  • custom - supply your own embedding vectors via DocumentInfo.embedding

Guides

Reference

MossClient and SessionIndex, plus all interfaces and types, are in the Reference section of the sidebar.