Retrieval v3: Query → tokenize → query expansion (synonyms + heuristic: mortgage→loan,interest) → HyDE hypothetical doc (Gao 2022) embedding → BM25 score (k1=1.2,b=0.75) + embedding cosine + HyDE cosine → RRF fusion (Cormack 2009) 1/(k+rank) ensemble of BM25 and embedding ranks → cross-encoder re-rank simulation (token overlap + embedding joint) → MMR diversity (Carbonell 1998) λ=0.7 balancing relevance vs redundancy → final top 8 with scores breakdown.
Reasoning: Auto-routes by complexity: simple→CoT, complex→ToT, plan→Least-to-Most, abstract→Step-Back. ToT BFS: root goal → branch 3 thoughts → evaluate 0-10 heuristic → promising/pruned → expand promising to L2 → select best path. Self-Consistency: sample 3 paths with different angles, confidence scores, vote. Reflexion: attempt → critique (what missed?) → retry improved. Step-Back: abstract principle first, then apply. Least-to-Most: decompose into subproblems solving sequentially. ReAct: Thought→Action (tool call)→Observation loop. Constitutional AI: self-critique vs principles grounded/helpful/honest/harmless/privacy.
Memory (Generative Agents Park 2023): Importance scoring heuristic 1-10 (financial/personal/preferences high, greetings low), recency Ebbinghaus exp(-hours/48) half-life 48h, relevance cosine. Final retrieval score = recency*0.2 + importance*0.3 + relevance*0.5. Hierarchical: working (current context) → short-term (last 100 turns) → long-term (IndexedDB vector) → episodic (interaction history). Reflection: summarize recent memories into higher-level insights.
Why this is best possible from GitHub repo: All research implemented in pure browser JS, zero dependencies, zero API, static hosting. 3MB brain (7517 vocab, 1124 tools, 64-dim embeddings, tool graph) + runtime advanced retrieval + reasoning simulation. Model optional (WebGPU) but demo mode already shows full trace. Privacy by construction — no data leaves browser.