0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Databricks と GraphDB にて Microsoft GraphRAG with an RDF Knowledge Graph の記事を実行する方法

Last updated at Posted at 2025-10-23

概要

Databricks と GraphDB にて Microsoft GraphRAG with an RDF Knowledge Graph の記事を実行する方法を紹介します。 RDF による Microsoft GraphRAG を実装する方法が 3 つの記事で公開されており、ローカルの GraphDB 、 LLM Studio 、そして、 Elasticsearch で実行コードとデータが公開されています。この記事では環境構築を最小限とするために、無償で利用可能なクラウドサービスである GraphDB と Databricks で実行する方法を詳細に説明します。

GitHub にて公開されているレポジトリのライセンスが GNU General Public License v3.0 であっため、フォークと修正を実施したコードを下記で公開しています。

事前準備

Graphwise Sandbox の準備

Graphwise Sandbox は無償でアカウントを作成でき、容易に Graph DB を利用できます。下記の記事で手順を紹介しています。

Databricks Free Edition の準備

下記リンク先のドキュメントに参考に簡単に無償で利用できるアカウントを作成できます。

ファイルのダウンロード

記事で紹介されている Google Drive のリンク先からファイルをダウンロードします。

image.png

出所:Microsoft GraphRAG with an RDF Knowledge Graph — Part 2 | by Ian Ormesher | Medium

image.png

複数の zip ファイルがあるため、すべて解凍します。

image.png

実施手順

GraphDB のプロジェクトの作成

Graphwise Sandbox にアクセスし、 Projects -> Start project を選択します。

image.png

GraphDB Vanilla を選択し、Start project を選択します。

image.png

Nameに名称を入力後、Launch Projectを選択します。

image.png

GraphDB のセットアップ

作成したプロジェクトにて Username 、 Password を控えて、Open GraphDBを選択し、 GraphDB のログイン画面を表示させます。

image.png

ユーザーID とパスワードを入力しログインします。

image.png

左側のImportタブを選択し、+ Create new repositoryを選択します。

image.png

GraphDB Repositoryを選択します。

image.png

Repository IDmsft-graphragと入力し、Createを選択します。

image.png

再度、Importタブを選択し、Upload RDF filesを選択します。msft-graphrag.owlchunk_300_parquetフォルダ内のmsft-graphrag-300-chunk-size.ttlをそれぞれアップロードします。

image.png

image.png

image.png

image.png

インポート後、 2 つのファイルを取り込めていることを確認します。

image.png

左側のSPARQLタブを選択し、デフォルトで表示されている SPARQL のコードを実行し結果が出力されることを確認します。

image.png

Databricks 側で設定する Project URL 、 Username 、 Password の値を控えます。

image.png

Databricks にレポジトリのクローンと接続情報のセット

Databricks Free Edition にログインし、左側のタブにあるWorkspace -> 右側のCreate -> Git Folderを選択します。

image.png

Git Repository URLhttps://github.com/manabian-/msft_graphrag_blog.gitの値を入力し、Craete Git folderを選択します。

image.png

by_databricks/00_configノートブックを表示し、Set information for GraphDBのセルに GraphDB の接続情報の値をセットします。。

image.png

パスワード等は Databricks シークレットに格納することが推奨されていますが、本手順では省略しています。

by_databricks/00_setupノートブックに移動し、Prepare Graph DB のセルを実行して GraphDB からデータを取得できることを確認します。

image.png

image.png

Databricks にてリソースを作成

by_databricks/00_setupノートブックのDatabricks Setupのセルを順次実行します。

image.png

作成した Volume の URL リンクを選択し、Filesタブを選択後、chunk_300_parquetフォルダのcreate_final_entities.parquetをアップロードします。

workspace_url = spark.conf.get("spark.databricks.workspaceUrl")
volume_url = f"https://{workspace_url}/explore/data/volumes/{CATALOG}/{SCHEMA}/{VOLUME}"
displayHTML(f'<a href="{volume_url}" target="_blank">[VolumeへのURLリンク]</a>')

image.png

image.png

Databricks Mosaic AI Vector Search のエンドポイントとインデックスの作成

by_databricks/00_setupノートブックのCreate Mosaic AI Vector Search endpointのセルを実行して、Databricks Mosaic AI Vector Search のエンドポイントを作成します。10分程度かかります。

image.png

Create Mosaic AI Vector Search Indexのセルを順次実行して、Databricks Mosaic AI Vector Search のインデックスを作成します。

image.png

image.png

01_create_local_global の実行

by_databricks/01_create_local_globalRun allで実行

image.png

01_create_local_global の結果確認

質問内容と想定結果

質問:What is the relationship between Bob Cratchit and Belinda Cratchit?

想定回答: Belinda Cratchit is Bob Cratchit’s daughter.

Local search の結果確認

Prompt with no context の結果

回答が誤っている。

