Agent skill

Dspy Haystack Integration

by OmidZamani in OmidZamani/dspy-skills

A skill your agent uses for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.

MITAuto-check passedAI & LLM Engineering

Install Dspy Haystack Integration

skills CLI
$ npx skills add OmidZamani/dspy-skills --skill dspy-haystack-integration -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install OmidZamani/dspy-skills dspy-haystack-integration --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/OmidZamani/dspy-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/dspy-haystack-integration .claude/skills/dspy-haystack-integration && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
dspy-haystack-integration
GitHub stars
124
Used in
1 other repo
Token cost
~1.4k tokens
SKILL.md length
254 words
Files
4 (incl. references)
Skills in repo
17
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.

  • Works in 5 steps: Build Initial Haystack Pipeline → Create DSPy RAG Module → Define Custom Metric → …
  • Integrating DSPy with Haystack
  • SKILL.md covers Goal, When to Use, Inputs and Outputs, plus 5 more sections
  • Runs Python scripts from its folder

What it does

Dspy Haystack Integration is an agent skill from OmidZamani/dspy-skills. Use for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.

Its SKILL.md is about 1.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 5 other files, including reference files (for example `example.py`, `examples/haystack-dspy-optimizer.py` and `references/prompt-extraction.md`).

It sits in AI & LLM Engineering, covering Retrieval-augmented generation. The repository describes itself as: Collection of Claude Skills for DSPy framework - program language models, optimize prompts, and build RAG pipelines systematically. The licence is MIT.

When your agent uses it

  • Integrating DSPy with Haystack
  • Optimizing Haystack prompts
  • Improving retrieval pipelines
  • Extracting DSPy prompts

Example prompts

  • “/dspy-haystack-integration”

Requirements

  • Python 3
  • Pre-approved tools (allowed-tools): Read, Write, Glob, Grep

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Build Initial Haystack Pipeline
  2. Create DSPy RAG Module
  3. Define Custom Metric
  4. Optimize with DSPy
  5. Extract and Apply Optimized Prompt

What it can do on your machine

Read from SKILL.md and the folder at commit f5db3b7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Glob
    • Grep

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Python), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • dspy.ai
    • github.com
    • docs.haystack.deepset.ai

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Dspy Haystack Integration loads about 1.4k tokens when it runs, and up to ~1.9k if it reads all its reference files. Until then it costs about 39 tokens; SKILL.md has 254 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~39
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from OmidZamani/dspy-skills at commit f5db3b7, republished under its MIT licence (© OmidZamani). 254 words, ~1,352 tokens.

Download SKILL.mdSave it as .claude/skills/dspy-haystack-integration/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.
name
dspy-haystack-integration
description
Use for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.
allowed-tools
Read, Write, Glob, Grep
version
1.0.0
dspy-compatibility
3.2.1
tags
retrieval, optimizer

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

InputTypeDescription
haystack_pipelinePipelineExisting Haystack pipeline
trainsetlist[dspy.Example]Training examples
metriccallableEvaluation function

Outputs

OutputTypeDescription
optimized_promptstrDSPy-optimized prompt
optimized_pipelinePipelineUpdated 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"))

# Optimize
optimizer = BootstrapFewShot(
    metric=mixed_metric,
    max_bootstrapped_demos=4,
    max_labeled_demos=4
)

compiled = optimizer.compile(rag_module, trainset=trainset)
Phase 5: Extract and Apply Optimized Prompt

After optimization, extract the optimized prompt and apply it to your Haystack pipeline.

See Prompt Extraction Guide for detailed steps on:

  • Extracting prompts from compiled DSPy modules
  • Mapping DSPy demos to Haystack templates
  • Building optimized Haystack pipelines

Production Example

For a complete production-ready implementation, see HaystackDSPyOptimizer.

This class provides:

  • Wrapper for Haystack retrievers in DSPy modules
  • Automatic optimization with BootstrapFewShot
  • Prompt extraction and Haystack pipeline rebuilding
  • Complete usage example with document store setup

