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

Requirements

  • Python 3.10 or higher

Install

Versions below 1.9.0 will stop loading models when the legacy download path is retired. Upgrade to 1.9.0+ before then.
Get your project credentials 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 job_id and doc_count.

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.

JSON, files and chunking

create_index, add_docs and SessionIndex.add_docs also take dicts, JSON array or JSON Lines text, and .json, .jsonl, .ndjson, .txt, .md and .markdown files as pathlib.Path objects. Text and markdown files are chunked into documents {path}#{n} with metadata parentId. Tune that with chunking=Chunking(...), or split text yourself with chunker=. (moss 1.18.0+)
Chunking, DocsInput and Chunker are exported from moss. See Chunking.

Load and query

Load an index into memory, then query it in-process. Call load_index 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 model_id="custom" (each document carries embedding, and queries pass embedding).
See Custom embeddings. Query several loaded indexes in one call; each result is tagged with its source index_name.
See Multi-index search.

Sessions

Index and query locally in real time with a SessionIndex, then push to the cloud. session() resumes an existing cloud index by name, or starts empty.
Save a session to disk and restore it in a later run with no index download. (moss 1.16.0+)
See Sessions.

Keeping indexes fresh

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

Errors

Every failure the native core reports raises MossError, a RuntimeError whose code is a stable string such as "NOT_FOUND" or "NETWORK". Branch on code, not on the message. InvalidArgumentError is the INVALID_ARGUMENT subclass and is also a ValueError. load_indexes reports each failed name’s code in failed_codes. Checks the SDK makes before calling the core, such as a closed client, raise plain Python exceptions with no code. (moss 1.15.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.