Back to list
dev_to 2026年4月17日

なぜグラフ埋め込みが重要なのか

Why Graph Embeddings Matter

Translated: 2026/4/17 11:03:49

Japanese Translation

ベクトルデータベースは確率的であり、遅い。グラフ埋め込みは決定論的であり、ミリ秒未満です。AI コーディングエージェントのコンテキスト構築、あるいは結果が返された理由を知る必要があるどのシステムであっても、その違いは学術的な議論にはすぎません。それはアプリケーションが何を約束できるかを変更します。 Terraphim は概念を知識グラフのノードとして表現し、同義語やエッジの数によってそれらをランク付けします。埋め込みモデル、GPU、1024 次元空間における各クエリごとの距離計算はありません。一度構築された Aho-Corasick 自動機は、入力長と一致数の合計に対して O(n+m+z) の時間でクエリ処理されます。この機構は詳細に「Graph Embeddings 参照ページ」で説明されており、この記事はそれがなぜ重要なのかについてです。 3 つの数字が論点を担っています。いずれもラップトップ上で再現可能です。 140 万のパターンを 1 ミリ秒以内に一致させ、4 GB 以下の RAM で処理します。これは、同一のプロセスでクエリサービスを行うマルチロール知識グラフ(オペレータ、エンジニア、アナリスト)のワーキングセットです。 知識グラフ推論ステップごとに 5〜10 ナノ秒。マイクロ秒ではなく、ナノ秒です。自動機が構築されれば、トラベルはバイトスライスとグラフエッジに対するタイトループであり、現代の CPU はそれに対して非常に適応しています。 20 ミリ秒でロールの埋め込みからゼロから再構築します。同義語を変更し、新しい用語を追加し、古いものを削除する——ロールの全グラフがエディタが次のフレームをレンダリングする前に再構成されます。 比較のために、典型的なベクトル DB の近邻検索クエリは、埋め込み API 呼び出し(50〜500 ミリ秒)とネットワークラウンドトリップを支払い、5〜50 ミリ秒の範囲に入ります。私たちは同一の regime にいません。 これらの数字自体が興味深いものです。それが重要なのは、それによって何ができるかだからです。 Terraphim の一致はすべて、知識グラフ内の特定のエッジと特定のロール内の特定の同義語に遡ります。「モデルが言った」というわけではありません。検索がドキュメントを返せば、一致した特定の手順、どのロールのグラフが同義語を提供したか、それらを接続したエッジは何かをユーザーに正確に示せます。それはデバッグ上の優位性ではありません。事後に判断を防御する必要があるどの分野でも、それは規制上の要件です。ヘルスケア、法務、金融、政府。ベクトル検索は設計上、これを行うことはできません。 新しい概念を追加することはテキスト編集です。同義語を書き下ろし、Terraphim をファイルに指示し、グラフは 20 ミリ秒で再構築されます。トレーニングラン、GPU 請求、そして「新しいコーパスに再トレーニングをスケジュールする必要があります」ということはありません。欠点を認識してそれを修正するループが、数日や数週から秒に短縮されます。プロジェクトの語彙をオンボーリングの途中であれだけ学ぶ必要がある AI コーディングエージェントにとって、これは作業するツールと停止するロールアウトの違いです。 一致は正規化された用語に基づいて行われるため——明示的に提供された同義語——グラフ内の同じノードは、追加コストなしで英語、フランス語、ロシア語、そして中国語のラベルを担うことができます。言語検出ステップ、単一言語の埋め込みモデル、独立したインデックスはありません。クエリ「consensus」とクエリ「консенсус」が、グラフにそれらが同義語であると指示していれば同じノードに到達します。停止語リストは無視されます:単語がグラフに含まれていなければ一致しません、それだけが事実です。 上記の部分はインフラストラクチャです。物語のアーチは続きます: AI コーディングエージェントの出力を決定論的に変換するフックを構築します。Claude Code が npm install を提案すると、グラフ埋め込みの一致を介してそれを干渉させ、bun install に置き換えます。私たちはこれを「Teaching AI Coding Agents with Knowledge Graph Hooks」という記事でまとめました。その記事は、このエンジンが可能にすることを示すデモです。 ミスを捕捉し再利用します。エージェントが更正された場合、その更正を新しい同義語として保存し、次回のセッションではそれは繰り返されません。「Teaching AI Agents to Learn from Their Mistakes」と「Learning via Negativa」をご覧ください。 4 GB のプロセス全体をラップトップ上で実行し、ネットワーク呼び出しなしに実行します。コンパクトさは偶然ではありません。これは Origin から来たエンジニアリングの布告です。