Best Practices

  1. Match retrievers - Use same retriever in DSPy module as Haystack pipeline
  2. Custom metrics - Combine Haystack evaluators with DSPy optimization
  3. Prompt extraction - Carefully map DSPy demos to Haystack template format
  4. Test both - Validate DSPy module AND final Haystack pipeline

Limitations

  • Prompt template conversion can be tricky
  • Some Haystack features don't map directly to DSPy
  • Requires maintaining two codebases initially
  • Complex pipelines may need custom integration

Official Documentation

© OmidZamani, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 3 other files (references) in skills/dspy-haystack-integration of OmidZamani/dspy-skills.

  • SKILL.md
  • example.py
  • examples/haystack-dspy-optimizer.py
  • references/prompt-extraction.md

Open the folder on GitHubat commit f5db3b7

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in OmidZamani/dspy-skills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Dspy Haystack Integration next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Dspy Haystack Integration compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Dspy Haystack Integration this skillOmidZamani/dspy-skills1241 repos~1.4kAutomated safety check: PassMIT
Chroma Vector DatabaseOrchestra-Research/AI-Research-SKILLs13k8 repos~2.3kAutomated safety check: PassMIT
LLM Application DevMoizIbnYousaf/ai-agent-skills1.1k2 repos~1.3kAutomated safety check: PassMIT
Senior Prompt Engineermaslennikov-ig/claude-code-orchestrator-kit2604 repos~1.4kAutomated safety check: PassCustom licence
MCP Local RAGshinpr/mcp-local-rag407—~4.4kAutomated safety check: PassMIT
Ms Agent Framework RAGshuyu-labs/WebCode278—~1.1kAutomated safety check: PassCustom licence

Similar skills

  • Chroma Vector Database

    Orchestra-Research/AI-Research-SKILLs

    Shows how to store documents and embeddings in Chroma, query them by similarity with metadata filters, and persist them to disk for RAG and semantic search projects.

    13k GitHub starsUsed in 8 repos~2.3k tokens
    AI & LLM EngineeringAuto-check passed
  • LLM Application Dev

    MoizIbnYousaf/ai-agent-skills

    Building applications with Large Language Models - prompt engineering, RAG patterns, and LLM integration.

    1.1k GitHub starsUsed in 2 repos~1.3k tokens
    AI & LLM EngineeringAuto-check passed
  • Senior Prompt Engineer

    maslennikov-ig/claude-code-orchestrator-kit

    Provides reference guides and Python scripts for prompt optimization, RAG evaluation, and agent orchestration when building or tuning LLM systems.

    260 GitHub starsUsed in 4 repos~1.4k tokens
    AI & LLM EngineeringAuto-check passed
  • MCP Local RAG

    shinpr/mcp-local-rag

    Searches, saves, and maintains a local document index through a local RAG MCP server.

    407 GitHub stars~4.4k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • Ms Agent Framework RAG

    shuyu-labs/WebCode

    Comprehensive guide for building Agentic RAG systems using Microsoft Agent Framework in C.

    278 GitHub stars~1.1k tokensUpdated 3 mo ago
    AI & LLM EngineeringAuto-check passed
  • Local RAG Search

    nkapila6/mcp-local-rag

    Efficiently perform web searches using the mcp-local-rag server with semantic similarity ranking.

    134 GitHub starsUsed in 1 repo~1.6k tokens
    AI & LLM EngineeringAuto-check passed

More from OmidZamani/dspy-skills

