GraphRag-Accelerator をまずは動かしてみる

https://www.microsoft.com/en-us/research/project/graphrag/

マイクロソフトがオープンソース化した新しいRAGシステム「GraphRAG」

そして以下の**GraphRag Accelerator**は、Azure上でGraphRagを動かすために必要なリソースをデプロイするIaCや、nodebooks形式での実行コードが含まれているレポジトリです。

https://github.com/Azure-Samples/graphrag-accelerator

試してみたところ、ガイドに沿って進める事で簡単にデプロイできましたが、自身の備忘録も兼ねて構築過程と遭遇したエラーなどを記載します。

## 事前準備
手順は[コチラ](https://github.com/Azure-Samples/graphrag-accelerator/blob/main/docs/DEPLOYMENT-GUIDE.md)のガイドに沿って進めます。
1. レポジトリをクローン後にVSCode [DevContainers](https://code.visualstudio.com/docs/devcontainers/containers)で開く
2. Azure RBAC 権限はサブスクリプションスコープで`Contributor` `Role Based Access Control (RBAC) Administrator`が必要
3. リソースプロパイダーに`Microsoft.OperationsManagement`と`Microsoft.AlertsManagement`を登録
    ```bash
    az provider register --namespace Microsoft.OperationsManagement
    az provider register --namespace Microsoft.AlertsManagement

    # プロバイダーが登録されていることを確認する
    az provider show --namespace Microsoft.OperationsManagement -o table
    az provider show --namespace Microsoft.AlertsManagement -o table
    ```
    上記コマンドかポータル画面で `サブスクリプション` > `リソースプロパイダー`から登録
    
    ![1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2821082/0600f19d-8b37-8905-3d17-21e208193903.png)
    <br>


4. Azure OpenAIサービスとモデルをデプロイ
    今回使用したのは `gpt-4o`と`text-embedding-ada-002`
    [TPM(Tokens-per-Minute)](https://learn.microsoft.com/ja-jp/azure/ai-services/openai/how-to/quota?tabs=rest#introduction-to-quota)は`gpt-4o`が100K `text-embedding-ada-002`を300kに。
    ![2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2821082/92cd7708-524b-90e2-f9e7-992ad9de6332.png)
    <br>

5. Azure Login ~ リソースグループの作成
    ```bash
    az login
    az account show
    az account set --subscription "<subscription id>"
    
    az group create --name <my_resource_group> --location japaneast
    ```
    <br>
    
6. パラメータファイルに加筆
    ```json:infra/deploy.parameters.json
    {
      "GRAPHRAG_API_BASE": "<openai-service-endpoint>",
      "GRAPHRAG_API_VERSION": "2023-03-15-preview",
      "GRAPHRAG_EMBEDDING_DEPLOYMENT_NAME": "text-embedding-ada-002",
      "GRAPHRAG_EMBEDDING_MODEL": "text-embedding-ada-002",
      "GRAPHRAG_LLM_DEPLOYMENT_NAME": "gpt-4o",
      "GRAPHRAG_LLM_MODEL": "gpt-4o",
      "LOCATION": "japaneast",
      "RESOURCE_GROUP": "<resource-group-name>"
    }
    ```
    ※Azure OpenAI Serviceのエンドポイントは `AzureOpenAIService` > `リソース管理` > `キーとエンドポイント`から確認
    ![2024-07-17_18h58_15.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2821082/56c4feb5-2965-6861-5547-c9bcf2c34d8e.png)
    <br>

7. デプロイ
    デプロイ用のスクリプトが用意されているのでそれを実行する
    ```bash
    cd infra
    bash deploy.sh -h

    Usage: bash deploy.sh [-h|d|g] -p <deploy.parameters.json>
    Description: Deployment script for the GraphRAG Solution Accelerator.
    options:
      -h     ヘルプメニューを表示。
      -d     プライベート・エンドポイントの使用を無効にする.
      -g     開発者専用です。このスクリプトをデプロイすると、Azure Storage、AI Search、CosmosDBへのアクセスが許可されます。プライベートエンドポイント (-d) を無効にし、デバッグモードを有効にします。
      -p    デプロイパラメータを含むJSONファイルを指定（deploy.parameters.json)
      
      
    bash deploy.sh -g -p deploy.parameters.json
    ```
    私の場合は30~40分ほどでデプロイ完了しました。

:::note warn
遭遇したエラー
:::
- 必要なCPUコア数が、現在のクォータを超えている
> Operation could not be completed as it results in exceeding approved Total Regional Cores quota. Additional details - Deployment Model: Resource Manager, Location: japaneast, Current Limit: 20, Current Usage: 6, Additional Required: 16, (Minimum) New Limit Required: 22. Setup Alerts when Quota reaches threshold. …

`az vm list-usage --location japaneast --output table` で確認。
クオータ増加依頼か既存で使っている仮想マシンなどを消去して解消。

- standard_d4s_v5 のSKUが無い
> Preflight validation check for resource(s) for container service aks-kluy2zvbjcn7w in resource group graphrag-test-rg failed. Message: Preflight validation check for resource(s) for container service aks-kluy2zvbjcn7w in resource group MC_graphrag-test-rg_aks-kluy2zvbjcn7w_japanwest failed. Message: The requested VM size for resource 'Following SKUs have failed for Capacity Restrictions: standard_d4s_v5' is currently not available in location 'japanwest'. 

当初、Japan Westにデプロイしようとしてエラー。Japan Eastに変更して解消。


- 同じ名前のAPI Managementが存在する
> Api service already exists: apim-×××××××× …

一度デプロイに失敗したリソースを削除して再デプロイを行った際にエラー
API Managementは48時間の間は論理削除になるらしい。
リソースグループ名が同じだとリソース名が同一のままなのでをリソースグループ名を変更して再デプロイする事で解消

## GraphRag構築
1. `notebooks/get-wiki-articles.py` を実行してウィキペディアからサンプルデータを取得
    ```diff_python:notebooks/get-wiki-articles.py
    import argparse
    import os

    import wikipedia

    + wikipedia.set_lang("ja")
    + manga = [
    + "ドラゴンボール",
    + "カカロット",
    + "ベジータ",
    + "クリリン",
    + "ピッコロ",
    + ]
    ...
    ```
    ```bash
    python get-wiki-articles.py testdata

    Saving wiki article 'ドラゴンボール' to testdata/ドラゴンボール_wiki_article.txt
    Saving wiki article '孫悟空_(ドラゴンボール)' to testdata/孫悟空_(ドラゴンボール)_wiki_article.txt
    Saving wiki article 'ベジータ' to testdata/ベジータ_wiki_article.txt
    Saving wiki article 'クリリン' to testdata/クリリン_wiki_article.txt
    Saving wiki article 'ピッコロ' to testdata/ピッコロ_wiki_article.txt
    ```
    <br>
2. notebooks/1-Quickstart.ipynb を順に進めていく
    - API Management のサブスクリプションキーとゲートウェイURLは以下から確認
    ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2821082/b47683de-d3ca-05cb-73b5-dceb3b5d67bc.png)
    ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2821082/0c0759a2-5fce-7ca2-f9fa-cec1755a0d8e.png)
    <br>
    
    - `Setup directories and API endpoint`
    ```python
    """
    These parameters must be defined by the notebook user:

    - file_directory: テキストファイルのローカルディレクトリ。ファイル構造はネストされたディレクトリのないフラットなものでなければならない。(例：file_directory/file1.txt、file_directory/file2.txtなど）。
    - storage_name: file_directory`のファイルがアップロードされる、Azureのblobストレージコンテナを識別するための一意な名前。
    - index_name: 同じ`storage_name` blob ストレージコンテナから複数のインデックスを作成することができる。				
    - endpoint: GraphRAG API のベース/エンドポイント (APIMゲートウェイURL)
    """

    file_directory = "testdata"
    storage_name = "test-files"
    index_name = "graphrag-index"
    endpoint = "https://apim-××××××××××.azure-api.net"
    ```
    - `Check status of an indexing job`
    インデックス作成の進行状況を確認できる。`status: complete` になるまで待つ。すごく時間がかかった。※私の場合は1時間以上待って完了した。

## 構築したAPIエンドポイントを確認
グローバルクエリ
> グローバルクエリーはリソースを大量に消費するが、データセット全体を理解する必要がある質問には良い回答を提供する。

```bash:bash
curl -X POST 'https://apim-××××××××××××.azure-api.net/query/global' \
-H 'Content-Type: application/json' \
-H 'Ocp-Apim-Subscription-Key: <Apim SubscriptionKey>' \
-d '{"index_name":"graphrag-index", "query":"ドラゴンボールで1番強いのは誰？"}'
```
<details><summary>レスポンス</summary>

```json:json
{
    "result": "### ドラゴンボールで最も強いキャラクターについて\n\nドラゴンボールシリーズにおいて、最も強いキャラクターを一人に絞るのは非常に難しいです。これは、キャラクターごとに異なる能力や変身形態があり、それぞれが異なる状況で圧倒的な力を発揮するためです。以下に、特に強力とされるキャラクターたちを紹介します。\n\n#### 孫悟空 (Goku)\n孫悟空は、ドラゴンボールシリーズの中で最も頻繁に強さが議論されるキャラクターの一人です。彼はスーパーサイヤ人3、スーパーサイヤ人ゴッド、そしてウルトラ本能（Ultra Instinct）など、数々の強力な変身を遂げています。特にウルトラ本能は、彼の戦闘能力を飛躍的に向上させ、ジレンとの激闘でその真価を発揮しました [Data: Reports (18, 99, 101, 102, 822, +more)]。\n\n#### ジレン (Jiren)\nジレンは「力の大会」において宇宙11を代表する戦士で、その圧倒的な力と戦闘能力で知られています。彼は悟空の元気玉を無傷で受け止めるなど、その強さは計り知れません。ジレンと悟空、ベジータ、フリーザとの戦いはシリーズの中でも特に重要なシーンです [Data: Reports (102, 345, 742, 225, 982, +more)]。\n\n#### ベジータ (Vegeta)\nベジータもまた、シリーズを通じて強力なキャラクターとして描かれています。彼はスーパーサイヤ人ゴッドやスーパーサイヤ人ブルーなどの変身を遂げ、ジレンやトッポとの戦いでその力を証明しました。特にトッポとの戦いでは、破壊神の力を持つトッポを打ち破ることで、その戦略的な強さを示しました [Data: Reports (24, 48, 102, 1474, 1457)]。\n\n#### フリーザ (Frieza)\nフリーザは、ドラゴンボールシリーズの主要な敵役の一人で、その変身能力と圧倒的な力で知られています。彼は何度も復活し、悟空や他のキャラクターと激しい戦いを繰り広げました [Data: Reports (47)]。\n\n#### ゼノ (Zeno)\nゼノ、または全王は、全宇宙の運命を決定する究極の権力者です。彼の力は絶大で、宇宙そのものを消滅させることができるため、ドラゴンボールの世界で最も強力な存在の一つとされています [Data: Reports (105)]。\n\n### 結論\nドラゴンボールシリーズには多くの強力なキャラクターが存在し、それぞれが異なる状況で圧倒的な力を発揮します。最も強いキャラクターを一人に絞るのは難しいですが、孫悟空、ジレン、ベジータ、フリーザ、そしてゼノが特に強力なキャラクターとして挙げられます。彼らの戦いと成長は、シリーズの魅力の一部となっています。",
    "context_data": {
        "reports": [
            {
                "id": "5",
                "title": "China and Bilibili's New Year Celebration",
                "content": "# China and Bilibili's New Year Celebration\n\nThe community centers around China and the significant cultural event hosted by Bilibili, which included a live performance by the youth dance group O-DOG. This event commemorated the 40th anniversary of the original work '龙珠' (Dragon Ball) and the New Year, attracting over 344 million viewers. Key entities include China, Bilibili, O-DOG, and the China Children's Press and Publication Group, which published the official version of '龙珠' in 2005.\n\n## China as the central entity\n\nChina is the central entity in this community, being the location where numerous pirated versions of '龙珠' were distributed and where the official version was published in 2005. Additionally, China hosted the Bilibili New Year celebration event, which recorded a historic viewership of over 344 million people. This highlights China's significant role in the distribution and cultural impact of '龙珠' [Data: Entities (1211), Relationships (402, 2829, 2830, 2831)].\n\n## Bilibili's role in cultural events\n\nBilibili is a key entity in this community, having hosted the New Year celebration event that commemorated the 40th anniversary of '龙珠' and the New Year. The event attracted over 344 million viewers, showcasing Bilibili's significant influence in the digital and cultural landscape of China. The platform's ability to draw such a large audience underscores its importance in the community [Data: Entities (1218), Relationships (2831, 2834, 2835)].\n\n## O-DOG's performance and cultural impact\n\nO-DOG, a youth dance troupe from China, performed during the Bilibili New Year celebration event. Their performance, which included a rendition of 'Dragon Ball,' was a key highlight of the event. The group's involvement in such a high-profile event underscores their cultural significance and the impact of their performance on the community [Data: Entities (1219), Relationships (2834, 2836)].\n\n## Significance of the New Year celebration event\n\nThe New Year celebration event hosted by Bilibili was a major cultural event in China, commemorating both the 40th anniversary of '龙珠' and the New Year. The event's historic viewership of over 344 million people highlights its massive impact and the importance of such cultural celebrations in the community [Data: Entities (1220), Relationships (2831, 2835, 2836)].\n\n## China Children's Press and Publication Group's role\n\nThe China Children's Press and Publication Group (中国少年儿童出版社) is a significant entity in this community, having started the official publication of '龙珠' in 2005. This publishing house played a crucial role in the distribution and popularization of the official version of '龙珠' in China, contributing to its cultural impact [Data: Entities (1213), Relationships (2829, 2830)].\n\n## Popularity and sales milestones of '龙珠' in China\n\n'龙珠' (Dragon Ball) achieved significant popularity and sales milestones in China, with the official version being published in 2005 by the China Children's Press and Publication Group. The widespread distribution and high sales of '龙珠' underscore its cultural significance and impact on the community [Data: Entities (1215), Relationships (2830)].",
                "rank": 8.5,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "5"
            },
            {
                "id": "75",
                "title": "Carddass Dragon Ball Series and Expansions",
                "content": "# Carddass Dragon Ball Series and Expansions\n\nThe community revolves around the Carddass Dragon Ball Series, a highly successful card game series introduced by Bandai in November 1988. This series has led to various expansions, including Super Battle and Jumbo Carddass, and has influenced the production of the Ensky Dragon Ball card series. The relationships between these entities highlight the significant impact and continued success of the Carddass Dragon Ball Series.\n\n## Carddass Dragon Ball Series as the central entity\n\nThe Carddass Dragon Ball Series is the central entity in this community, marking the beginning of the Dragon Ball card series and achieving major success since its release in November 1988. This series has become a cornerstone in the Dragon Ball franchise, leading to various expansions and significant sales milestones. Its central role is evident from its numerous relationships with other entities in the community, such as Super Battle, Jumbo Carddass, and the Ensky Dragon Ball card series [Data: Entities (1022), Relationships (2690, 2696, 2697, 2698)].\n\n## Bandai's role in the success of the Carddass Dragon Ball Series\n\nBandai played a crucial role in the introduction and success of the Carddass Dragon Ball Series. By launching this series, Bandai significantly contributed to its widespread popularity and commercial success. The relationship between Bandai and the Carddass Dragon Ball Series underscores the importance of Bandai's involvement in the development and distribution of the series [Data: Relationships (2690)].\n\n## Super Battle as a key expansion\n\nSuper Battle is one of the key expansions of the Carddass Dragon Ball Series, contributing to its overall popularity and success. This expansion has helped maintain the series' relevance and appeal among fans, further solidifying the Carddass Dragon Ball Series' position in the market. The relationship between Super Battle and the Carddass Dragon Ball Series highlights the importance of expansions in sustaining the series' success [Data: Entities (1023), Relationships (2696)].\n\n## Jumbo Carddass as another significant expansion\n\nJumbo Carddass is another significant expansion of the Carddass Dragon Ball Series, furthering its reach and impact. This expansion has played a role in enhancing the series' appeal and ensuring its continued success. The relationship between Jumbo Carddass and the Carddass Dragon Ball Series demonstrates the series' ability to evolve and expand over time [Data: Entities (1024), Relationships (2697)].\n\n## Influence on the Ensky Dragon Ball card series\n\nThe success of the Carddass Dragon Ball Series has influenced the production of the Ensky Dragon Ball card series. This relationship indicates the broader impact of the Carddass Dragon Ball Series on the Dragon Ball card game market, inspiring other series and contributing to the overall growth of the franchise. The connection between these two series highlights the Carddass Dragon Ball Series' role as a pioneer in the market [Data: Entities (1504), Relationships (2698)].\n\n## Super Dragon Ball Heroes as a continuation\n\nSuper Dragon Ball Heroes is a continuation of the success of the Carddass Dragon Ball Series, achieving significant card shipments. This continuation underscores the enduring popularity and influence of the original series, demonstrating its ability to inspire new iterations and maintain its relevance in the market. The relationship between Super Dragon Ball Heroes and the Carddass Dragon Ball Series highlights the series' lasting impact [Data: Relationships (2424)].",
                "rank": 8.5,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "75"
            },
            ...
        ],
        "entities": [],
        "relationships": [],
        "claims": []
    }
}
```
</details>

```bash:bash
curl -X POST 'https://apim-××××××××××××.azure-api.net/query/global' \
-H 'Content-Type: application/json' \
-H 'Ocp-Apim-Subscription-Key: <Apim SubscriptionKey>' \
-d '{"index_name":"graphrag-index", "query":"カカロットとは何者？"}'
```
<details><summary>レスポンス</summary>

```json:json
{
    "result": "### カカロットとは？\n\nカカロットは、ドラゴンボールシリーズの主要キャラクターである孫悟空の本名です。彼はサイヤ人という戦闘民族の一員であり、幼少期に地球に送られました [Data: Reports (20, 19, 95, 33, 88, +more)]。地球に到着した後、孫悟飯に育てられ、地球の守護者として数々の冒険を繰り広げます [Data: Reports (33, 88, 107, 80, 4, +more)]。\n\n### 主要な特徴と能力\n\nカカロットは、純粋な心を持ち、卓越した武術のスキルを持つキャラクターです。彼はスーパーサイヤ人やウルトラインスティンクトなど、さまざまな強力な変身形態を持ち、これらの形態は彼の戦闘力を大幅に向上させます [Data: Reports (111, 47, 31, 13, 11, +more)]。特にスーパーサイヤ人への変身は、シリーズの中で重要な転機となることが多いです [Data: Reports (47, 59)]。\n\n### 主要なストーリーアークと敵\n\nカカロットは、フリーザ、セル、魔人ブウなどの強力な敵との戦いで知られています。これらの戦いは、ドラゴンボールシリーズの主要なストーリーアークを形成し、彼の成長と戦闘能力の向上を描いています [Data: Reports (30, 103, 74, 10, +more)]。また、彼の兄であるラディッツが地球に来た際に、カカロットのサイヤ人としての出自が明らかになりました [Data: Reports (50)]。\n\n### 人間関係と影響\n\nカカロットは、ベジータやクリリン、フリーザなどのキャラクターと複雑な関係を持っています。これらの関係は、ライバル関係、友情、師弟関係など、多岐にわたります [Data: Reports (18, 48, 71, +more)]。彼の行動と犠牲は、地球の安全と平和に大きく貢献しており、シリーズ全体の物語を牽引しています [Data: Reports (23, 49, 109, 113, 100, +more)]。\n\n### 結論\n\nカカロットは、ドラゴンボールシリーズの中心的なキャラクターであり、彼の冒険と成長がシリーズの主要なストーリーラインを形成しています。彼の戦闘能力と変身形態、そして彼の人間関係は、シリーズ全体の魅力の一部です [Data: Reports (30, 103, 74, 10, +more)]。",
    "context_data": {
        "reports": [
            {
                "id": "5",
                "title": "China and Bilibili's New Year Celebration",
                "content": "# China and Bilibili's New Year Celebration\n\nThe community centers around China and the significant cultural event hosted by Bilibili, which included a live performance by the youth dance group O-DOG. This event commemorated the 40th anniversary of the original work '龙珠' (Dragon Ball) and the New Year, attracting over 344 million viewers. Key entities include China, Bilibili, O-DOG, and the China Children's Press and Publication Group, which published the official version of '龙珠' in 2005.\n\n## China as the central entity\n\nChina is the central entity in this community, being the location where numerous pirated versions of '龙珠' were distributed and where the official version was published in 2005. Additionally, China hosted the Bilibili New Year celebration event, which recorded a historic viewership of over 344 million people. This highlights China's significant role in the distribution and cultural impact of '龙珠' [Data: Entities (1211), Relationships (402, 2829, 2830, 2831)].\n\n## Bilibili's role in cultural events\n\nBilibili is a key entity in this community, having hosted the New Year celebration event that commemorated the 40th anniversary of '龙珠' and the New Year. The event attracted over 344 million viewers, showcasing Bilibili's significant influence in the digital and cultural landscape of China. The platform's ability to draw such a large audience underscores its importance in the community [Data: Entities (1218), Relationships (2831, 2834, 2835)].\n\n## O-DOG's performance and cultural impact\n\nO-DOG, a youth dance troupe from China, performed during the Bilibili New Year celebration event. Their performance, which included a rendition of 'Dragon Ball,' was a key highlight of the event. The group's involvement in such a high-profile event underscores their cultural significance and the impact of their performance on the community [Data: Entities (1219), Relationships (2834, 2836)].\n\n## Significance of the New Year celebration event\n\nThe New Year celebration event hosted by Bilibili was a major cultural event in China, commemorating both the 40th anniversary of '龙珠' and the New Year. The event's historic viewership of over 344 million people highlights its massive impact and the importance of such cultural celebrations in the community [Data: Entities (1220), Relationships (2831, 2835, 2836)].\n\n## China Children's Press and Publication Group's role\n\nThe China Children's Press and Publication Group (中国少年儿童出版社) is a significant entity in this community, having started the official publication of '龙珠' in 2005. This publishing house played a crucial role in the distribution and popularization of the official version of '龙珠' in China, contributing to its cultural impact [Data: Entities (1213), Relationships (2829, 2830)].\n\n## Popularity and sales milestones of '龙珠' in China\n\n'龙珠' (Dragon Ball) achieved significant popularity and sales milestones in China, with the official version being published in 2005 by the China Children's Press and Publication Group. The widespread distribution and high sales of '龙珠' underscore its cultural significance and impact on the community [Data: Entities (1215), Relationships (2830)].",
                "rank": 8.5,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "5"
            },
            {
                "id": "75",
                "title": "Carddass Dragon Ball Series and Expansions",
                "content": "# Carddass Dragon Ball Series and Expansions\n\nThe community revolves around the Carddass Dragon Ball Series, a highly successful card game series introduced by Bandai in November 1988. This series has led to various expansions, including Super Battle and Jumbo Carddass, and has influenced the production of the Ensky Dragon Ball card series. The relationships between these entities highlight the significant impact and continued success of the Carddass Dragon Ball Series.\n\n## Carddass Dragon Ball Series as the central entity\n\nThe Carddass Dragon Ball Series is the central entity in this community, marking the beginning of the Dragon Ball card series and achieving major success since its release in November 1988. This series has become a cornerstone in the Dragon Ball franchise, leading to various expansions and significant sales milestones. Its central role is evident from its numerous relationships with other entities in the community, such as Super Battle, Jumbo Carddass, and the Ensky Dragon Ball card series [Data: Entities (1022), Relationships (2690, 2696, 2697, 2698)].\n\n## Bandai's role in the success of the Carddass Dragon Ball Series\n\nBandai played a crucial role in the introduction and success of the Carddass Dragon Ball Series. By launching this series, Bandai significantly contributed to its widespread popularity and commercial success. The relationship between Bandai and the Carddass Dragon Ball Series underscores the importance of Bandai's involvement in the development and distribution of the series [Data: Relationships (2690)].\n\n## Super Battle as a key expansion\n\nSuper Battle is one of the key expansions of the Carddass Dragon Ball Series, contributing to its overall popularity and success. This expansion has helped maintain the series' relevance and appeal among fans, further solidifying the Carddass Dragon Ball Series' position in the market. The relationship between Super Battle and the Carddass Dragon Ball Series highlights the importance of expansions in sustaining the series' success [Data: Entities (1023), Relationships (2696)].\n\n## Jumbo Carddass as another significant expansion\n\nJumbo Carddass is another significant expansion of the Carddass Dragon Ball Series, furthering its reach and impact. This expansion has played a role in enhancing the series' appeal and ensuring its continued success. The relationship between Jumbo Carddass and the Carddass Dragon Ball Series demonstrates the series' ability to evolve and expand over time [Data: Entities (1024), Relationships (2697)].\n\n## Influence on the Ensky Dragon Ball card series\n\nThe success of the Carddass Dragon Ball Series has influenced the production of the Ensky Dragon Ball card series. This relationship indicates the broader impact of the Carddass Dragon Ball Series on the Dragon Ball card game market, inspiring other series and contributing to the overall growth of the franchise. The connection between these two series highlights the Carddass Dragon Ball Series' role as a pioneer in the market [Data: Entities (1504), Relationships (2698)].\n\n## Super Dragon Ball Heroes as a continuation\n\nSuper Dragon Ball Heroes is a continuation of the success of the Carddass Dragon Ball Series, achieving significant card shipments. This continuation underscores the enduring popularity and influence of the original series, demonstrating its ability to inspire new iterations and maintain its relevance in the market. The relationship between Super Dragon Ball Heroes and the Carddass Dragon Ball Series highlights the series' lasting impact [Data: Relationships (2424)].",
                "rank": 8.5,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "75"
            },
            ...
        ],
        "entities": [],
        "relationships": [],
        "claims": []
    }
}

```
</details>

ローカルクエリ
> ローカル検索クエリは、文書に記載されている特定のエンティティを理解する必要がある、焦点を絞った質問に最適。
```bash:bash
curl -X POST 'https://apim-××××××××××××.azure-api.net/query/local' \
-H 'Content-Type: application/json' \
-H 'Ocp-Apim-Subscription-Key: <Apim SubscriptionKey>' \
-d '{"index_name":"graphrag-index", "query":"ブルマの夫は誰？"}'
```
<details><summary>レスポンス</summary>

```json:json
{
    "result": "# ブルマの夫について\n\n## 概要\nブルマの夫はベジータです。彼らの関係は「ドラゴンボール」シリーズにおいて重要な役割を果たしています。以下に、ブルマとベジータの関係に関する詳細を示します。\n\n## ベジータとの関係\nブルマはベジータと結婚しており、二人の間にはトランクスとブラという二人の子供がいます。ベジータは惑星ベジータの王子であり、初期の頃は冷酷で残忍な性格でしたが、ブルマや他のキャラクターたちとの交流を通じて次第に変わっていきました。\n\n### 家族構成\n- **ブルマ**: 科学者であり、カプセルコーポレーションの一員。\n- **ベジータ**: 惑星ベジータの王子であり、戦士。\n- **トランクス**: ブルマとベジータの息子。\n- **ブラ**: ブルマとベジータの娘。\n\n## 重要なエピソード\nブルマとベジータの関係は、シリーズを通じて多くのエピソードで描かれています。例えば、ブルマの誕生日パーティーでは、ベジータが彼女のために参加し、普段とは異なる一面を見せるシーンがあります [Data: Relationships (1434)]。\n\nまた、ベジータはブルマの影響を受けて人間的な感情を見せるようになり、娘のブラに対しては特に甘い一面を持っています [Data: Entities (313); Relationships (1419, 1263, 1782)]。\n\n## 結論\nブルマの夫はベジータであり、彼らの関係は「ドラゴンボール」シリーズにおいて非常に重要です。ベジータはブルマとの関係を通じて大きく成長し、家族としての絆を深めています。\n\n---\n\nこの情報は、提供されたデータに基づいています。",
    "context_data": {
        "reports": [
            {
                "id": "242",
                "title": "ブラ and Her Influential Relationships",
                "content": "# ブラ and Her Influential Relationships\n\nThe community centers around ブラ, a character who significantly influences the actions of others through her comments and interactions. Key relationships include her family members ベジータ, ブルマ, and トランクス, as well as other characters like 悟飯, チチ, and 悟天. ブラ's actions often lead to notable reactions from these characters, highlighting her impact within the community.\n\n## ブラ's influence on her father ベジータ\n\nブラ is the daughter of ベジータ, born six years after the battle with ブウ. Her influence on her father is evident when she criticizes his beard, prompting him to shave it off. This interaction highlights the strong impact ブラ has on ベジータ's actions and decisions [Data: Entities (313); Relationships (1419)].\n\n## Family dynamics involving ブラ, ブルマ, and トランクス\n\nブラ is part of a family that includes her mother ブルマ and her brother トランクス. ブルマ's relationship with ブラ is significant, as ブラ was born six years after the battle with ブウ. The sibling relationship between ブラ and トランクス shows a dynamic where ブラ is treated more leniently, indicating a unique family dynamic [Data: Entities (313); Relationships (1263, 1782)].\n\n## ブラ's interactions with 悟飯 and their consequences\n\nブラ criticizes 悟飯's beard, leading him to shave it off. This interaction demonstrates ブラ's ability to influence the actions of others through her comments. The relationship between ブラ and 悟飯 is an example of how her opinions can lead to significant changes in the behavior of other characters [Data: Relationships (1357)].\n\n## ブラ's shopping incident and its dramatic outcome\n\nブラ is involved in a shopping incident where she is harassed by men, leading to a dramatic response involving a car. This incident underscores the potential for ブラ's interactions to escalate into significant events, affecting not only her but also those around her [Data: Entities (313); Relationships (2204)].\n\n## ブラ's interactions with 悟天 and their implications\n\nブラ interacts with 悟天, criticizing his beard and going shopping with him. These interactions highlight ブラ's active involvement in various situations and her ability to influence the actions and decisions of other characters, further emphasizing her role within the community [Data: Relationships (1809)].\n\n## Emotional reactions from チチ to ブラ's actions\n\nブラ's actions and interactions are observed by チチ, who reacts emotionally. This indicates that ブラ's behavior has a significant impact on the emotional state of other characters, further highlighting her influence within the community [Data: Relationships (1566)].\n\n## Indirect influence on 一星龍\n\nブラ's comment about appearance indirectly influences the dynamics involving 一星龍. This shows that even indirect interactions or comments from ブラ can have far-reaching effects on the relationships and dynamics within the community [Data: Relationships (2203)].",
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "242"
            },
            {
                "id": "219",
                "title": "桃白白 and Red Ribbon Army",
                "content": "# 桃白白 and Red Ribbon Army\n\nThe community centers around 桃白白, a character hired by the Red Ribbon Army to defeat the protagonist. 桃白白 has significant relationships with other key entities such as ボラ, whom he kills, and ウパ, ボラ's son. The community also includes nostalgic adversaries like ピラフ一味, who are remembered by the protagonist.\n\n## 桃白白's central role in the community\n\n桃白白 is a pivotal character in this community, hired by the Red Ribbon Army to defeat the protagonist. His actions, including the killing of ボラ, a friend of the protagonist, make him a significant figure. 桃白白's relationships with other entities, such as ピラフ一味, further emphasize his importance in the community [Data: Entities (595), Relationships (1639, 2495, 2496)].\n\n## Red Ribbon Army's influence\n\nThe Red Ribbon Army plays a crucial role in this community by hiring 桃白白 to defeat the protagonist. This relationship highlights the antagonistic nature of the Red Ribbon Army and its influence over key events and characters within the community [Data: Relationships (1639)].\n\n## Impact of ボラ's death\n\nThe killing of ボラ by 桃白白 is a significant event in the community. ボラ, who is a friend of the protagonist, has a direct relationship with his son, ウパ. This event not only affects the protagonist but also has a lasting impact on ウパ, adding emotional depth to the community's dynamics [Data: Entities (630, 631), Relationships (2496, 2524)].\n\n## Nostalgic adversaries\n\nBoth 桃白白 and ピラフ一味 are former adversaries who are nostalgically remembered by the protagonist. This nostalgic element adds a layer of complexity to the community, as it reflects on past conflicts and their lasting impressions on the protagonist [Data: Relationships (2495)].\n\n## ウパ's role and relationships\n\nウパ, the son of ボラ, becomes friends with the protagonist. His relationship with his father and the protagonist adds a personal dimension to the community, highlighting the interconnectedness of the characters and the emotional stakes involved [Data: Entities (631), Relationships (2524)].",
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "219"
            }
        ],
        "entities": [
            {
                "id": "129",
                "entity": "\"ブルマ (BULMA)\"",
                "description":"Bulma (\ブ\ル\マ) is a character in the Dragon Ball series, renowned for her intelligence and inventiveness. She is a close friend of Goku (\悟\空) and the wife of Vegeta. Bulma is the first person Goku meets other than his adoptive parent, Grandpa Gohan (\悟\飯), during her quest to find the Dragon Balls. She plays a significant role in the series, including informing others about Frieza's revival in the movie \"Dragon Ball Z: Resurrection 'F'\".",
                "number of relationships": "4",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "129"
            },
            {
                "id": "138",
                "entity": "\"ブルマの誕生日パーティー\"",
                "description": "\"ブルマの誕生日パーティー\" is an event where characters like 悟飯, ビーデル, 18号, マーロン, and 破壊神ビルス gather. Additionally, various characters, including ベジータ and ビルス, interact during this event, leading to significant incidents.",
                "number of relationships": "2",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "138"
            },
            {
                "id": "102",
                "entity": "\"坊主頭のキャラクター\"",
                "description": "",
                "number of relationships": "1",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "102"
            },
            {
                "id": "313",
                "entity": "\"ブラ\"",
                "description": "\"ブラ\" is a character who plays a significant role in influencing the actions of others through her comments. She is the daughter of ベジータ and ブルマ, born six years after the battle with ブウ. One notable instance of her influence is when she criticizes her father's beard, prompting him to shave it off. Additionally, ブラ is involved in a shopping incident where she is harassed by men, leading to a dramatic response involving a car. She also goes shopping with her father, further highlighting her active involvement in various situations.",
                "number of relationships": "8",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "313"
            },
            ...
        ]
    }
}
```
</details>

```bash:bash
curl -X POST 'https://apim-××××××××××××.azure-api.net/query/local' \
-H 'Content-Type: application/json' \
-H 'Ocp-Apim-Subscription-Key: <Apim SubscriptionKey>' \
-d '{"index_name":"graphrag-index", "query":"クリリンの妻は誰？"}'
```
<details><summary>レスポンス</summary>

```json:json
{
    "result": "# クリリンの妻について\n\nクリリンの妻は人造人間18号（Android 18）です。彼らの関係は、ドラゴンボールシリーズの中で重要な要素の一つとなっています。\n\n## 結婚と家族生活\n\nクリリンと18号の関係は、初めは敵対関係から始まりましたが、次第に友情と愛情に発展しました。彼らは結婚し、娘のマーロンをもうけています。この家族生活は、クリリンと18号のキャラクターに深みを与え、戦闘以外の側面も描かれています [Data: Relationships (1302, 25, 19, 20, 1294, +more)]。\n\n## 18号の戦闘能力\n\n18号は非常に強力な戦士であり、クリリンとの関係が彼女のキャラクターにさらなる深みを与えています。彼女は「力の大会」などの主要なイベントに参加し、その戦闘能力を発揮しています [Data: Entities (30), Relationships (1120, 1301, 1298, 1303, 1296, +more)]。\n\n## クリリンと18号の関係の発展\n\nクリリンと18号の関係は、初めはクリリンが18号に対して抱いていた恐れや不信感から始まりましたが、次第に信頼と愛情に変わっていきました。彼らの結婚は、ドラゴンボールシリーズの中でも感動的なエピソードの一つです [Data: Relationships (1302, 25, 19, 20, 1294, +more)]。\n\n## まとめ\n\nクリリンの妻は人造人間18号であり、彼らの関係はドラゴンボールシリーズの中で重要な役割を果たしています。彼らの結婚と家族生活は、シリーズにおける感動的な要素の一つであり、戦闘以外のキャラクターの側面を描く重要な要素となっています。",
    "context_data": {
        "reports": [
            {
                "id": "256",
                "title": "Krillin and Android 18 Community",
                "content": "# Krillin and Android 18 Community\n\nThe community revolves around Krillin and Android 18, two significant characters in the Dragon Ball series. Their relationships with other key characters such as Goku, Gohan, and Vegeta, as well as their involvement in major events like the Tournament of Power and battles against formidable foes like Frieza and Cell, highlight their importance. The community also includes various locations like Kame House and significant events that shape their interactions and development.\n\n## Krillin's pivotal role in the Dragon Ball series\n\nKrillin is a central character in the Dragon Ball series, known for his close relationships with Goku and other key characters. He has been involved in numerous significant events, including battles against Frieza, Cell, and participating in the Tournament of Power. His death at the hands of Frieza was a pivotal moment that triggered Goku's transformation into a Super Saiyan, showcasing his profound impact on the storyline [Data: Relationships (13, 0, 41, 112, 13, +more)].\n\n## Android 18's strength and combat abilities\n\nAndroid 18 is a formidable character known for her strength and combat prowess. She has participated in major events such as the Tournament of Power and has been involved in significant battles against characters like Cell and Beerus. Her relationship with Krillin, including their marriage and family life, adds depth to her character and highlights her importance in the series [Data: Entities (30), Relationships (683, 1120, 1301, 1298, 1302, +more)].\n\n## The dynamic relationship between Krillin and Goku\n\nKrillin and Goku share a deep and multifaceted relationship characterized by their close friendship, mutual respect, and significant influence on each other's lives. They trained together under Master Roshi and have supported each other in numerous battles. Krillin's death deeply affected Goku, leading to significant transformations and developments in the storyline [Data: Relationships (8, 0, 640, 92, 112, +more)].\n\n## Kame House as a central location\n\nKame House is a significant location in the Dragon Ball series, serving as the residence of Master Roshi and a hub for various characters. It has hosted important interactions and developments, including training sessions and strategic planning for battles. Krillin, Android 18, and their daughter Maron have lived there, highlighting its importance in their lives [Data: Entities (47), Relationships (26, 610, 1083, 521, 1578, +more)].\n\n## Krillin and Android 18's family life\n\nKrillin and Android 18's relationship evolves from initial mentorship and critique to a romantic commitment, culminating in their marriage and the birth of their daughter Maron. Their family life adds emotional depth to their characters and showcases their development beyond combat and battles. This aspect of their lives is depicted in various scenarios, including attending Bulma's birthday party and participating in family activities [Data: Entities (43), Relationships (25, 19, 20, 1294, 1295, +more)].\n\n## Krillin's strategic and supportive role in battles\n\nKrillin is known for his strategic thinking and supportive role in battles. He has assisted Goku and other characters in critical moments, such as helping to create the Spirit Bomb and using techniques like the Destructo Disc. His ability to provide crucial backup and his quick thinking have made him an invaluable ally in various confrontations [Data: Relationships (8, 92, 49, 63, 110, +more)].\n\n## Android 18's involvement in major battles\n\nAndroid 18 has been involved in several major battles throughout the series, showcasing her combat abilities and strategic thinking. She has fought against powerful opponents like Cell and Beerus and has participated in the Tournament of Power. Her involvement in these battles highlights her significance as a warrior and her contribution to the overall narrative [Data: Entities (30), Relationships (1120, 1301, 1298, 1303, 1296, +more)].\n\n## Krillin's mentorship and training under Master Roshi\n\nKrillin's training under Master Roshi has been a significant aspect of his development as a warrior. He learned the Kamehameha technique and other skills through rigorous training, which has contributed to his strength and combat abilities. Master Roshi's guidance and mentorship have played a crucial role in shaping Krillin's character and his approach to battles [Data: Relationships (7, 56, 45, 610, 594, +more)].\n\n## The impact of Krillin's death on the storyline\n\nKrillin's death at the hands of Frieza was a pivotal moment in the Dragon Ball series. This event had a profound impact on Goku, triggering his transformation into a Super Saiyan and marking a significant turning point in the storyline. Krillin's death and subsequent revival using the Dragon Balls highlight his importance and the emotional depth of his character [Data: Relationships (13, 112, 2, 12, 113, +more)].\n\n## Android 18's role in the Tournament of Power\n\nAndroid 18's participation in the Tournament of Power showcases her combat abilities and strategic thinking. She represented Universe 7 and collaborated with other warriors to achieve victory. Her involvement in this event highlights her significance as a fighter and her contribution to the overall narrative of the Dragon Ball series [Data: Relationships (1301, 1303, 1304, 1302, 683, +more)].",
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "256"
            }
        ],
        "entities": [
            {
                "id": "182",
                "entity": "\"亀仙士\"",
                "description": "\"亀仙士は新亀仙流の後進の戦士たちで、クリリンの精神を受け継いでいる。\"",
                "number of relationships": "1",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "182"
            },
            {
                "id": "116",
                "entity": "\"ブリーフ夫妻\"",
                "description": "\"ブリーフ夫婦\" are characters who are present during the karaoke session. They are also characters who enjoy クリリン's singing.",
                "number of relationships": "1",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "116"
            },
            {
                "id": "206",
                "entity": "\"田中真弓\"",
                "description": "田中真弓 is a multifaceted artist known for her work as both a singer and a voice actor. She performs the theme songs \"アサ・ヒル・ヨル・キミ・ボク\" and \"一度は結婚したいマンボ\". In addition to her singing career, 田中真弓 is also recognized for her voice acting, particularly for the character クリリン. She has expressed surprise and difficulty in imagining クリリン in a romantic relationship, highlighting her engagement with the character's storyline. 田中真弓 was chosen to play the role of クリリン by 鳥山, based on her performance in \"銀河鉄道の夜\". Her dual talents in singing and voice acting have made her a notable figure in the entertainment industry.",
                "number of relationships": "5",
                "in_context": true,
                "index_name": "e2123faa571a6174a1c926e4e841646a",
                "index_id": "206"
            },
            ...
        ]
    }
}
            
```
</details>

## さいごに
まずは動かしてみるところまでやってみました。

デプロイしたリソースの利用料は1日半ほど放置して大体3千円くらいでした。
ただ、AzureOpenAI Serviceの利用料で5千円ほどかかりました。

取り込むドキュメントの内容によるのでしょうか。正直、GraphDB自体よくわかっていないので、今後も色々触ってみていこうと思います！