About DSPy
DSPy replaces hand-written prompts with compiled, optimized LLM programs. The dspy-moss package provides MossRM, a retriever module that plugs into dspy.Retrieve to give DSPy programs sub-10ms semantic search. MossRM also works as a ReAct agent tool, letting DSPy agents autonomously decide when to search.
Why Use Moss with DSPy
01
Drop-in Retriever
MossRM extends dspy.Retrieve - use as a drop-in retriever in any DSPy program
02
Sub-10ms Retrieval
Sub-10ms retrieval for DSPy RAG pipelines, ChainOfThought, and MultiHop programs
03
Agent Tool Calling
moss_search function for ReAct agent tool calling: agents decide when to search
04
Hybrid Search
Hybrid search via alpha parameter blends semantic and BM25 keyword matching
05
DSPy Optimizers
Works with DSPy optimizers like BootstrapFewShot and MIPRO for compiled retrieval programs
Quick Start
import dspy
from dspy_moss import MossRM
rm = MossRM(index_name="my-index")
rm.load_index()
dspy.configure(lm=dspy.LM("openai/gpt-4o"), rm=rm)
retrieve = dspy.Retrieve(k=3)
result = retrieve("What is the refund policy?")
for passage in result.passages:
print(f"[{passage['score']:.3f}] {passage['long_text']}")Get Started in 3 Steps
01
Install dependencies
Run pip install dspy-moss to set up your environment.
02
Create a MossRM retriever
Initialize MossRM with your index name, call load_index(), then register it with dspy.configure(rm=...).
03
Use in DSPy programs
Call dspy.Retrieve(k=3) in your DSPy modules. MossRM handles the search. For agentic use, pass moss_search as a ReAct tool.
Frequently asked questions
Ready to ship faster AI products?
Moss gives you production-ready semantic retrieval without infrastructure complexity.