All 17 skills in this repo
  • Skill Perfection

    OmidZamani/dspy-skills

    A skill your agent uses when you need to QA audit and fix a plugin skill file.

    124 GitHub stars~1.6k tokensUpdated 3 mo ago
    Auto-check passed
  • Dspy Advanced Module Composition

    OmidZamani/dspy-skills

    A skill your agent uses for composing DSPy modules with Ensemble, MultiChainComparison, ensemble voting, sequential pipelines, and multi-program workflows.

    124 GitHub starsUsed in 1 repo~2.2k tokens
    Auto-check passed
  • Dspy Better Together

    OmidZamani/dspy-skills

    A skill your agent uses for BetterTogether, prompt plus weight optimization, fine-tuning sequences, and strategy chains like p - w - p.

    124 GitHub starsUsed in 1 repo~756 tokens
    Auto-check passed
  • Dspy Bootstrap Fewshot

    OmidZamani/dspy-skills

    A skill your agent uses for BootstrapFewShot, bootstrapped demonstrations, teacher-model demos, and low-data DSPy prompt optimization.

    124 GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • Dspy Custom Module Design

    OmidZamani/dspy-skills

    A skill your agent uses for creating custom DSPy modules, extending dspy.Module, reusable components, stateful modules, serialization, and module testing.

    124 GitHub starsUsed in 1 repo~1.9k tokens
    Auto-check passed
  • A skill your agent uses for dspy.Refine, dspy.BestOfN, output constraints, validation, reward functions, and iterative output refinement.

    124 GitHub starsUsed in 1 repo~1.7k tokens
    Auto-check passed

Questions about Dspy Haystack Integration

What does Dspy Haystack Integration do?

A skill your agent uses for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts. Dspy Haystack Integration is an agent skill from OmidZamani/dspy-skills. Use for integrating DSPy with Haystack, optimizing Haystack prompts, improving retrieval pipelines, and extracting DSPy prompts.

When should I use Dspy Haystack Integration?

Dspy Haystack Integration fits situations like: integrating DSPy with Haystack; optimizing Haystack prompts; improving retrieval pipelines; extracting DSPy prompts.

How do I install Dspy Haystack Integration in Claude Code?

Run `npx skills add OmidZamani/dspy-skills --skill dspy-haystack-integration -a claude-code`. Or copy the skill folder (skills/dspy-haystack-integration in OmidZamani/dspy-skills) into .claude/skills/dspy-haystack-integration in your project. Claude Code loads it when a task matches its description.

How do I install Dspy Haystack Integration in Codex?

Run `npx skills add OmidZamani/dspy-skills --skill dspy-haystack-integration -a codex`. Or copy the skill folder (skills/dspy-haystack-integration in OmidZamani/dspy-skills) into .agents/skills/dspy-haystack-integration in your project. Codex loads it when a task matches its description.

Can I use Dspy Haystack Integration in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add OmidZamani/dspy-skills --skill dspy-haystack-integration -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/dspy-haystack-integration, .gemini/skills/dspy-haystack-integration, .github/skills/dspy-haystack-integration and .opencode/skills/dspy-haystack-integration in your project.

What does Dspy Haystack Integration need to run?

Going by SKILL.md and its folder, Dspy Haystack Integration needs Python for the scripts in its folder. Our summary lists: Python 3. Its frontmatter pre-approves these tools: Read, Write, Glob, Grep.

Does Dspy Haystack Integration access the network?

SKILL.md names 3 domains. As links in the text: dspy.ai, github.com and docs.haystack.deepset.ai. This is read from the text; nothing was executed.

Is Dspy Haystack Integration safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Dspy Haystack Integration use?

Dspy Haystack Integration is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Dspy Haystack Integration use?

About 1.4k tokens (SKILL.md is roughly 5.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 498 tokens, read only when the agent opens those files.

What are the alternatives to Dspy Haystack Integration?

Skills that share tags, products or a category with Dspy Haystack Integration: Chroma Vector Database (Orchestra-Research/AI-Research-SKILLs, 13k stars), LLM Application Dev (MoizIbnYousaf/ai-agent-skills, 1.1k stars), Senior Prompt Engineer (maslennikov-ig/claude-code-orchestrator-kit, 260 stars) and MCP Local RAG (shinpr/mcp-local-rag, 407 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Dspy Haystack Integration?

OmidZamani (a GitHub user) maintains it in OmidZamani/dspy-skills, which has 124 GitHub stars. The repository holds 17 skills in this directory. The repository was last updated on June 23, 2026.

Source: OmidZamani/dspy-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.