Automatic RAG with Amazon Bedrock
DevDuck automatically retrieves relevant context before each query and stores conversations after. No manual RAG calls neededβjust set an environment variable.
When DEVDUCK_KNOWLEDGE_BASE_ID is set, DevDuck performs automatic retrieval and storage:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β DevDuck Query Flow β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β β User Query β β β β β βΌ β β βββββββββββββββββββββββββββββββββββββββββββ β β β 1. RETRIEVE - Before Agent Runs β β β β β β β β retrieve( β β β β text=query, β β β β knowledgeBaseId=KB_ID β β β β ) β β β β β β β β β Injects relevant context into agent β β β βββββββββββββββββββββββββββββββββββββββββββ β β β β β βΌ β β βββββββββββββββββββββββββββββββββββββββββββ β β β 2. AGENT EXECUTION β β β β β β β β Agent processes query with context β β β β from knowledge base β β β βββββββββββββββββββββββββββββββββββββββββββ β β β β β βΌ β β βββββββββββββββββββββββββββββββββββββββββββ β β β 3. STORE - After Agent Completes β β β β β β β β store_in_kb( β β β β content="Input: ... Result: ...", β β β β title="DevDuck: 2026-02-02 | ...", β β β β knowledge_base_id=KB_ID β β β β ) β β β β β β β β β Saves for future reference β β β βββββββββββββββββββββββββββββββββββββββββββ β β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Just set your Bedrock Knowledge Base ID and DevDuck handles the rest automatically:
# Enable automatic RAG
export DEVDUCK_KNOWLEDGE_BASE_ID="your-kb-id-here"
# Start DevDuck
devduck
# Every query now:
# 1. Retrieves relevant context from KB
# 2. Processes with enriched context
# 3. Stores conversation for future
# Retrieve from knowledge base
retrieve(
text="how do I configure bedrock?",
knowledgeBaseId="your-kb-id",
numberOfResults=5,
score=0.4 # Minimum relevance threshold
)
# Store content in knowledge base
store_in_kb(
content="Important information to remember...",
title="Session Notes - 2026-02-02",
knowledge_base_id="your-kb-id"
)
Semantic search against your Bedrock Knowledge Base with relevance scoring.
| Parameter | Default | Description |
|---|---|---|
text |
required | Query text for semantic search |
knowledgeBaseId |
env var | Bedrock Knowledge Base ID |
numberOfResults |
5 | Maximum results to return |
score |
0.4 | Minimum relevance score (0.0-1.0) |
region |
us-west-2 | AWS region |
enableMetadata |
false | Include source metadata in results |
{
"content": {
"text": "Retrieved document content...",
"type": "TEXT"
},
"location": {
"customDocumentLocation": {
"id": "document_id"
},
"type": "CUSTOM"
},
"metadata": {
"x-amz-bedrock-kb-source-uri": "source_uri",
"x-amz-bedrock-kb-chunk-id": "chunk_id",
"x-amz-bedrock-kb-data-source-id": "data_source_id"
},
"score": 0.95
}
Real-time ingestion into Bedrock Knowledge Base. Runs async in background thread.
| Parameter | Default | Description |
|---|---|---|
content |
required | Text content to store |
title |
timestamp | Optional title for the content |
knowledge_base_id |
env var | Target Knowledge Base ID |
# Store with custom title
store_in_kb(
content="Complete API documentation for the user service...",
title="API Docs - User Service v2.0",
knowledge_base_id="kb-12345"
)
# Store with auto-generated timestamp title
store_in_kb(content="Important meeting notes...")
Retrieval and storage happen automaticallyβno manual tool calls needed.
Conversations persist across sessions. DevDuck remembers past interactions.
Storage runs in background thread. No impact on response latency.
Filter results by relevance score. Only high-quality context injected.
Vector-based similarity matching. Finds conceptually related content.
Track sources, chunk IDs, and data sources for audit trails.
| Variable | Description |
|---|---|
DEVDUCK_KNOWLEDGE_BASE_ID |
Bedrock Knowledge Base ID for automatic RAG |
STRANDS_KNOWLEDGE_BASE_ID |
Alternative env var for KB ID (used by strands_tools) |
AWS_REGION |
AWS region for Bedrock (default: us-west-2) |
Index project docs for instant retrieval during development.
Pick up where you left off across multiple DevDuck sessions.
Share knowledge across team members through shared KB.
Build up knowledge over long research projects.