dspy-3-retrieval-augmented-generation
Provides tools and modules to implement RAG patterns within the DSPy framework.
Install
mkdir -p .claude/skills/dspy-3-retrieval-augmented-generation && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/14520" && unzip -o skill.zip -d .claude/skills/dspy-3-retrieval-augmented-generation && rm skill.zipInstalls to .claude/skills/dspy-3-retrieval-augmented-generation
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Sub-skill of dspy: 3. Retrieval-Augmented Generation.Key capabilities
- →Configure DSPy with a retriever and language model
- →Define RAG signatures for question answering
- →Implement RAG modules with retrieval and generation
- →Perform multi-hop RAG for complex questions
- →Retrieve relevant passages from a document collection
How it works
The skill configures DSPy with a retriever (e.g., ChromadbRM) and a language model. It defines RAG signatures and modules to retrieve relevant passages based on a question and then generate an answer using the retrieved context.
Inputs & outputs
When to use dspy-3-retrieval-augmented-generation
- →Building RAG pipelines with DSPy
- →Retrieving context for LLM answers
- →Configuring vector store integration
About this skill
3. Retrieval-Augmented Generation
3. Retrieval-Augmented Generation
RAG with DSPy:
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:
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?"
)
When not to use it
- →The task does not involve Retrieval-Augmented Generation
- →The project is not using DSPy
- →There is no document collection for retrieval
Limitations
- →Requires DSPy framework
- →Requires a configured language model (e.g., OpenAI GPT-4)
- →Requires a retrieval mechanism (e.g., ChromaDB) with a document collection
How it compares
This skill provides a structured and programmatic way to build RAG pipelines using DSPy, enabling more controlled and verifiable generation compared to direct LLM prompting.
Compared to similar skills
dspy-3-retrieval-augmented-generation side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| dspy-3-retrieval-augmented-generation (this skill) | 0 | 4mo | No flags | Advanced |
| dspy | 4 | 7mo | Review | Intermediate |
| embedding-strategies | 8 | 2mo | No flags | Intermediate |
| pinecone | 3 | 7mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by vamseeachanta
View all by vamseeachanta →You might also like
dspy
davila7
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
embedding-strategies
wshobson
Select and optimize embedding models for semantic search and RAG applications. Use when choosing embedding models, implementing chunking strategies, or optimizing embedding quality for specific domains.
pinecone
davila7
Managed vector database for production AI applications. Fully managed, auto-scaling, with hybrid search (dense + sparse), metadata filtering, and namespaces. Low latency (<100ms p95). Use for production RAG, recommendation systems, or semantic search at scale. Best for serverless, managed infrastructure.
embeddings
ruvnet
Vector embeddings with HNSW indexing, sql.js persistence, and hyperbolic support. 75x faster with agentic-flow integration. Use when: semantic search, pattern matching, similarity queries, knowledge retrieval. Skip when: exact text matching, simple lookups, no semantic understanding needed.
trulens-dataset-curation
truera
Create and curate evaluation datasets with ground truth for TruLens
talon
darkmice
Talon 多模融合数据引擎使用指南。当用户需要使用 Talon 数据库进行开发时触发:包括 SQL 查询、KV 存储、向量搜索、时序数据、消息队列、全文检索、地理空间、图数据库、AI 引擎(Session/Context/Memory/RAG/Agent/Trace)。也适用于:选择 Talon 引擎模块、使用 Go/Python/Node.js/Java/.NET SDK、构建 RAG 管道、Agent 工具缓存、对话管理、embedding 缓存、跨引擎融合查询(GraphRAG、Hybrid Search)。