Codelab - Firestore、ベクトル検索、Langchain、Gemini を使用してコンテキストに応じたヨガのポーズ レコメンダー アプリを作成する(Python バージョン)

1. はじめに

この Codelab では、ベクトル検索を使用してヨガのポーズをおすすめするアプリを作成します。

この Codelab では、次の手順で進めていきます。

  1. ヨガのポーズの既存の Hugging Face データセット(JSON 形式)を利用します。
  2. Gemini を使用して各ポーズの説明を生成するフィールドの説明を追加して、データセットを拡張します。
  3. Langchain を使用してドキュメントを作成し、Firestore Langchain 統合を使用して Firestore にコレクションとエンベディングを作成します。
  4. Firestore で複合インデックスを作成して、ベクトル検索を可能にします。
  5. 以下に示すように、Flask アプリケーションでベクトル検索を使用して、すべてを統合します。

84e1cbf29cbaeedc.png

演習内容

  • ベクトル検索を使用してヨガのポーズをおすすめするウェブ アプリケーションを設計、構築、デプロイします。

学習内容

  • Gemini を使用してテキスト コンテンツを生成する方法と、この Codelab のコンテキスト内でヨガのポーズの説明を生成する方法
  • Firestore 用 Langchain ドキュメント ローダーを使用して、Hugging Face の拡張データセットのレコードをベクトル エンベディングとともに Firestore に読み込む方法
  • Firestore 用の Langchain ベクターストアを使用して、自然言語クエリに基づいてデータを検索する方法
  • Google Cloud Text to Speech API を使用して音声コンテンツを生成する方法

必要なもの

  • Chrome ウェブブラウザ
  • Gmail アカウント
  • 課金が有効になっている Cloud プロジェクト

この Codelab は、初心者を含むあらゆるレベルのデベロッパーを対象としており、サンプル アプリケーションで Python を使用します。ただし、ここで説明するコンセプトを理解するために Python の知識は必要ありません。

2. 始める前に

プロジェクトを作成する

  1. Google Cloud コンソールのプロジェクト選択ページで、Google Cloud プロジェクトを選択または作成します。
  2. Cloud プロジェクトに対して課金が有効になっていることを確認します。詳しくは、プロジェクトで課金が有効になっているかどうかを確認する方法をご覧ください。
  3. Cloud Shell(Google Cloud で動作するコマンドライン環境)を使用します。この環境には bq がプリロードされています。Google Cloud コンソールの上部にある [Cloud Shell をアクティブにする] をクリックします。

Cloud Shell を有効にするボタンの画像

  1. Cloud Shell に接続したら、次のコマンドを使用して、認証が完了していることと、プロジェクトがプロジェクト ID に設定されていることを確認します。
gcloud auth list
  1. Cloud Shell で次のコマンドを実行して、gcloud コマンドがプロジェクトを認識していることを確認します。
gcloud config list project
  1. プロジェクトが設定されていない場合は、次のコマンドを使用して設定します。
gcloud config set project <YOUR_PROJECT_ID>
  1. 次のコマンドを使用して、必要な API を有効にします。この処理には数分かかることがありますので、少々お待ちください。
gcloud services enable firestore.googleapis.com \
                       compute.googleapis.com \
                       cloudresourcemanager.googleapis.com \
                       servicenetworking.googleapis.com \
                       run.googleapis.com \
                       cloudbuild.googleapis.com \
                       cloudfunctions.googleapis.com \
                       aiplatform.googleapis.com \
                       texttospeech.googleapis.com

コマンドが正常に実行されると、次のようなメッセージが表示されます。

Operation "operations/..." finished successfully.

gcloud コマンドの代わりに、コンソールで各プロダクトを検索するか、このリンクを使用します。

いずれかの API が不足している場合は、実装中にいつでも有効にできます。

gcloud コマンドとその使用方法については、ドキュメントをご覧ください。

