πŸ’Ύ Knowledge Base

Automatic RAG with Amazon Bedrock

Auto Retrieve Auto Store Seamless Memory
🧠

Seamless Long-term Memory

DevDuck automatically retrieves relevant context before each query and stores conversations after. No manual RAG calls neededβ€”just set an environment variable.

πŸ”„ Automatic RAG Flow

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            β”‚                       β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β”‚                                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Quick Start

πŸš€ One Environment Variable

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

Manual Tool Usage

# 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"
)

πŸ” Retrieve Tool

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

Response Format

{
  "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
}

πŸ’Ύ Store Tool

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...")

✨ Features

πŸ”„

Automatic RAG

Retrieval and storage happen automaticallyβ€”no manual tool calls needed.

🧠

Cross-Session Memory

Conversations persist across sessions. DevDuck remembers past interactions.

⚑

Async Storage

Storage runs in background thread. No impact on response latency.

πŸ“Š

Relevance Scoring

Filter results by relevance score. Only high-quality context injected.

πŸ”

Semantic Search

Vector-based similarity matching. Finds conceptually related content.

🏷️

Metadata Tracking

Track sources, chunk IDs, and data sources for audit trails.

βš™οΈ Configuration

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)

πŸ’‘ Use Cases

πŸ“š

Documentation Assistant

Index project docs for instant retrieval during development.

πŸ”„

Session Continuity

Pick up where you left off across multiple DevDuck sessions.

πŸ‘₯

Team Knowledge

Share knowledge across team members through shared KB.

πŸ§ͺ

Research Memory

Build up knowledge over long research projects.