Skip to main content

Moss session manager for the TEN Framework

Project description

ten-moss

A Moss session manager for the TEN Framework, powered by Moss.

MossSessionManager wraps a Moss session — a local, in-process index (~1–10ms, no cloud round-trip) — and mirrors the Moss Sessions SDK (open, add_docs, get_docs, delete_docs, push_index, doc_count). It adds one convenience for grounding: query_context(text) returns an injection-ready context block (not a raw SearchResult), and degrades to an empty string on no-hit/error so the voice loop never stalls.

A full runnable TEN voice-assistant example ships in the companion apps/ten-moss/ app (see the app PR / the apps/ten-moss/ directory once both land on main).

Install

pip install ten-moss   # or: uv add ten-moss

Usage

from ten_moss import DocumentInfo, MossSessionManager

session = MossSessionManager(
    project_id="...", project_key="...", index_name="support-docs",
    top_k=5, alpha=0.8,
)
await session.open()                             # open the session (create-or-resume)
context = await session.query_context(user_text) # per turn; "" on no hits/error
# optional: write runtime context, then persist for handoff
await session.add_docs([DocumentInfo(id="turn-1", text=user_text)])
await session.push_index()

Or build it from TEN properties:

from ten_moss import MossSessionConfig, MossSessionManager

config = MossSessionConfig(**props)                # moss_* fields from property.json
session = MossSessionManager.from_config(config)

Public API (MossSessionManager)

Method Purpose
await open() Open the Moss session (create-or-resume the index)
await query_context(text) -> str Grounding block for this turn; "" on blank/no-hit/error
await add_docs(docs) Add/update documents in the session (mirrors SessionIndex.add_docs)
await get_docs() Documents currently in the session
await delete_docs(ids) Delete documents from the session by id
await push_index() Persist the session to the cloud (durability / handoff)
doc_count Number of documents in the session
last_time_taken_ms Engine-measured retrieval time (ms) from the last query_context (SearchResult.time_taken_ms); None before the first query / on error

When built with enable_moss=false, no client is created and every method is a safe no-op.

Configuration (MossSessionConfig)

Field Default Meaning
moss_project_id "" Moss project id
moss_project_key "" Moss project key (stored as a masked SecretStr)
moss_index_name "" session index to open (create-or-resume)
moss_model_id "" embedding model; empty = adopt the stored index's model (or the SDK default for a new index). "custom" is rejected — it needs a query embedding this manager can't supply.
moss_top_k 5 results per query (must be > 0)
moss_alpha 0.8 semantic/keyword blend, 0.0–1.0 (1.0 semantic, 0.0 keyword)
moss_context_header "Relevant knowledge from Moss:" header of the injected block
moss_max_context_chars 2000 cap on the injected grounding block (0 = unlimited)
enable_moss true master toggle

moss_top_k, moss_alpha, and moss_max_context_chars are validated at construction — an out-of-range value raises a clear error instead of failing later.

Create a demo index

The example loads .env via python-dotenv if it's installed; otherwise export the variables directly.

pip install ten-moss python-dotenv     # python-dotenv is only needed for .env loading
cp .env.example .env                   # fill in your Moss credentials
python examples/create_index.py
# — or, without python-dotenv —
export MOSS_PROJECT_ID=... MOSS_PROJECT_KEY=... MOSS_INDEX_NAME=...
python examples/create_index.py

Development

uv sync
uv run pytest tests/ -v
uv run ruff check .

Tests are offline (the Moss client is mocked) — no credentials required.

License

BSD-2-Clause.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ten_moss-0.1.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ten_moss-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file ten_moss-0.1.0.tar.gz.

File metadata

  • Download URL: ten_moss-0.1.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ten_moss-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5939ba5486c3eabeb170855cd8f0fb87bff481b184808d800e769aa9cc532b6d
MD5 ee1d95affc23af2c7927be447c33e8a9
BLAKE2b-256 5ec56b71765a0c987e30a1b6124db92e8165a5067d7d3a6da0295bda6cb3b08d

See more details on using hashes here.

File details

Details for the file ten_moss-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ten_moss-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ten_moss-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cf6a6afa64f9b4bf13cd645e5b2fcc5a304716c207836c31b4c2bc3ccec3206
MD5 620e7d263f56137dec6a78f2ae013442
BLAKE2b-256 f4c3b38217fc8d01459800eb1cbb1105a6de5030845f5fe92a6b349ebbaedb10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page