リポジトリのクローンを作成して環境設定を設定する

次のステップでは、Codelab の残りの部分で参照するサンプル リポジトリのクローンを作成します。Cloud Shell を使用している場合は、ホーム ディレクトリから次のコマンドを実行します。

git clone https://github.com/rominirani/yoga-poses-recommender-python

エディタを起動するには、Cloud Shell ウィンドウのツールバーで [エディタを開く] をクリックします。左上のメニューバーをクリックし、[ファイル] → [フォルダを開く] の順に選択します。

66221fd0d0e5202f.png

yoga-poses-recommender-python フォルダを選択すると、次のようにフォルダが開き、次のファイルが表示されます。

44699efc7fb1b911.png

次に、使用する環境変数を設定する必要があります。config.template.yaml ファイルをクリックすると、次のような内容が表示されます。

project_id: your-project-id
location: us-central1
gemini_model_name: gemini-1.5-flash-002
embedding_model_name: text-embedding-004
image_generation_model_name: imagen-3.0-fast-generate-002
database: (default)
collection: poses
test_collection: test-poses
top_k: "3"

Google Cloud プロジェクトと Firestore データベースのリージョンの作成時に選択した内容に従って、project_idlocation の値を更新してください。理想的には、location の値は Google Cloud プロジェクトと Firestore データベースで同じにする必要があります(us-central1 など)。

この Codelab では、事前構成済みの値を使用します(ただし、project_idlocation は、構成に応じて設定する必要があります)。

このファイルを config.template.yaml ファイルと同じフォルダに config.yaml として保存してください。

最後のステップは、ローカルで使用する Python 環境を作成し、すべての Python 依存関係を設定することです。詳細が記載されている pyproject.toml ファイルを確認します。その内容は次のとおりです。

dependencies = [
    "datasets>=3.2.0",
    "flask>=3.1.0",
    "google-cloud-aiplatform>=1.78.0",
    "google-cloud-texttospeech>=2.24.0",
    "langchain-community>=0.3.15",
    "langchain-core>=0.3.31",
    "langchain-google-community>=2.0.4",
    "langchain-google-firestore>=0.5.0",
    "langchain-google-vertexai>=2.0.7",
    "pydantic-settings>=2.7.1",
    "pyyaml>=6.0.2",
    "tenacity>=9.0.0",
]

これらの依存関係は、requirements.txt ですでにバージョンロックされています。.要約すると、requirements.txt の Python パッケージ依存関係を含む仮想 Python 環境を作成し、その仮想環境にインストールする必要があります。これを行うには、Cloud Shell IDE で Command Palette(Ctrl+Shift+P)に移動し、Python: Create Environment と入力します。次の手順に沿って、Virtual Environment(venv)Python 3.x interpreterrequirements.txt ファイルを選択します。

環境が作成されたら、次のコマンドを使用して作成した環境を有効にする必要があります。

source .venv/bin/activate

コンソールに(.venv)が表示されます。例: -> (.venv) yourusername@cloudshell:

これで準備が整いました。これで、Firestore データベースの設定に進むことができます。

3. Firestore を設定する

Cloud Firestore は、アプリケーション データのバックエンドとして使用するフルマネージドのサーバーレス ドキュメント データベースです。Cloud Firestore のデータは、ドキュメントコレクションで構成されます。

Firestore データベースの初期化

Cloud コンソールの [Firestore] ページに移動します。

プロジェクトで Firestore データベースを初期化したことがない場合は、[Create Database] をクリックして default データベースを作成します。データベースの作成時に、次の値を使用します。

  • Firestore モード: Native.
  • 位置情報: デフォルトの位置情報設定を使用します。
  • セキュリティ ルールには Test rules を選択します。
  • データベースを作成します。

504cabdb99a222a5.png

次のセクションでは、デフォルトの Firestore データベースに poses という名前のコレクションを作成する準備を行います。このコレクションには、サンプルデータ(ドキュメント)またはヨガポーズに関する情報を格納します。これらのデータは、アプリケーションで使用します。

