Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ pip install -e '.[mcp]'
neuron-graph-rag-mcp --database /absolute/path/to/knowledge.db
```

同じ adapter は SQLite 正本の判断を読む専用 tool `search_judgments`、`get_judgment`、`traverse_judgments` も公開します。これらは通常 `search` と異なり retrieval trace、activation、feedback を保存せず、read-only です。例えば `search_judgments` の `repository` には `liplus-language` や `neuron-graph-rag` の namespace を指定でき、archived judgment は `include_archived=true` を明示した時だけ検索・探索対象に入ります。接続先は workspace 固有 path を commit せず、上記の `/absolute/path/to/knowledge.db` を各 client の絶対 path へ置き換えます。

この接続例は local stdio の実装済み範囲だけを示します。Wiki 自動生成、共有フォルダ同期、remote / on-prem 配置は含みません。

To opt one local stdio server into the evaluated stabilization settings, pass both feedback options explicitly:

```bash
Expand Down
12 changes: 12 additions & 0 deletions docs/canonical-sqlite-judgment-graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ archive は通常 retrieval から外す論理的忘却であり、revision、pr

MCP の `write_judgment` は同じ domain API へ写像し、model に raw SQL を公開しない。既存 `search`、`record_source_use`、`record_outcome` の contract と既定値は変更しない。

## Read-only API

`NeuronGraphRAG.judgments` は `search_judgments`、`get_judgment`、`traverse_judgments` も提供する。三操作は current judgment state を SQLite 正本から読み、judgment、revision、relation、retrieval trace、feedback、node、edge、activation を成功時・失敗時とも変更しない。

`search_judgments(query, limit=5, include_archived=False, repository=None)` は judgment の `nodes` projection に既存 NGR と同じ lexical / dense scorer と process の有効 weight を適用する。結果は stable identity、current revision、lifecycle、statement、rationale、provenance、outgoing typed relation、score と lexical / dense の説明内訳を返す。既定候補は active のみで、archived は `include_archived=True` の時だけ候補に入る。`repository` は provenance の full repository または stable identity に使う basename namespace の完全一致で絞り込む。この検索は通常 `search` と異なり trace と動的 activation を保存せず、feedback の入力にもならない。

`get_judgment(judgment_id)` は stable identity の完全一致で lifecycle を問わず current state を返す。`traverse_judgments(judgment_id, direction="outgoing", relation_type=None, max_hops=1, include_archived=False)` は relation type と `incoming` / `outgoing` / `both` を指定できる。探索は root を再訪しない cycle-safe BFS とし、hop、到達した judgment の stable identity、source identity、target identity、relation type、direction の順で決定的に返す。archived node は明示指定時だけ traversal result に含める。

optional MCP adapter は同名の三 tool をこの domain API へ写像し、`readOnlyHint=true`、`destructiveHint=false`、`idempotentHint=true`、`openWorldHint=false` を宣言する。input / output schema は未知 field を拒否し、失敗は既存 `{code, message, retryable}` envelope を使う。

この実装範囲は local SQLite core と optional local stdio MCP adapter の読み取り surface までである。SQLite からの Wiki 自動生成、共有フォルダ同期、remote / on-prem deployment は実装しておらず、将来の配置判断とする。

## Portability and recovery

`tools/judgment_graph.py` は次を提供する。
Expand Down
8 changes: 7 additions & 1 deletion docs/optional-mcp-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ neuron-graph-rag-mcp \

## 2. Protocol envelope

tool 名は `search`、`record_source_use`、`record_outcome` とする。すべての input と成功 output は JSON Schema で宣言し、未知 field を受け付けない。
tool 名は `search`、`record_source_use`、`record_outcome`、`write_judgment`、`search_judgments`、`get_judgment`、`traverse_judgments` とする。すべての input と成功 output は JSON Schema で宣言し、未知 field を受け付けない。

