1
RAD 読み API のクイックツアー
RAD read-API quick tour — synthetic 3-doc corpus → 3 queries → score 比較
TRIZ#35 パラメータ変更 — 入力クエリを変えると filename 一致 / content 一致 / no-hit の差が一目で分かる
実行
py -3.11 -m llive.demo --only 1 --lang japy -3.11 -m llive.demo --only 1 --lang en
期待出力
==[ rad-quick-tour :: RAD 読み API のクイックツアー ]==
ミニコーパスを生成して RAD 読み API を 3 通りに当てます。
サンプルコーパスを /tmp/llive-demo-XXXX に作成中...
3 件のドキュメントを security_corpus_v2 に配置しました。
[1/3] クエリ: 'buffer overflow'
- security_corpus_v2/buffer_overflow.md score=9.0 matched=buffer,overflow
抜粋: # Buffer Overflow Classic memory-safety bug: writes that exceed the allocated b
[2/3] クエリ: 'TOCTOU race'
- security_corpus_v2/race_conditions.md score=5.0 matched=race,toctou
抜粋: # Race conditions TOCTOU and threading hazards. Use atomics or locks.
[3/3] クエリ: 'elephant'
(該当なし)
----------------------------------------------------------------
合計 2 件のヒット。クエリの強さは filename 一致が一段強い。
==[ rad-quick-tour :: RAD read-API quick tour ]== Build a tiny synthetic corpus and hit the read API three ways. ... [1/3] Query: 'buffer overflow' - security_corpus_v2/buffer_overflow.md score=9.0 matched=buffer,overflow [2/3] Query: 'TOCTOU race' - security_corpus_v2/race_conditions.md score=5.0 matched=race,toctou [3/3] Query: 'elephant' (no matches) Total 2 hits. Filename matches dominate as designed.
- 所要
- ~30 秒
- 依存
- stdlib のみ (実 RAD コーパス不要)
- 学べる
RadCorpusIndex/query()/ filename×3 + content score
2
学習物の書き込み → 即時検索
Write learning → retrieve immediately — append_learning + provenance.json sidecar
TRIZ#5 結合 — 書き層と読み層を同じ
RadCorpusIndex に統合、書いた直後に検索可能実行
py -3.11 -m llive.demo --only 2 --lang japy -3.11 -m llive.demo --only 2 --lang en
期待出力
==[ append-roundtrip :: 学習物の書き込み → 即時検索 ]==
_learned/ に学習物を書き、すぐ検索で見える経路を示します。
[1/2] vlm_findings に学習物を書き込み...
ok wrote 20260515T...md と 20260515T....provenance.json を作成
provenance.json の中身:
source_type: 'demo'
source_id: 'scenario-2'
confidence: 0.85
derived_from: ['event-001', 'event-002']
[2/2] 書いた直後にキーワード 'adversarial patch' で検索...
- _learned/vlm_findings/20260515T...md score=2.0
抜粋: # Adversarial patch on stop signs ...
----------------------------------------------------------------
1 件ヒット。consolidation 出口の書き戻し経路と同じ仕組みです。
==[ append-roundtrip :: Write learning -> retrieve immediately ]== Write into _learned/ and immediately retrieve it through query. [1/2] Writing learned doc into vlm_findings... [2/2] Querying for 'adversarial patch' right after the write... - _learned/vlm_findings/20260515T...md score=2.0 1 hits. Same path the consolidator uses on its semantic out.
- 所要
- ~20 秒
- 依存
- stdlib のみ + Pydantic (Provenance モデル)
- 学べる
append_learning()/provenance.json/ LLW-AC-01 source-anchored
3
RAD ヒント注入つきコードレビュー
Code review with RAD hint injection — security_corpus_v2 → LLM grounding
TRIZ#24 仲介 — RAD が LLM の知識仲介、汎用 LLM が specialised security reviewerに化ける
実行
py -3.11 -m llive.demo --only 3 --lang japy -3.11 -m llive.demo --only 3 --lang en
期待出力
==[ code-review :: RAD ヒント注入つきコードレビュー ]==
security_corpus からヒントを抜き、LLM にレビューさせる流れを示します。
ミニ security_corpus を生成中...
[1/3] 脆弱コード:
void greet(const char* user) {
char buf[16];
strcpy(buf, user); /* unchecked length */
printf(buf); /* untrusted format string */
}
[2/3] tool_code_review を実行 (mock backend、ネットワーク不要)...
注入された RAD ヒント (2件):
- format_string.md
- strcpy_overflow.md
生成された system prompt の冒頭:
| You are a security-focused code reviewer. ...
| # Relevant security knowledge from RAD
| - Calling printf with attacker-controlled format specifiers ...
| - strcpy() copies until NUL; ...
[3/3] LLM 応答:
- L3: strcpy() lacks bounds check (CWE-120); use strncpy or snprintf.
- L4: printf(buf) is a CWE-134 format-string sink; use printf("%s", buf).
----------------------------------------------------------------
ヒント 2 件が system に注入され、LLM がそれを下敷きに回答。
==[ code-review :: Code review with RAD hint injection ]==
Pull hints from security_corpus and let an LLM review the code.
...
Injected RAD hints (2):
- format_string.md
- strcpy_overflow.md
LLM reply:
- L3: strcpy() lacks bounds check (CWE-120); use strncpy or snprintf.
- L4: printf(buf) is a CWE-134 format-string sink; use printf("%s", buf).
- 所要
- ~30 秒
- 依存
- RecordingBackend (mock) で完結、実 LLM 不要
- 学べる
tool_code_review/ system prompt 構築 / RAD grounding 効果- 本番では
LLIVE_LLM_BACKEND=ollamaで qwen2.5-coder 等に差し替え可能
4
MCP server を実 client で呼ぶ
Real MCP stdio round-trip — initialize / list_tools / call_tool
TRIZ#28 機構の交換 — モックではなく 本物の MCP SDKで呼ぶことで、Claude Desktop と同等の経路を実機検証
実行
py -3.11 -m pip install -e .[mcp] && py -3.11 -m llive.demo --only 4 --lang japy -3.11 -m pip install -e .[mcp] && py -3.11 -m llive.demo --only 4 --lang en
期待出力
==[ mcp-roundtrip :: MCP server を実 client で呼ぶ ]==
MCP server を subprocess で起動し、公式 client から呼びます。
[1/3] subprocess で `py -m llive.mcp.server` を起動中...
ok initialize() 成功
[2/3] list_tools() = append_learning,code_complete,code_review,
get_domain_info,list_rad_domains,query_rad,read_document,
vlm_describe_image
[3/3] call_tool('query_rad', keywords='buffer') 実行中...
(該当なし — synthetic corpus が空でも server 自体は応答)
----------------------------------------------------------------
8 tool 検出、1 ラウンドトリップ完了。Claude Desktop と同じ経路です。
==[ mcp-roundtrip :: Call the MCP server with the real client ]==
...
ok initialize()
list_tools() = ... (8 tools)
Calling call_tool('query_rad', keywords='buffer')...
(no hits -- server still responded with valid JSON)
8 tools advertised. Same path Claude Desktop uses.
- 所要
- ~1 分 (subprocess 起動含む)
- 依存
pip install -e .[mcp](mcp>=1.0)- 学べる
- stdio transport / list_tools / call_tool / TextContent → JSON
- 同じ経路
- Claude Desktop / LM Studio / Cursor / Continue.dev
5
OpenAI 互換 HTTP server で RAG-on-by-flag
RAG on/off contrast via x_rad_domain header — Ollama / OpenWebUI 直結経路
TRIZ#15 動的化 — 同じプロンプトでも
x_rad_domain を入れると system prompt にヒントが動的注入される実行
py -3.11 -m llive.demo --only 5 --lang japy -3.11 -m llive.demo --only 5 --lang en
期待出力
==[ openai-http :: OpenAI 互換 HTTP server で RAG-on-by-flag ]==
HTTP server を ephemeral port で起動し、RAD on/off の差分を出します。
サーバ起動: http://127.0.0.1:<ephemeral>/v1
ミニ security_corpus を準備...
[1/2] POST (RAD オフ):
応答 text 抜粋:
[mock] Explain buffer overflow in C in two sentences.
注入されたヒント: 0 件 / -
[2/2] POST (RAD オン: x_rad_domain=security_corpus_v2):
応答 text 抜粋:
[mock] Explain buffer overflow in C in two sentences.
注入されたヒント: 1 件 / buffer_overflow.md
----------------------------------------------------------------
RAD オンにすると同じプロンプトに 1 件のヒントが system に追加されました。
==[ openai-http :: OpenAI-compat HTTP server with RAG-on-by-flag ]== Boot the HTTP server on an ephemeral port and contrast RAD on/off. Server listening at http://127.0.0.1:<ephemeral>/v1 ... [1/2] POST (RAD off): Hints injected: 0 [2/2] POST (RAD on: x_rad_domain=security_corpus_v2): Hints injected: 1 via buffer_overflow.md Switching RAD on appended 1 system hints for the same prompt.
本番接続例 (Ollama / OpenWebUI)
py -3.11 -m llive.server.openai_api --host 127.0.0.1 --port 8765
# Then point your OpenAI client at base_url=http://127.0.0.1:8765/v1
- 所要
- ~40 秒
- 依存
- stdlib のみ (Ollama 不要、Mock backend で完結)
- 学べる
- OpenAI 互換 endpoint /
x_rad_domain拡張 / RAG-on-by-flag - 同じ経路
- Ollama / OpenWebUI / 任意の OpenAI compat クライアント
6
VLM describe + RAD ヒント (画像 + 知識基盤)
1x1 PNG + domain_hint で vision-language model の grounding 効果を可視化
TRIZ#24 仲介 — RAD が VLM の知識仲介、汎用 VLM がドメイン用語にチューニングされる経路
実行
py -3.11 -m llive.demo --only 6 --lang japy -3.11 -m llive.demo --only 6 --lang en
期待出力
==[ vlm-describe :: VLM describe + RAD ヒント (画像 + 知識基盤) ]==
1x1 の合成 PNG を渡し、VLM describe を 2 通り (RAD 無し / 有り) で実行。
1x1 PNG をメモリ上で生成中...
vision_corpus を予約準備 (synthetic)...
[1/2] RAD 無しの VLM describe:
応答:
[vlm-mock] saw 1 image; prompt = What is in this image? ...
注入されたヒント: 0 件 / -
[2/2] RAD 有り (domain_hint=vision_corpus) の VLM describe:
応答:
[vlm-mock] saw 1 image; prompt = What is in this image? ...
注入されたヒント: 2 件 / small_image_pitfalls.md, color_terminology.md
system prompt (head):
| # RAD hints
| - Single-pixel and very small images mostly carry hue information; ...
| - When asked to 'describe an image', VLMs benefit from explicit colour ...
----------------------------------------------------------------
RAD 有りで 2 件のヒントが system に注入。
==[ vlm-describe :: VLM describe + RAD hint (image + knowledge grounding) ]== Send a 1x1 synthetic PNG to VLM describe twice (without / with RAD). ... [1/2] VLM describe without RAD: Hints injected: 0 [2/2] VLM describe with RAD (domain_hint=vision_corpus): Hints injected: 2 2 hints injected with RAD on. Same image, different prompt grounding.
- 所要
- ~20 秒
- 依存
- stdlib のみ (合成 PNG をメモリ上で生成)
- 学べる
- VLM multimodal request /
domain_hintgrounding / 1x1 PNG の制約 - 本番では
LLIVE_LLM_BACKEND=ollama LLIVE_LLM_MODEL=qwen2.5-vl等で実 VLM に差し替え
7
生物学的記憶モデルから RAD への書き戻し
Episodic events → Consolidator → ConceptPage → _learned/ ミラー (LLW-AC-01)
TRIZ#5 結合 — episodic / semantic / RAD を単一サイクルで結合、source-anchored provenance で因果を維持
実行
py -3.11 -m llive.demo --only 7 --lang japy -3.11 -m llive.demo --only 7 --lang en
期待出力
==[ consolidation-mirror :: 生物学的記憶モデルから RAD への書き戻し ]==
EpisodicEvent → cluster → ConceptPage → _learned/ への自動ミラー経路を 1 サイクルで示します。
[1/2] 3 件の類似 episodic event を書き込み...
event_ids = ['15db4...', '3658d...', '24676...']
[2/2] Consolidator.run_once() を実行 (Mock LLM、ネットワーク不要)...
pages_created=1 / pages_updated=0 / clusters=1
_learned/<page_type>/ に書かれたファイル:
- domain_concept/heap-spray-is-a-classic-technique.md
provenance.json (LLW-AC-01 source-anchored):
source_type: 'consolidator'
source_id: 'heap-spray-is-a-classic-technique'
confidence: 0.8
derived_from: ['24676...', '3658d...', '15db4...']
----------------------------------------------------------------
1 件の learned doc が生成。derived_from で生 event id まで追跡可能です。
==[ consolidation-mirror :: Biological memory consolidation -> RAD mirror ]== Watch one consolidator cycle turn episodic events into a ConceptPage mirrored to _learned/. ... pages_created=1 / pages_updated=0 / clusters=1 _learned/<page_type>/ files: domain_concept/heap-spray-is-a-classic-technique.md derived_from: ['24676...', '3658d...', '15db4...'] 1 learned docs produced. derived_from traces back to the raw event ids.
- 所要
- ~30 秒 (DuckDB + Kuzu の初期化込み)
- 依存
- stdlib + duckdb + kuzu (既に core 依存)、Mock CompileLLM で完結
- 学べる
- episodic → cluster → consolidator → RAD のフルパス / LLW-AC-01 source-anchored
- 差別化
- llive 独自の生物学的記憶モデル × RAD の交点で、他のメモリ LLM フレームワークと一線を画す機能
B
[ブラウザ] 人体図カウンセリング (Dr. Aria, educational fiction)
SVG 人体図 × medical_corpus_v2 grounding × 医師ペルソナ — クリックで部位説明、mock fallback 込み
TRIZ#1 分割 + #24 仲介 — 部位を SVG path に分割、RAD が医師ペルソナの知識仲介となる
開く
demos/anatomy/index.html
ブラウザでこの HTML を開いてください (file:// で動きます)。バックエンド起動なしでも mock テキストで動作確認できます。
実バックエンドで動かす
py -3.11 -m llive.server.openai_api --host 127.0.0.1 --port 8765
起動後にページをリロードすると status が live に変わり、
x_rad_domain=medical_corpus_v2 経由で RAD ヒントが注入されます。
医療コーパスを取り込んでいない場合は hints 0 件のまま動作します。
収録部位 (8)
- 頭部 / 胸部 / 心臓 / 腹部
- 左腕 / 右腕 / 左脚 / 右脚
免責 (重要)
これは "Dr. Aria" という架空キャラクターによる 教育・調査用デモであり、医療助言ではありません。 画面上部のバナーと LLM system prompt の両方で educational-fiction を明示しています。
- 所要
- ~10 秒 / 部位
- 依存
- ブラウザのみ (mock) / + llive HTTP server (live RAD grounding)
- 学べる
- OpenAI compat HTTP の
x_rad_domain/ SVG raycasting / educational fiction の安全な免責設計 - UA 動作
- Chrome / Firefox / Safari / Edge いずれでも fetch + ES2017 で動作
▶
全シナリオ連続再生
Run all 7 in sequence — overall ~3 min
実行
py -3.11 -m llive.demo --lang japy -3.11 -m llive.demo --lang en
サマリ末尾
=== summary: 7/7 ok === OK rad-quick-tour OK append-roundtrip OK code-review OK mcp-roundtrip OK openai-http OK vlm-describe OK consolidation-mirror