これで、Firestore データベースの設定セクションは完了です。

4. ヨガのポーズ データセットを準備する

まず、アプリケーションで使用するヨガポーズ データセットを準備します。まず、既存の Hugging Face データセットから始め、追加情報を追加して拡張します。

ヨガのポーズ用の Hugging Face データセットをご覧ください。この Codelab ではデータセットの 1 つを使用しますが、実際には他の任意のデータセットを使用して、ここで説明した手法に沿ってデータセットを拡張できます。

298cfae7f23e4bef.png

[Files and versions] セクションに移動すると、すべてのポーズの JSON データファイルを取得できます。

3fe6e55abdc032ec.png

yoga_poses.json をダウンロードし、そのファイルをお送りしました。このファイルの名前は yoga_poses_alldata.json で、/data フォルダにあります。

Cloud Shell エディタで data/yoga_poses.json ファイルに移動し、JSON オブジェクトのリストを調べます。各 JSON オブジェクトはヨガのポーズを表します。レコードは合計 3 つあり、サンプル レコードを以下に示します。

{
   "name": "Big Toe Pose",
   "sanskrit_name": "Padangusthasana",
   "photo_url": "https://pocketyoga.com/assets/images/full/ForwardBendBigToe.png",
   "expertise_level": "Beginner",
   "pose_type": ["Standing", "Forward Bend"]
 }

ここで、Gemini と、デフォルト モデル自体を使用して description フィールドを生成する方法について説明します。

Cloud Shell エディタで、generate-descriptions.py ファイルに移動します。このファイルの内容は次のとおりです。

import json
import time
import logging
import vertexai
from langchain_google_vertexai import VertexAI
from tenacity import retry, stop_after_attempt, wait_exponential
from settings import get_settings

