dspy-haystack-integration
Use for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.
Skill by OmidZamani
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/omidzamani-dspy-haystack-integration
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
- Runs as
- Python package
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/dspy-haystack-integration
What's inside
- Skill name
dspy-haystack-integration- Description
- Use for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.
- License
- MIT
- Instructions
- 170 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Agent Skills spec issues
- allowed-tools: must be a space-separated string
Files (4)
- SKILL.md
- example.py
- haystack-dspy-optimizer.py · examples/
- prompt-extraction.md · references/
SKILL.md (first lines)
# DSPy + Haystack Integration
## Goal
Use DSPy's optimization capabilities to automatically improve prompts in Haystack pipelines.
## When to Use
- You have existing Haystack pipelines
- Manual prompt tuning is tedious
- Need data-driven prompt optimization
- Want to combine Haystack components with DSPy optimization
## Inputs
| Input | Type | Description |
|-------|------|-------------|
| `haystack_pipeline` | `Pipeline` | Existing Haystack pipeline |
| `trainset` | `list[dspy.Example]` | Training examples |
| `metric` | `callable` | Evaluation function |
## Outputs
| Output | Type | Description |
|--------|------|-------------|
| `optimized_prompt` | `str` | DSPy-optimized prompt |
| `optimized_pipeline` | `Pipeline` | Updated Haystack pipeline |
## Workflow
### Phase 1: Build Initial Haystack Pipeline
```python
from haystack import Pipeline
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.document_stores.in_memory import InMemoryDocumentStore
# Setup document store
doc_store = InMemoryDocumentStore()
doc_store.write_documents(documents)
# Initial generic prompt
initial_prompt = """
Context: {{context}}
Question: {{question}}
Answer:
"""
# Build pipeline
pipeline = Pipeline()
pipeline.add_component("retriever", InMemoryBM25Retriever(document_store=doc_store))
pipeline.add_component("prompt_builder", PromptBuilder(template=initial_prompt))
pipeline.add_component("generator", OpenAIGenerator(model="gpt-4o-mini"))
pipeline.connect("retriever", "prompt_builder.context")
pipeline.connect("prompt_builder", "generator")
```
### Phase 2: Create DSPy RAG Module
```python
import dspy
class HaystackRAG(dspy.Module):
"""DSPy module wrapping Haystack retriever."""
def __init__(self, retriever, k=3):
super().__init__()
self.retriever = retriever
self.k = k
self.generate = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
# Use Haystack retriever
results = self.retriever.run(query=question, top_k=self.k)
context = [doc.content for doc in results['documents']]
# Use DSPy for generation
pred = self.generate(context=context, question=question)
return dspy.Prediction(context=context, answer=pred.answer)
```
### Phase 3: Define Custom Metric
```python
from haystack.components.evaluators import SASEvaluator
# Haystack semantic evaluator
sas_evaluator = SASEvaluator(model="sentence-transformers/all-MiniLM-L6-v2")
def mixed_metric(example, pred, trace=None):
"""Combine semantic accuracy with conciseness."""
# Semantic similarity (Haystack SAS)
sas_result = sas_evaluator.run(
ground_truth_answers=[example.answer],
predicted_answers=[pred.answer]
)
semantic_score = sas_result['score']
# Conciseness penalty
word_count = len(pred.answer.split())
conciseness = 1.0 if word_count <= 20 else max(0, 1 - (word_count - 20) / 50)
return 0.7 * semantic_score + 0.3 * conciseness
```
### Phase 4: Optimize with DSPy
```python
from dspy.teleprompt import BootstrapFewShot
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)
# Create DSPy module with Haystack retriever
rag_module = HaystackRAG(retriever=pipeline.get_component("retriever"))From OmidZamani/dspy-skills, MIT.
More from OmidZamani/dspy-skills
- 0.668score
dspy-evaluation-suite
OmidZamani
Use for evaluating DSPy programs with Evaluate, answer_exact_match, SemanticF1, custom metrics, baselines, and program comparisons.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-adapters-multimodal
OmidZamani
Use for DSPy adapter selection, JSONAdapter, XMLAdapter, ChatAdapter, native function calling, structured outputs, and multimodal inputs like dspy.Image or…
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-advanced-module-composition
OmidZamani
Use for composing DSPy modules with Ensemble, MultiChainComparison, ensemble voting, sequential pipelines, and multi-program workflows.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-optimizer-selection
OmidZamani
Use to choose or compare DSPy optimizers including LabeledFewShot, BootstrapFewShot, MIPROv2, SIMBA, GEPA, BootstrapFinetune, Ensemble, and BetterTogether.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-production-deployment
OmidZamani
Use for deploying DSPy with save/load, configure_cache, restrict_pickle, track_usage, async execution, streaming, and production runtime controls.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-rag-pipeline
OmidZamani
Use for RAG pipelines, retrieval augmented generation, ColBERTv2, context retrieval, multi-hop RAG, and grounded DSPy answers.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-signature-designer
OmidZamani
Use for DSPy signatures, InputField, OutputField, typed inputs and outputs, signature classes, and Pydantic-style structured schemas.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-simba-optimizer
OmidZamani
Use for SIMBA optimization, mini-batch introspective optimization, self-reflective rules, stochastic ascent, and numeric-metric optimization.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-reasoning-modules
OmidZamani
Use for DSPy reasoning modules including RLM, ProgramOfThought, CodeAct, Parallel, sandboxed execution, and long-context workflows.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-custom-module-design
OmidZamani
Use for creating custom DSPy modules, extending dspy.Module, reusable components, stateful modules, serialization, and module testing.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-debugging-observability
OmidZamani
Use for debugging DSPy programs, inspect_history, tracing LLM calls, custom callbacks, observability, monitoring, and cost tracking.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-embedding-retrieval
OmidZamani
Use for DSPy retrieval with dspy.Embedder, dspy.Embeddings, FAISS indexes, semantic search, and local or hosted embedding models.
SkillCFreshness: C★ 124Claude Code +9
Signals
- Stars
- 124
- Forks
- 13
- Open issues
- 1
- Last commit (this folder)
- Jun 23, 2026 (4 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/OmidZamani/dspy-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from OmidZamani
- 0.668score
dspy-embedding-retrieval
OmidZamani
Use for DSPy retrieval with dspy.Embedder, dspy.Embeddings, FAISS indexes, semantic search, and local or hosted embedding models.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-advanced-module-composition
OmidZamani
Use for composing DSPy modules with Ensemble, MultiChainComparison, ensemble voting, sequential pipelines, and multi-program workflows.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-adapters-multimodal
OmidZamani
Use for DSPy adapter selection, JSONAdapter, XMLAdapter, ChatAdapter, native function calling, structured outputs, and multimodal inputs like dspy.Image or…
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-debugging-observability
OmidZamani
Use for debugging DSPy programs, inspect_history, tracing LLM calls, custom callbacks, observability, monitoring, and cost tracking.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-custom-module-design
OmidZamani
Use for creating custom DSPy modules, extending dspy.Module, reusable components, stateful modules, serialization, and module testing.
SkillCFreshness: C★ 124Claude Code +9 - 0.668score
dspy-finetune-bootstrap
OmidZamani
Use for BootstrapFinetune, fine-tuning DSPy models, teacher-student distillation, weight optimization, and lower-cost deployment.
SkillCFreshness: C★ 124Claude Code +9
Cite this page
dspy-haystack-integration skill. Agent Mart. https://agentmart.dev/skills/omidzamani-dspy-haystack-integration (last updated 2026-10-24)