In the novel "A Christmas Carol" by Charles Dickens, there is actually no mention of a Belinda Cratchit. The name Belinda is not associated with the Cratchit family in the book.\n\nThe main female character in the Cratchit family is actually Mrs. Cratchit, née Emily, who is the wife of Bob Cratchit and the mother of their children, including Tiny Tim.

image.png

チャールズ・ディケンズの小説『クリスマス・キャロル』には、ベリンダ・クラチットという人物は実際には登場しません。ベリンダという名前は、作中に登場するクラチット家とは一切関係がありません。\n\nクラチット家の主な女性登場人物は、ボブ・クラチットの妻であり、タイニー・ティムを含む子供たちの母親であるクラチット夫人(旧姓エミリー)です。

上記の翻訳

Prompt with context from Knowledge Graph の結果

娘と回答しているため正解。

According to the summary of the data, Belinda Cratchit is a daughter of Bob Cratchit, and Mrs. Cratchit (Bob's wife) assists with household tasks such as managing the cloth. Additionally, it mentions that Mrs. Cratchit and Miss Belinda (presumably another reference to Belinda Cratchit) collaborate on food preparation for the family gathering.

image.png

資料の要約によると、ベリンダ・クラチットはボブ・クラチットの娘であり、クラチット夫人(ボブの妻)は布の管理などの家事を手伝っている。さらに、クラチット夫人とミス・ベリンダ(おそらくこれもベリンダ・クラチットのこと)が家族の集まりのための料理の準備を協力して行っていることも記されている。

Global search の結果確認

**Summary of the Story**

The story revolves around the transformation of Ebenezer Scrooge, a miserly and isolated individual, into a kinder and more compassionate person. The story explores the complexities of Scrooge's relationships with other entities, including his nephew, clerk, and the Ghosts, which highlights the importance of kindness and compassion.

**Key Plot Points**

The story begins with Scrooge being visited by the Ghost of Christmas Past, who guides him through his past experiences, influencing his perspective on his own life and behavior. Scrooge is then visited by the Ghost of Christmas Present, who shows him his present and future experiences, highlighting the consequences of his actions. Finally, Scrooge is visited by the Ghost of Christmas Yet to Come, who shows him a potential future where he has died and is remembered as a cruel and miserly person.

**Themes and Implications**

The story touches on the themes of self-discovery, redemption, and personal growth, as Scrooge undergoes a significant change in his life and behavior. The story highlights the importance of kindness, compassion, and generosity, and how these qualities can positively impact one's life and relationships. The story also raises questions about the impact of the Ghost's visit on Scrooge's character development and potentially changing behavior.

**Relevant Entities and Relationships**

Scrooge's relationships with his nephew, clerk, and the Ghosts play a significant role in shaping his perspective and behavior. The story also features interactions between Scrooge and other entities, such as The Schoolmaster, Master Scrooge, and The Plump Sister, which suggest their significance in the story's dynamics.

**Data References**

The story is supported by data from various sources, including:

* Entities (100, 96, 136, 93, 107)
* Relationships (93, 107, 92, 197, 199)
* Reports (59, 74, 62, 73, 321, 220)
* Christmas Past (37), Christmas Present (103), and Christmas Yet to Come (121)

**+more**

image.png

**物語の要約**

この物語は、けちで孤独なエベニーザー・スクルージが、より優しく思いやりのある人間へと変貌を遂げる過程を描いています。物語は、スクルージと甥、事務員、そして幽霊たちといった他者との複雑な関係性を探求し、優しさと思いやりの大切さを浮き彫りにしています。

**あらすじ**

物語は、スクルージが過去のクリスマスの幽霊に訪ねられるところから始まります。幽霊はスクルージの過去の経験を導き、彼自身の人生観や行動に影響を与えます。次に、現在のクリスマスの幽霊がスクルージに訪ね、現在と未来の経験を見せ、彼の行動が招いた結果を浮き彫りにします。最後に、未来のクリスマスの幽霊がスクルージに訪ね、彼が死に、残酷でけちな人物として記憶される未来を見せます。

**テーマと意味**

この物語は、スクルージの人生と行動に大きな変化を経験する中で、自己発見、贖罪、そして個人的な成長というテーマに触れています。物語は、優しさ、思いやり、寛大さの大切さ、そしてこれらの資質が人生や人間関係にどのような良い影響を与えるかを強調しています。また、幽霊の訪問がスクルージの人格形成と行動の変化にどのような影響を与えたのかという疑問も提起しています。

**関連する存在と関係**

スクルージと、甥、書記、そして幽霊たちとの関係は、彼の視点と行動を形成する上で重要な役割を果たしています。物語には、スクルージと、校長、スクルージ先生、ふくよかな妹といった他の存在との交流も描かれており、物語の力学における彼らの重要性を示唆しています。

**データ参照**

このストーリーは、以下の様々な情報源から得たデータに基づいています。

* エンティティ (100、96、136、93、107)
* リレーションシップ (93、107、92、197、199)
* レポート (59、74、62、73、321、220)
* 過去のクリスマス (37)、現在のクリスマス (103)、これからのクリスマス (121)

**その他**

上記の翻訳

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?