Original Content

Vector databases are probabilistic and slow. Graph embeddings are deterministic and sub-millisecond. If you are building context for an AI coding agent — or any system where you need to know why a result came back — the difference is not academic. It changes what your application is allowed to promise. Terraphim represents concepts as nodes in a knowledge graph and ranks them by how many synonyms and edges connect them. There is no embedding model, no GPU, no per-query distance computation in a 1024-dimensional space. There is an Aho-Corasick automaton built once, queried in O(n+m+z) time over the input length plus the number of matches. The mechanism is described in detail on the Graph Embeddings reference page; this post is about why it matters. Three numbers carry the argument. Each is reproducible on a laptop. 1.4 million patterns matched in under one millisecond, with under 4 GB of RAM. That is the working set behind a multi-role knowledge graph — operator, engineer, analyst — held resident in the same process that serves the query. 5–10 nanoseconds per knowledge-graph inference step. Not microseconds. Nanoseconds. Once the automaton is built, traversal is a tight loop over byte slices and graph edges, and modern CPUs are extremely good at that. 20 milliseconds to rebuild the embeddings for a role from scratch. Rename a synonym, add a new term, drop an obsolete one — the whole role's graph is reconstituted before your editor has rendered the next frame. For comparison, a typical vector-DB nearest-neighbour query lands in the 5–50 ms range after you have paid the embedding API call (50–500 ms) and the network round-trip. We are not in the same regime. The numbers are interesting on their own. The reason they matter is what they let you build. Every match in Terraphim traces back to a specific edge in the knowledge graph and a specific synonym in a specific role. There is no "the model said so." When a search returns a document, you can show the user exactly which terms matched, which role's graph supplied the synonym, and which edges connected them. That is not a debugging nicety — it is a regulatory requirement in any domain where you have to defend a decision after the fact. Healthcare, legal, finance, government. Vector search by construction cannot do this. Adding a new concept is a text edit. You write the synonym down, you point Terraphim at the file, the graph rebuilds in 20 ms. There is no training run, no GPU bill, no "we need to schedule a retrain on the new corpus." This collapses the loop between noticing a gap and fixing the gap from days or weeks to seconds. For an AI coding agent that needs to learn a project's vocabulary as you onboard, this is the difference between a working tool and a stalled rollout. Because matching is done on normalised terms — synonyms you supply explicitly — the same node in the graph can carry English, French, Russian, and Mandarin labels at no extra cost. There is no language-detection step, no per-language embedding model, no separate index. The query "consensus" and the query "консенсус" both reach the same node if you have told the graph they are synonyms. Stop-word lists become irrelevant: if a word is not in the graph, it does not match, full stop. The pieces above are infrastructure. The story arc continues: Build hooks that transform AI coding agent output deterministically. When Claude Code suggests npm install, intercept it via a graph-embeddings match and replace it with bun install. We wrote this up at Teaching AI Coding Agents with Knowledge Graph Hooks — that post is the demo of what this engine enables. Capture and reuse mistakes. When an agent gets corrected, store the correction as a new synonym and the next session never repeats it. See Teaching AI Agents to Learn from Their Mistakes and Learning via Negativa. Run the whole thing in a 4 GB process on your laptop with no network calls. The compactness is not an accident — it is the engineering brief from the Origin Story, which explains where the design came from and why it has stayed this small. If you want to wire this into your own project, the Command Rewriting How-to walks through the moving parts: where to put your synonyms, how the role graph is built, how hooks call the matcher. The mechanism — automata, ranking formula, ASCII walk-through — is on the Graph Embeddings reference page. Read that next if you want the data structures. The current default in the AI tooling ecosystem is to reach for a vector database the moment anyone mentions "semantic search." It is the path of least resistance because the tools are well-marketed and the API surface is familiar. But for a large class of problems — explainability-first systems, on-device agents, anywhere you need a hard latency budget or a hard explainability guarantee — graph embeddings are the better-engineered answer. Not the only answer; the better one for that class. The promotion campaign over the next few weeks goes deeper: a sub-millisecond context article walks through the FST/Aho-Corasick implementation, and the Context Engineering with Knowledge Graphs book (launching in May) puts it in the wider context of moving from RAG to context graphs. Until then: read the reference, try the how-to, and let us know in Discourse what you build with it.