dspy-retrieval
Installation
SKILL.md
Retrieval Modules in DSPy
Guide the user through DSPy's retrieval modules for searching documents, computing embeddings, and building RAG (retrieval-augmented generation) pipelines.
Step 1: Gather context
Before building retrieval into a DSPy program, clarify:
- What are you searching over? Your own documents, a knowledge base, an external corpus like Wikipedia?
- How large is the corpus? A few hundred docs (in-memory FAISS works) vs. millions (need a dedicated vector store like Pinecone, Qdrant, or Chroma)?
- Do you already have a search backend? If you have Elasticsearch, Pinecone, or another store, subclass
dspy.Retrieveto wrap it. If not, usedspy.retrievers.Embeddingsfor a local solution. - Single-hop or multi-hop? Simple questions need one retrieval step. Compositional questions (e.g., "Where was the designer of the Eiffel Tower born?") need chained retrieval.
What retrieval modules are
DSPy provides retrieval modules that fetch relevant documents or passages given a query. These modules plug into DSPy programs just like dspy.Predict or dspy.ChainOfThought -- declare them in __init__, call them in forward(), and optimizers handle the rest.
There are four key components: