Retrieval · Reasoning · Execution
RAG learning — from market facts to trade decisions
Cryptrade does not treat each price tick in isolation. A Retrieval-Augmented Generation (RAG)
knowledge base grows automatically from live feeds, Hermes AI digests, and trade outcomes — then
the best-matching facts are injected into every strategy and gate evaluation before a swap is signed.
Knowledge flows in continuously; decisions pull the most relevant facts out at runtime.
Two memory layers — one decision
Session tape (memoryBrief)
Chronological log of this session: ticks, signals, skips, fills, AI verdicts, news hits.
- Answers: What just happened in the last 24 hours?
- Built from
data/bot-memory.jsonl
- Compressed before each Hermes call
Knowledge store (knowledgeBrief)
Durable, tagged facts with confidence scores and TTL — the RAG corpus.
- Answers: What should we remember about this market regime?
- Built from
data/market-knowledge.jsonl
- Ranked and retrieved at decision time
At every AI evaluation, Hermes receives both briefs plus live quote, EMA, order book, macro, and intel context.
The strategy math fires first; RAG shapes whether gates pass and how confident the AI is.
What the system learns — all knowledge sources
Every ~5 minutes collectors upsert fresh chunks. Hourly digest adds Hermes-distilled facts. Outcomes close the loop.
| Source |
What gets written |
TTL (typical) |
Role in trades |
seed |
Baseline rules: wallet hygiene, accumulation scenarios, exchange references |
Permanent |
Always-retrieved guardrails |
intel_feed |
Fear & Greed, funding rates, spot references, composite intel score |
12–72 h |
Regime context; adjusts AI confidence discount |
macro_feed |
Crypto vs metals leadership, risk-on / risk-off regime |
48 h |
Macro gate + bearish accumulation caution |
orderbook_feed |
Binance L2 imbalance, spread, mid prices |
6 h |
Order book gate; CEX vs DEX sanity |
wallet |
Sanitized live wallet: USDC balance, gas, active chain |
24 h |
Size and readiness checks |
whale_feed |
Large transfer bias summary |
24 h |
Whale gate on BUY/SELL |
news_feed |
Verified headlines (BBC, CNBC, WSJ, Bloomberg, FT, Fed, SEC) |
48 h |
Event playbooks; desk intel |
ai_learning |
Win rate, blocked signals, correlated AI vs outcome patterns |
168 h |
Teaches Hermes what blocks saved capital |
hermes_digest |
1–3 new facts distilled hourly from session + feeds |
72 h |
Durable learned cautions and scenarios |
hermes_gate |
Snapshot of each AI assessment at gate time |
48 h |
Audit trail; future RAG retrieval |
How RAG retrieval ranks facts
When a BUY or SELL signal arrives, retrieveKnowledgeChunks scores every active chunk and builds knowledgeBrief.
Tag & asset match
+25 for chain tag (e.g. ethereum). +18 per matching asset (eth, weth, usdc). Focus accumulation boosts scenario and pattern categories.
Recency boost
Market regime and pattern chunks written in the last 6 hours get up to +22. Stale intel naturally fades as TTL expires.
Must-have guardrails
Security and core accumulation scenarios are always included in the brief — even if they would not top the score alone.
Confidence weighting
Each chunk carries a 0–100 confidence score. Seed facts and wallet snapshots rank high; Hermes digest facts start at ~70 until reinforced by outcomes.
From signal to swap — where knowledge decides
Uniswap tick→
EMA / dip strategy→
BUY or SELL signal→
RAG + memory brief→
Hermes assessment→
Gates→
Execute or skip
1
Strategy fires (quant first)
Price websocket triggers EMA dip logic, take-profit, or stop-loss. No AI required for the initial signal — math defines when to consider a trade.
2
RAG brief assembled
knowledgeBriefForContext retrieves top chunks for chain, pair (WETH/USDC), and accumulation focus. Session memoryBrief adds recent skips, fills, and AI history.
3
Hermes evaluates
AiAdvisor.getIntelligence sends briefs + live context to Ollama. Returns bias, confidence, action_hint, risk flags, and invalidation — logged to session memory.
4
Gates apply knowledge
When AI_GATE_BUY / AI_GATE_SELL are on, Hermes must approve. CEX, macro, order book, and whale gates also consult live feeds already mirrored in RAG. Failed gate → skip with desk commentary.
5
Outcome feeds back
Executed trades and skipped signals get correlated by signal ID. Win rates and “AI blocked N signals” patterns upsert into ai_learning chunks — retrieved on the next decision.
Example: a BUY signal with RAG in the loop
Retrieved knowledge might say…
- Extreme fear 12 — contrarian accumulation context (intel_feed)
- ETH funding negative — shorts pay longs; cautious long bias (intel_feed)
- Macro risk_off — crypto lagging metals; macro gate may block (macro_feed)
- AI blocked 3 signals — recent CEX gate pattern (ai_learning)
- Hermes digest: wait for momentum confirmation (hermes_digest)
Hermes might conclude…
- bias: neutral or bearish despite dip
- confidence: below
AI_MIN_CONFIDENCE
- action_hint: hold / wait
- Result: skip BUY — logged with reason; desk shows gate block
With AI gates off, RAG still enriches desk and hourly digest — strategy may execute if other gates pass.
The learning cycle (continuous)
Collect — every ~5 min
refreshKnowledgeBase runs collectors: wallet, intel, macro, orderbook, whale, news, memory learning. Fresh snapshots replace expired TTL chunks.
Digest — hourly
digestMarketKnowledge asks Hermes for 1–3 new JSON facts given current memory + RAG. Upserts as hermes_digest with 72 h TTL.
Retrieve — every signal
Ranked chunks compress into knowledgeBrief (~1800 chars). Injected into getIntelligence alongside macro and intel briefs.
Learn — after outcomes
SignalOutcomeTracker links AI verdicts to PnL. collectFromMemoryLearning writes pattern chunks so future trades benefit from closed-loop feedback.
Configuration knobs
| Env variable | Default | Effect |
KNOWLEDGE_ENABLED | true | Master switch for RAG store |
KNOWLEDGE_COLLECT_SEC | 300 | How often collectors refresh feeds |
KNOWLEDGE_DIGEST_SEC | 3600 | Hermes hourly fact distillation |
KNOWLEDGE_BRIEF_MAX_CHARS | 1800 | Max RAG text injected per decision |
AI_GATE_BUY / AI_GATE_SELL | configurable | Require Hermes approval before swap |
AI_MIN_CONFIDENCE | — | Minimum % for BUY approval (adjusted by intel) |
Monitor live facts locally: npm run rag:monitor:open
Related slides
Session tape vs knowledge store, privacy, and what AI does not control.
Every external feed that feeds the collectors above.
Execution, safety checks, and on-chain audit trail.
See signals, intel, and gate blocks in real time.