settings = get_settings()
logging.basicConfig(
    level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
# Initialize Vertex AI SDK
vertexai.init(project=settings.project_id, location=settings.location)
logging.info("Done Initializing Vertex AI SDK")


@retry(
    stop=stop_after_attempt(5),
    wait=wait_exponential(multiplier=1, min=4, max=10),
)
def generate_description(pose_name, sanskrit_name, expertise_level, pose_types):
    """Generates a description for a yoga pose using the Gemini API."""

    prompt = f"""
    Generate a concise description (max 50 words) for the yoga pose: {pose_name}
    Also known as: {sanskrit_name}
    Expertise Level: {expertise_level}
    Pose Type: {", ".join(pose_types)}

    Include key benefits and any important alignment cues.
    """
    try:
        model = VertexAI(model_name=settings.gemini_model_name, verbose=True)
        response = model.invoke(prompt)
        return response
    except Exception as e:
        logging.info(f"Error generating description for {pose_name}: {e}")
        return ""


def add_descriptions_to_json(input_file, output_file):
    """Loads JSON data, adds descriptions, and saves the updated data."""

    with open(input_file, "r") as f:
        yoga_poses = json.load(f)

    total_poses = len(yoga_poses)
    processed_count = 0

    for pose in yoga_poses:
        if pose["name"] != " Pose":
            start_time = time.time()  # Record start time
            pose["description"] = generate_description(
                pose["name"],
                pose["sanskrit_name"],
                pose["expertise_level"],
                pose["pose_type"],
            )
            end_time = time.time()  # Record end time

            processed_count += 1
            end_time = time.time()  # Record end time
            time_taken = end_time - start_time
            logging.info(
                f"Processed: {processed_count}/{total_poses} - {pose['name']} ({time_taken:.2f} seconds)"
            )

        else:
            pose["description"] = ""
            processed_count += 1
            logging.info(
                f"Processed: {processed_count}/{total_poses} - {pose['name']} ({time_taken:.2f} seconds)"
            )
        # Adding a delay to avoid rate limit
        time.sleep(30)

    with open(output_file, "w") as f:
        json.dump(yoga_poses, f, indent=2)


def main():
    # File paths
    input_file = "./data/yoga_poses.json"
    output_file = "./data/yoga_poses_with_descriptions.json"

    # Add descriptions and save the updated JSON
    add_descriptions_to_json(input_file, output_file)


if __name__ == "__main__":
    main()

このアプリケーションは、各ヨガのポーズ JSON レコードに新しい description フィールドを追加します。Gemini モデルを呼び出して説明を取得します。このモデルには、必要なプロンプトが提供されます。フィールドが JSON ファイルに追加され、新しいファイルが data/yoga_poses_with_descriptions.json ファイルに書き込まれます。

主な手順は次のとおりです。

  1. main() 関数では、add_descriptions_to_json 関数が呼び出され、想定される入力ファイルと出力ファイルが指定されています。
  2. add_descriptions_to_json 関数は、JSON レコード(ヨガ投稿情報)ごとに次のことを行います。
  3. pose_namesanskrit_nameexpertise_levelpose_types が抽出されます。
  4. generate_description 関数を呼び出してプロンプトを構築し、Langchain VertexAI モデルクラスを呼び出してレスポンス テキストを取得します。
  5. このレスポンス テキストが JSON オブジェクトに追加されます。
  6. 更新されたオブジェクトの JSON リストが宛先ファイルに書き込まれます。

このアプリケーションを実行してみましょう。新しいターミナル ウィンドウ(Ctrl+Shift+C)を起動し、次のコマンドを入力します。

python generate-descriptions.py

承認を求められた場合は、承認してください。

アプリケーションの実行が開始されます。新しい Google Cloud アカウントで発生する可能性があるレート制限の割り当てを回避するため、レコード間に 30 秒の遅延を追加しました。ご不便をおかけしますが、ご容赦ください。

実行中の実行例を以下に示します。

8e830d9ea9b6c60.png

3 つのレコードがすべて Gemini 呼び出しで拡張されると、ファイル data/yoga_poses_with_description.json が生成されます。ご確認いただけます。

これでデータファイルの準備が整いました。次のステップでは、エンベディングの生成とともに、Firestore データベースにデータを入力する方法について説明します。

5. データを Firestore にインポートしてベクトル エンベディングを生成する

data/yoga_poses_with_description.json ファイルを作成したので、Firestore データベースにこのファイルを入力し、各レコードのベクトル エンベディングを生成する必要があります。ベクトル エンベディングは、後で自然言語で指定されたユーザーのクエリと類似性検索を行う際に役立ちます。

ここでは、Langchain Firestore コンポーネントを使用して上記のプロセスを実装します。

手順は次のとおりです。

  1. JSON オブジェクトのリストを Langchain Document オブジェクトのリストに変換します。各ドキュメントには、page_contentmetadata の 2 つの属性があります。メタデータ オブジェクトには、namedescriptionsanskrit_name などの属性を持つ JSON オブジェクト全体が含まれます。page_content は、いくつかのフィールドを連結した文字列テキストです。
  2. Document オブジェクトのリストが作成されたら、FirestoreVectorStore Langchain クラス、特に from_documents メソッドを使用して、このドキュメントのリスト、コレクション名(test-poses を指す TEST_COLLECTION 変数を使用)、Vertex AI エンベディング クラス、Firestore 接続の詳細(PROJECT_IDDATABASE 名)を指定します。これにより、コレクションが作成され、各属性の embedding フィールドも生成されます。

import-data.py のコードは次のとおりです(簡潔にするため、コードの一部を省略しています)。

... 

def create_langchain_documents(poses):
   """Creates a list of Langchain Documents from a list of poses."""
   documents = []
   for pose in poses:
       # Convert the pose to a string representation for page_content
       page_content = (
           f"name: {pose.get('name', '')}\n"
           f"description: {pose.get('description', '')}\n"
           f"sanskrit_name: {pose.get('sanskrit_name', '')}\n"
           f"expertise_level: {pose.get('expertise_level', 'N/A')}\n"
           f"pose_type: {pose.get('pose_type', 'N/A')}\n"
       ).strip()
       # The metadata will be the whole pose
       metadata = pose

       document = Document(page_content=page_content, metadata=metadata)
       documents.append(document)
   logging.info(f"Created {len(documents)} Langchain documents.")
   return documents

def main():
    all_poses = load_yoga_poses_data_from_local_file(
        "./data/yoga_poses_with_descriptions.json"
    )
    documents = create_langchain_documents(all_poses)
    logging.info(
        f"Successfully created langchain documents. Total documents: {len(documents)}"
    )

    embedding = VertexAIEmbeddings(
        model_name=settings.embedding_model_name,
        project=settings.project_id,
        location=settings.location,
    )

    client = firestore.Client(project=settings.project_id, database=settings.database)

    vector_store = FirestoreVectorStore.from_documents(
        client=client,
        collection=settings.test_collection,
        documents=documents,
        embedding=embedding,
    )
    logging.info("Added documents to the vector store.")


if __name__ == "__main__":
    main()

このアプリケーションを実行してみましょう。新しいターミナル ウィンドウ(Ctrl+Shift+C)を起動し、次のコマンドを入力します。

python import-data.py

問題がなければ、次のようなメッセージが表示されます。

2025-01-21 14:50:06,479 - INFO - Added documents to the vector store.

レコードが正常に挿入され、エンベディングが生成されたかどうかを確認するには、Cloud コンソールの Firestore ページに移動します。

504cabdb99a222a5.png

(デフォルトの)データベースをクリックすると、test-poses コレクションとそのコレクション内の複数のドキュメントが表示されます。各ドキュメントは 1 つのヨガのポーズです。

d0708499e403aebc.png

ドキュメントをクリックして、フィールドを調べます。インポートしたフィールドに加えて、embedding フィールドも存在します。これは、使用した Langchain の VertexAIEmbeddings クラスによって自動生成されたベクトル フィールドで、text-embedding-004 Vertex AI エンベディング モデルが指定されています。

d67113e2dc63cd6b.png

エンベディングが設定されたレコードが Firestore データベースにアップロードされたので、次のステップに進み、Firestore でベクトル類似度検索を行う方法を確認します。

6. ヨガのポーズ全体を Firestore データベース コレクションにインポートする

次に、160 種類のヨガポーズの完全なリストである poses コレクションを作成します。このコレクション用に、直接インポートできるデータベース インポート ファイルを生成しました。これは、ラボでの時間を節約するためです。説明とエンベディングを含むデータベースを生成するプロセスは、前のセクションで説明したものと同じです。

次の手順に沿ってデータベースをインポートします。

  1. 次の gsutil コマンドを使用して、プロジェクトにバケットを作成します。次のコマンドの <PROJECT_ID> 変数を、Google Cloud プロジェクト ID に置き換えます。
gsutil mb -l us-central1 gs://<PROJECT_ID>-my-bucket
  1. バケットが作成されたので、Firebase データベースにインポートする前に、準備したデータベース エクスポートをこのバケットにコピーする必要があります。次のコマンドを使用します。
gsutil cp -r gs://yoga-database-firestore-export-bucket/2025-01-27T05:11:02_62615  gs://<PROJECT_ID>-my-bucket

インポートするデータが用意できたので、作成した Firebase データベース(default)にデータをインポートする最後のステップに進みます。

  1. 次の gcloud コマンドを使用します。
gcloud firestore import gs://<PROJECT_ID>-my-bucket/2025-01-27T05:11:02_62615

インポートには数秒かかります。準備ができたら、https://console.cloud.google.com/firestore/databases にアクセスして、default データベースと poses コレクションを選択して、Firestore データベースとコレクションを検証します。

a8f5a6ba69bec69b.png

これで、アプリケーションで使用する Firestore コレクションの作成が完了しました。

7. Firestore でベクトル類似性検索を行う

ベクトル類似検索を実行するには、ユーザーからクエリを受け取ります。このクエリの例は "Suggest me some exercises to relieve back pain" です。

search-data.py ファイルを確認します。注目すべき関数は検索関数です。これは次のとおりです。大まかに言うと、ユーザークエリのエンベディングの生成に使用されるエンベディング クラスが作成されます。次に、FirestoreVectorStore クラスを使用して similarity_search 関数を呼び出します。

def search(query: str):
    """Executes Firestore Vector Similarity Search"""
    embedding = VertexAIEmbeddings(
        model_name=settings.embedding_model_name,
        project=settings.project_id,
        location=settings.location,
    )

    client = firestore.Client(project=settings.project_id, database=settings.database)

    vector_store = FirestoreVectorStore(
        client=client, collection=settings.collection, embedding_service=embedding
    )

    logging.info(f"Now executing query: {query}")
    results: list[Document] = vector_store.similarity_search(
        query=query, k=int(settings.top_k), include_metadata=True
    )
    for result in results:
        print(result.page_content)

いくつかのクエリ例でこのコードを実行する前に、まず Firestore 複合インデックスを生成する必要があります。これは、検索クエリを成功させるために必要です。インデックスを作成せずにアプリケーションを実行すると、まずインデックスを作成する必要があることを示唆するエラーと、まずインデックスを作成するコマンドが返されます。

複合インデックスを作成する gcloud コマンドは次のとおりです。

gcloud firestore indexes composite create --project=<YOUR_PROJECT_ID> --collection-group=poses --query-scope=COLLECTION --field-config=vector-config='{"dimension":"768","flat": "{}"}',field-path=embedding

データベースに 150 を超えるレコードがあるため、インデックスの作成には数分かかります。完了したら、次のコマンドを使用してインデックスを表示できます。

gcloud firestore indexes composite list

作成したインデックスがリストに表示されます。

次のコマンドを試してみましょう。

python search-data.py --prompt "Recommend me some exercises for back pain relief"

いくつかの推奨事項が表示されます。サンプル実行は次のとおりです。

2025-01-21 15:48:51,282 - INFO - Now executing query: Recommend me some exercises for back pain relief
name: Supine Spinal Twist Pose
description: A gentle supine twist (Supta Matsyendrasana), great for beginners.  Releases spinal tension, improves digestion, and calms the nervous system.  Keep shoulders flat on the floor and lengthen the spine.

sanskrit_name: Supta Matsyendrasana
expertise_level: Beginner
pose_type: ['Supine', 'Twist']
name: Cow Pose
description: Cow Pose (Bitilasana) is a gentle backbend, stretching the chest, shoulders, and abdomen.  Maintain a neutral spine, lengthen the tailbone, and avoid hyperextension.  Benefits include improved posture and stress relief.

sanskrit_name: Bitilasana
expertise_level: Beginner
pose_type: ['Arm Leg Support', 'Back Bend']
name: Locust I Pose
description: Locust Pose I (Shalabhasana A) strengthens the back, glutes, and shoulders.  Lie prone, lift chest and legs simultaneously, engaging back muscles.  Keep hips grounded and gaze slightly forward.

sanskrit_name: Shalabhasana A
expertise_level: Intermediate
pose_type: ['Prone', 'Back Bend']

これで、Firestore ベクトル データベースを使用してレコードをアップロードし、エンベディングを生成してベクトル類似性検索を行う方法を理解できました。これで、ベクトル検索をウェブ フロントエンドに統合するウェブ アプリケーションを作成できます。

8. ウェブ アプリケーション

Python Flask ウェブ アプリケーションは main.py ファイルで使用でき、フロントエンド HTML ファイルは templates/index.html. にあります。

両方のファイルを確認することをおすすめします。まず、main.py ファイルから始めます。このファイルには、フロントエンドの HTML index.html ファイルから渡されたプロンプトを受け取る /search ハンドラが含まれています。これにより、検索メソッドが呼び出され、前のセクションで説明したベクトル類似検索が実行されます。

その後、レスポンスが推奨事項のリストとともに index.html に返されます。index.html に、推奨事項が異なるカードとして表示されます。

アプリケーションをローカルで実行する

新しいターミナル ウィンドウ(Ctrl+Shift+C)または既存のターミナル ウィンドウを起動し、次のコマンドを実行します。

python main.py

実行例を以下に示します。

 * Serving Flask app 'main'
 * Debug mode: on
2025-01-21 16:02:37,473 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8080
 * Running on http://10.88.0.4:8080
2025-01-21 16:02:37,473 - INFO - Press CTRL+C to quit
2025-01-21 16:02:37,474 - INFO -  * Restarting with stat
2025-01-21 16:02:41,462 - WARNING -  * Debugger is active!
2025-01-21 16:02:41,484 - INFO -  * Debugger PIN: 440-653-555

アプリが稼働したら、下のウェブでプレビュー ボタンをクリックして、アプリのホームページ URL にアクセスします。

de297d4cee10e0bf.png

次のように、提供された index.html ファイルが表示されます。

20240a0e885ac17b.png

サンプルクエリ(例 : Provide me some exercises for back pain relief)を指定し、[Search] ボタンをクリックします。これにより、データベースからいくつかのおすすめが取得されます。[Play Audio] ボタンも表示されます。このボタンをクリックすると、説明に基づいて音声ストリームが生成され、直接聞くことができます。

789b4277dc40e2be.png

9. (省略可)Google Cloud Run へのデプロイ

最後のステップでは、このアプリケーションを Google Cloud Run にデプロイします。デプロイ コマンドは次のとおりです。デプロイする前に、変数(<<YOUR_PROJECT_ID>>)の値をプロジェクト固有の値に置き換えてください。これらの値は、config.yaml ファイルから取得できます。

gcloud run deploy yogaposes --source . \
  --port=8080 \
  --allow-unauthenticated \
  --region=us-central1 \
  --platform=managed  \
  --project=<<YOUR_PROJECT_ID>> \
  --env-vars-file=config.yaml

アプリケーションのルートフォルダから上記のコマンドを実行します。Google Cloud APIs を有効にするよう求められたり、さまざまな権限について承認を求められたりします。その場合は、承認してください。

デプロイ プロセスが完了するまでに 5 ~ 7 分ほどかかりますので、しばらくお待ちください。

3a6d86fd32e4a5e.png

デプロイが正常に完了すると、デプロイの出力に Cloud Run サービス URL が表示されます。形式は次のようになります。

Service URL: https://yogaposes-<<UNIQUEID>.us-central1.run.app

その公開 URL にアクセスすると、同じウェブ アプリケーションがデプロイされ、正常に実行されていることがわかります。

84e1cbf29cbaeedc.png

Google Cloud コンソールから Cloud Run にアクセスすると、Cloud Run のサービスが一覧表示されます。yogaposes サービスが、そこに表示されるサービスの 1 つ(唯一のサービスではない)である必要があります。

f2b34a8c9011be4c.png

特定のサービス名(この場合は yogaposes)をクリックすると、URL、構成、ログなどのサービスの詳細を表示できます。

faaa5e0c02fe0423.png

これで、Cloud Run でのヨガのポーズ レコメンデーター ウェブ アプリケーションの開発とデプロイが完了しました。

10.完了

これで、データセットを Firestore にアップロードし、エンベディングを生成し、ユーザーのクエリに基づいてベクトル類似度検索を行うアプリケーションを作成できました。

リファレンス ドキュメント