成功時は MCP envelope の `resultType` を `complete` とし、機械処理用の `structuredContent` と、その同じ JSON を直列化した `TextContent` を返す。これは [MCP 2026-07-28 tools specification](https://modelcontextprotocol.io/specification/2026-07-28/server/tools) の tool result、structured content、後方互換性の指針に合わせる。

Expand All @@ -94,9 +94,15 @@ tool の意味をこの文書だけに閉じ込めない。MCP client が `tools
| `search` | `false` | `false` | `false` | `false` |
| `record_source_use` | `false` | `false` | `true` | `false` |
| `record_outcome` | `false` | `false` | `true` | `false` |
| `write_judgment` | `false` | `true` | `false` | `false` |
| `search_judgments` | `true` | `false` | `true` | `false` |
| `get_judgment` | `true` | `false` | `true` | `false` |
| `traverse_judgments` | `true` | `false` | `true` | `false` |

`search` は edge を強化しないが、retrieval trace と動的 activation を保存するため read-only ではない。annotation は表示上の hint であり、認証・認可の代替ではない。

judgment 専用三 tool は通常 `search` の feedback loop から分離されている。`search_judgments` は trace ID を発行せず、`get_judgment` は stable identity を完全一致で取得し、`traverse_judgments` は有限 hop の typed relation を決定的に辿る。三 tool は成功時・失敗時とも persistent table を変更しない。`search_judgments` と `traverse_judgments` は既定で active judgment だけを返し、archived は `include_archived=true` の時だけ含める。

## 3. Shared identifiers and validation

### 3.1 `trace_id`
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
10. 活性値は半減期に従って時間減衰する。
11. 活性減衰はノード確信度とエッジ事実性を変更しない。
12. 同一コーパスで通常のハイブリッド検索とグラフ統合検索を比較できる。
13. 任意 MCP adapter の `search`、`record_source_use`、`record_outcome` 契約を、実装と transport から独立して定義する。
13. 任意 MCP adapter の `search`、`record_source_use`、`record_outcome`、`write_judgment` と judgment 専用 read tool 契約を、実装と transport から独立して定義する。
14. source-use を `retrieved`、`selected`、`validated`、`used` に分け、新規 `used` への遷移だけを即時 reinforcement に接続する。
15. `corrected`、`rolled_back` などの delayed outcome を source-use と別に記録し、初期契約では edge weight を自動変更しない。
16. MCP adapter は trace、node、enum、stage 順序、idempotency を境界で検証する。
Expand Down Expand Up @@ -106,6 +106,7 @@
87. outcome-driven deactivation evaluation はcontrol / candidate、`corrected` / `rolled_back` / `superseded`、exact credited / sibling inverse、baseline floor、dormancy / reactivation、rank / locality、source isolation、exclusive outputを結果観測前に固定する。protocolはregistered output不在のfreeze-only PRで固定し、そのsquash merge後のsuccessor Issueでdevelopmentを一度だけ実行する。全hard gate通過時だけholdoutを一度開き、観測前後にquery、case、schedule、metric、gate、default、live configを変更しない。
88. NGR 自身の新規 judgment graph は SQLite の stable identity、revision、lifecycle、provenance、typed relation を machine-readable 正本とする。add / update / supersede / archive / restore / hard-delete candidate は raw SQL でなく atomic domain API を通し、stale revision、dangling relation、部分更新、二重 successor を fail closed にする。archive は通常 retrieval から外す論理的忘却、hard delete は履歴参照のない archived candidate だけに許す物理削除として分離する。current graph の deterministic export / atomic import と SQLite backup / integrity-checked restore を維持し、既存 Wiki entry の本番移行は fixture 検証後に分離する。
89. Li+ / NGR Decision Structure Wiki pilot は各 repository の index が列挙する entry だけを専用の新規 SQLite へ取り込み、repository namespace 付き identity、page 本文、Wiki URL、repository、取得 commit、source state、typed relation を保持する。duplicate identity、unknown relation target、parser ambiguity、partial publication、既存出力の上書きを fail closed にし、SQLite / supersession integrity、deterministic export、backup を検証する。Wiki、既存検索 DB、凍結済み feedback 実験 DB は変更せず、本 pilot だけで正本を切り替えない。
90. judgment 専用 read API は `search_judgments`、`get_judgment`、`traverse_judgments` を提供し、current revision、lifecycle、statement、rationale、provenance、typed relation を返す。search は judgment の既存 node projection に同じ lexical / dense scorer と有効 weight を適用し、既定で active のみ、明示指定時だけ archived を含め、repository namespace で絞り込める。traversal は relation type、incoming / outgoing / both、1 以上の有限 hop を受け、cycle-safe な hop 優先・stable identity 順を維持する。三操作と対応 MCP tool は成功時・失敗時とも judgment、revision、relation、retrieval trace、feedback、node、edge、activation を永続変更せず、MCP は read-only annotation、未知 field を拒否する schema、既存 error envelope を持つ。既存 `search`、feedback、`write_judgment`、library default は変更しない。
75. v3 implementation、prompt、manifest、query override、schema、集約、path audit、hash規則、gate、stop rule、testsをresult-free commitでpushした後、development stage / 4 case packet / 12 responses / resultを各一度だけ生成する。
76. development全12 gate通過時だけholdout stageを一度生成し、異なるfresh 12 judgesで同じgateを評価する。packet、response、resultの上書き、観測後の規則変更、実LLM品質値のCI再生成を拒否する。

Expand Down
9 changes: 8 additions & 1 deletion src/neuron_graph_rag/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,16 @@ def __init__(
) -> None:
self.config = config or EngineConfig()
self.store = SQLiteStore(database)
self.judgments = JudgmentGraph(self.store)
self.sparse_retriever = BM25Retriever()
self.dense_retriever = DenseRetriever(dense_encoder)
self.judgments = JudgmentGraph(
self.store,
sparse_retriever=self.sparse_retriever,
dense_retriever=self.dense_retriever,
sparse_weight=self.config.sparse_weight,
dense_weight=self.config.dense_weight,
use_dense_retrieval=self.config.use_dense_retrieval,
)

def close(self) -> None:
self.store.close()
Expand Down
Loading