skills/dspy-embedding-retrieval/SKILL.md
This skill should be used when the user asks to "build local DSPy retrieval", "use dspy.Embedder", "use dspy.Embeddings", "save an embeddings index", "add FAISS retrieval", mentions semantic search, hosted embeddings, local embedding models, `EmbeddingsWithScores`, or needs a DSPy retriever over an application-owned text corpus.
npx skillsauth add omidzamani/dspy-skills dspy-embedding-retrievalInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Build semantic retrieval over an application-owned text corpus with dspy.Embedder and dspy.Embeddings.
import dspy
corpus = [
"DSPy programs are composed from modules.",
"MIPROv2 optimizes instructions and demonstrations.",
"RLM explores large contexts with a sandboxed REPL.",
]
embedder = dspy.Embedder("openai/text-embedding-3-small")
search = dspy.Embeddings(corpus=corpus, embedder=embedder, k=2)
result = search("Which optimizer tunes prompts?")
print(result.passages)
print(result.indices)
class LocalRAG(dspy.Module):
def __init__(self, retriever):
super().__init__()
self.retriever = retriever
self.answer = dspy.ChainOfThought("context: list[str], question -> answer")
def forward(self, question: str):
context = self.retriever(question).passages
return self.answer(context=context, question=question)
Wrap any callable that accepts list[str] and returns a 2D numeric array:
from sentence_transformers import SentenceTransformer
import dspy
model = SentenceTransformer("sentence-transformers/static-retrieval-mrl-en-v1")
embedder = dspy.Embedder(model.encode)
search = dspy.Embeddings(corpus=corpus, embedder=embedder, k=5)
Use dspy.EmbeddingsWithScores when downstream logic needs similarity thresholds or reranking.
For corpora at or above the brute_force_threshold default of 20_000, DSPy builds a FAISS index. Install FAISS first:
pip install faiss-cpu
Persist the index when embedding the corpus is expensive:
search.save("./retrieval-index")
loaded = dspy.Embeddings.from_saved("./retrieval-index", embedder=embedder)
EmbeddingsWithScores when debugging relevance.tools
This skill should be used when the user asks to "optimize with SIMBA", "use mini-batch introspective optimization", "generate self-reflective rules", mentions "SIMBA optimizer", "stochastic mini-batch ascent", "output variability", or needs an alternative to MIPROv2/GEPA that evolves rules and demonstrations from numeric metrics.
data-ai
This skill should be used when the user asks to "create a DSPy signature", "define inputs and outputs", "design a signature", "use InputField or OutputField", "add type hints to DSPy", mentions "signature class", "type-safe DSPy", "Pydantic models in DSPy", or needs to define what a DSPy module should do with structured inputs and outputs.
development
This skill should be used when the user asks to "use DSPy RLM", "process a very long context", "use ProgramOfThought", "use CodeAct", "run DSPy modules in parallel", mentions Recursive Language Models, sandboxed Python execution, Deno, `dspy.RLM`, `dspy.ProgramOfThought`, `dspy.CodeAct`, or `dspy.Parallel`, or needs to choose a DSPy reasoning module beyond Predict, ChainOfThought, and ReAct.
tools
This skill should be used when the user asks to "create a ReAct agent", "build an agent with tools", "implement tool-calling agent", "use dspy.ReAct", mentions "agent with tools", "reasoning and acting", "multi-step agent", "agent optimization with GEPA", or needs to build production agents that use tools to solve complex tasks.