Skip to main content
Use dspy-moss to add Moss semantic search to DSPy programs. The package provides MossRM, a DSPy retrieval model (RM) that plugs into DSPy’s retrieval interface for sub-10ms knowledge retrieval after the index is loaded locally.

Why use Moss with DSPy?

DSPy’s retrieval modules connect external knowledge sources to composable LLM programs. Moss provides a standard retriever backed by an in-memory semantic search runtime, so dspy.Retrieve, RAG modules, and ReAct agents can query your knowledge base without managing a vector database.

Required tools

  • Moss project credentials from the Moss Portal
  • Python 3.10+
  • A DSPy-compatible LLM provider

Integration guide

1

Install

2

Configure credentials

MossRM can create its own MossClient from environment variables.
3

Use as DSPy's default retriever

Create a MossRM, load the index into local memory, and register it with dspy.configure().
4

Use inside a RAG module

Any dspy.Retrieve() in your program now uses Moss.
5

Use as a ReAct tool

MossRM.forward() is synchronous, so you can pass the retriever instance directly to a DSPy ReAct agent.

Configuration

MossRM

Passage format

Each entry in result.passages is a dictionary:

Mutable index helpers

MossRM also exposes helpers for agents that read or update the knowledge base: