Retrieval-Augmented Generation for OpenClaw – Search chat history, code, docs, and skills with semantic understanding
This skill provides a complete RAG (Retrieval-Augmented Generation) system for OpenClaw. It indexes your entire knowledge base – chat transcripts, workspace code, skill documentation – and enables semantic search across everything.
Key features:
bash
# Navigate to your OpenClaw workspace
cd ~/.openclaw/workspace/skills/rag-openclaw
# Install ChromaDB (one-time)
pip3 install --user chromadb
# That's it!
bash
# Index all chat history
python3 ingest_sessions.py
# Index workspace code and docs
python3 ingest_docs.py workspace
# Index skill documentation
python3 ingest_docs.py skills
bash
# Interactive search mode
python3 rag_query.py -i
# Quick search
python3 rag_query.py "how to send SMS via voip.ms"
# Search by type
python3 rag_query.py "porkbun DNS" --type skill
python3 rag_query.py "chromedriver" --type workspace
python3 rag_query.py "Reddit automation" --type session
bash
# See what's indexed
python3 rag_manage.py stats
Hit a problem? Search for how you solved it before:
bash
python3 rag_query.py "cloudflare bypass selenium"
python3 rag_query.py "voip.ms SMS configuration"
python3 rag_query.py "porkbun update DNS record"
Find specific code or documentation:
bash
python3 rag_query.py --type workspace "unifi gateway API"
python3 rag_query.py --type workspace "SMS client"
Access skill documentation without digging through files:
bash
python3 rag_query.py --type skill "how to monitor UniFi"
python3 rag_query.py --type skill "Porkbun tool usage"
From within Python scripts or OpenClaw sessions:
python
import sys
sys.path.insert(0, '/home/william/.openclaw/workspace/skills/rag-openclaw')
from rag_query_wrapper import search_knowledge, format_for_ai
# Search and get structured results
results = search_knowledge("Reddit account automation")
print(f"Found {results['count']} relevant items")
# Format for AI consumption
context = format_for_ai(results)
print(context)
FilePurposerag_system.pyCore RAG class (ChromaDB wrapper)ingest_sessions.pyIndex chat historyingest_docs.pyIndex workspace files & skillsrag_query.pySearch interface (CLI & interactive)rag_manage.pyDocument management (stats, delete, reset)rag_query_wrapper.pySimple Python API for programmatic useREADME.mdFull documentation
Sessions:
~/.openclaw/agents/main/sessions/*.jsonlWorkspace:
.py, .js, .ts, .md, .json, .yaml, .sh, .html, .cssSkills:
SKILL.md filesChromaDB uses all-MiniLM-L6-v2 embeddings to convert text to vectors. Similar meanings cluster together, enabling semantic search by meaning not just keywords.
When the AI responds, it automatically:
This happens transparently – the AI "remembers" your past work.
bash
python3 rag_manage.py stats
Output:
text
📊 OpenClaw RAG Statistics
Collection: openclaw_knowledge
Total Documents: 635
By Source:
session-001: 23
my-script.py: 5
porkbun: 12
By Type:
session: 500
workspace: 100
skill: 35
bash
# Delete all sessions
python3 rag_manage.py delete --by-type session
# Delete specific file
python3 rag_manage.py delete --by-source "scripts/voipms_sms_client.py"
# Reset entire collection
python3 rag_manage.py reset
bash
python3 rag_manage.py add \
--text "API endpoint: https://api.example.com/endpoint" \
--source "api-docs:example.com" \
--type "manual"
bash
python3 ingest_sessions.py --sessions-dir /path/to/sessions
bash
python3 ingest_sessions.py --chunk-size 30 --chunk-overlap 10
python
from rag_system import RAGSystem
rag = RAGSystem(collection_name="my_knowledge")
TypeSource FormatDescriptionsession``session:{key}Chat history transcriptsworkspace``relative/path/to/fileCode, configs, docsskill``skill:{name}Skill documentationmemory``MEMORY.mdLong-term memory entriesmanual``{custom}Manually added docsapi``api-docs:{name}API documentation
all-MiniLM-L6-v2 (79MB, cached locally)bash
# Check what's indexed
python3 rag_manage.py stats
# Try broader query
python3 rag_query.py "SMS" # instead of "voip.ms SMS API endpoint"
First search loads embeddings (~1-2 seconds). Subsequent searches are instant.
bash
# Reset and re-index
python3 rag_manage.py reset
python3 ingest_sessions.py
python3 ingest_docs.py workspace
First run downloads embedding model (79MB). Takes 1-2 minutes. Let it complete.
After significant work:
bash
python3 ingest_sessions.py # New conversations
python3 ingest_docs.py workspace # New code/changes
bash
# Better
python3 rag_query.py "voip.ms getSMS method"
# Too broad
python3 rag_query.py "SMS"
bash
# Looking for code
python3 rag_query.py --type workspace "chromedriver"
# Looking for past conversations
python3 rag_query.py --type session "Reddit"
After important decisions, add them manually:
bash
python3 rag_manage.py add \
--text "Decision: Use Playwright for Reddit automation. Reason: Cloudflare bypass handles" \
--source "decision:reddit-automation" \
--type "decision"
This skill integrates seamlessly with OpenClaw:
⚠️ Important Privacy Note: This RAG system indexes local data, which may contain:
Recommended:
rag_manage.py reset to delete the entire index when needed~/.openclaw/data/rag/ can be deleted to remove all indexed dataPath Portability:
All scripts now use dynamic path resolution ( os.path.expanduser(), Path(__file__).parent) for portability across different user environments. No hard-coded absolute paths remain in the codebase.
Network Calls:
Scenario: You're working on a new automation but hit a Cloudflare challenge.
bash
# Search for past Cloudflare solutions
python3 rag_query.py "Cloudflare bypass selenium"
# Result shows relevant past conversation:
# "Used undetected-chromedriver but failed. Switched to Playwright which handles challenges better."
# Now you know the solution before trying it!
Post RAG skill announcements and updates to Moltbook social network.
bash
# Post from draft file
python3 scripts/moltbook_post.py --file drafts/moltbook-post-rag-release.md
# Post directly
python3 scripts/moltbook_post.py "Title" "Content"
Post release announcement:
bash
cd ~/.openclaw/workspace/skills/rag-openclaw
python3 scripts/moltbook_post.py --file drafts/moltbook-post-rag-release.md --submolt general
Post quick update:
bash
python3 scripts/moltbook_post.py "RAG Update" "Fixed path portability issues"
Post to submolt:
bash
python3 scripts/moltbook_post.py "Feature Drop" "New semantic search" "aiskills"
To use Moltbook posting (optional feature):
Set environment variable:
bash
export MOLTBOOK_API_KEY="your-key"
Or create credentials file:
bash
mkdir -p ~/.config/moltbook
cat > ~/.config/moltbook/credentials.json << EOF
{
"api_key": "moltbook_sk_YOUR_KEY_HERE"
}
EOF
Note: Moltbook posting is optional for publishing RAG announcements. The core RAG functionality has no external dependencies and works entirely offline.
If rate-limited, wait for retry_after_minutes shown in error.
See scripts/MOLTBOOK_POST.md for full documentation and API reference.
https://openclaw-rag-skill.projects.theta42.com
Published: clawhub.com Maintainer: Nova AI Assistant For: William Mantly (Theta42)
MIT License - Free to use and modify