dspy-3-retrieval-augmented-generation

Sub-skill of dspy: 3. Retrieval-Augmented Generation.

5 stars

Best use case

dspy-3-retrieval-augmented-generation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Sub-skill of dspy: 3. Retrieval-Augmented Generation.

Teams using dspy-3-retrieval-augmented-generation should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/3-retrieval-augmented-generation/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/_archive/ai/prompting/dspy/3-retrieval-augmented-generation/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/3-retrieval-augmented-generation/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How dspy-3-retrieval-augmented-generation Compares

Feature / Agentdspy-3-retrieval-augmented-generationStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Sub-skill of dspy: 3. Retrieval-Augmented Generation.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 3. Retrieval-Augmented Generation

## 3. Retrieval-Augmented Generation


**RAG with DSPy:**
```python
import dspy
from dspy.retrieve.chromadb_rm import ChromadbRM

# Configure retriever
retriever = ChromadbRM(
    collection_name="engineering_docs",
    persist_directory="./chroma_db",
    k=5
)

# Configure DSPy with retriever
dspy.settings.configure(
    lm=dspy.OpenAI(model="gpt-4"),
    rm=retriever
)

class RAGSignature(dspy.Signature):
    """Answer questions using retrieved context."""
    context = dspy.InputField(desc="Retrieved relevant passages")
    question = dspy.InputField(desc="Question to answer")
    answer = dspy.OutputField(desc="Answer based on context")

class RAGModule(dspy.Module):
    """RAG module with retrieval and generation."""

    def __init__(self, num_passages=5):
        super().__init__()
        self.retrieve = dspy.Retrieve(k=num_passages)
        self.generate = dspy.ChainOfThought(RAGSignature)

    def forward(self, question):
        # Retrieve relevant passages
        passages = self.retrieve(question).passages

        # Generate answer with context
        context = "\n\n".join(passages)
        result = self.generate(context=context, question=question)

        return dspy.Prediction(
            answer=result.answer,
            passages=passages,
            reasoning=result.rationale
        )

# Usage
rag = RAGModule(num_passages=5)
result = rag(question="What are the safety factor requirements for moorings?")

print(f"Answer: {result.answer}")
print(f"Sources: {len(result.passages)} passages retrieved")
```

**Multi-Hop RAG:**
```python
class MultiHopRAG(dspy.Module):
    """
    Multi-hop RAG that retrieves, reasons, and retrieves again
    for complex questions requiring multiple pieces of information.
    """

    def __init__(self, num_hops=2, passages_per_hop=3):
        super().__init__()
        self.num_hops = num_hops
        self.retrieve = dspy.Retrieve(k=passages_per_hop)
        self.generate_query = dspy.ChainOfThought(
            "context, question -> search_query"
        )
        self.generate_answer = dspy.ChainOfThought(RAGSignature)

    def forward(self, question):
        context = []
        current_query = question

        for hop in range(self.num_hops):
            # Retrieve for current query
            passages = self.retrieve(current_query).passages
            context.extend(passages)

            if hop < self.num_hops - 1:
                # Generate refined query for next hop
                all_context = "\n\n".join(context)
                query_result = self.generate_query(
                    context=all_context,
                    question=question
                )
                current_query = query_result.search_query

        # Final answer generation
        full_context = "\n\n".join(context)
        result = self.generate_answer(
            context=full_context,
            question=question
        )

        return dspy.Prediction(
            answer=result.answer,
            hops=self.num_hops,
            total_passages=len(context)
        )

# Usage
multi_hop_rag = MultiHopRAG(num_hops=3, passages_per_hop=3)
result = multi_hop_rag(
    question="How does fatigue analysis relate to mooring safety factors?"
)
```

Related Skills

label-driven-prompt-generation-architecture

5
from vamseeachanta/workspace-hub

Pattern for building automation scripts that classify GitHub issues into prompt templates using label-based routing and extract contextual data for batch processing

agent-team-prompt-generation

5
from vamseeachanta/workspace-hub

Create self-contained execution prompts that define multi-role workflows for Codex sessions without external dependencies

gtm-workflow-gif-generation

5
from vamseeachanta/workspace-hub

Generate workflow-style GTM GIFs from validated HTML demo reports using synthetic scene slides plus Playwright/Pillow scroll capture, with Python 3.12 fallback and GIF size optimization.

gtm-demo-workflow-gif-generation

5
from vamseeachanta/workspace-hub

Generate GTM demo GIF assets from validated HTML reports, including both report-scroll GIFs and one higher-fidelity workflow-style GIF, while avoiding Playwright/Python environment traps.

stable-diffusion-image-generation

5
from vamseeachanta/workspace-hub

State-of-the-art text-to-image generation with Stable Diffusion models via HuggingFace Diffusers. Use when generating images from text prompts, performing image-to-image translation, inpainting, or building custom diffusion pipelines.

orcawave-mesh-generation

5
from vamseeachanta/workspace-hub

Panel mesh generation for OrcaWave diffraction analysis. Use when converting CAD/STL to panel mesh, validating mesh quality, running convergence studies, or generating GDF files for hydrodynamic computations.

cad-mesh-generation

5
from vamseeachanta/workspace-hub

Generate parametric CAD geometry and finite element meshes using FreeCAD and GMSH

lead-generation

5
from vamseeachanta/workspace-hub

B2B demand generation with CAC optimization, multi-channel strategies, and lead qualification frameworks. Use for lead acquisition, nurture campaigns, and conversion optimization. Based on alirezarezvani/Codex-skills.

dspy

5
from vamseeachanta/workspace-hub

Build complex AI systems with declarative programming, optimize prompts automatically, create modular RAG systems and agents with DSPy - Stanford NLP's framework for systematic LM programming

json-config-loader-3-json-report-generation

5
from vamseeachanta/workspace-hub

Sub-skill of json-config-loader: 3. JSON Report Generation.

wave-theory-4-time-series-generation

5
from vamseeachanta/workspace-hub

Sub-skill of wave-theory: 4. Time Series Generation (+1).

orcawave-mesh-generation-standard-mesh-generation

5
from vamseeachanta/workspace-hub

Sub-skill of orcawave-mesh-generation: Standard Mesh Generation (+1).