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 のコンテキストでは、ヨガのポーズの説明を生成します。
  • Langchain Document Loader for Firestore を使用して、Hugging Face の強化されたデータセットから Firestore にレコードをベクトル エンベディングとともに読み込む方法
  • Langchain Vector Store for Firestore を使用して、自然言語クエリに基づいてデータを検索する方法
  • 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 ウィンドウのツールバーにある [エディタを開く] をクリックします。左上のメニューバーをクリックし、[File] → [Open Folder] を選択します。

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_id] と [location] の値を更新してください。理想的には、Google Cloud プロジェクトと Firestore データベースで [location] の値が同じになるようにします(例: 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. でバージョンがすでにロックされています。つまり、仮想環境にインストールする Python パッケージの依存関係を含む仮想 Python 環境を requirements.txt に作成する必要があります。これを行うには、Cloud Shell IDE の [Command Palette](Ctrl+Shift+P)に移動し、「[Python: Create Environment]」と入力します。次の手順に沿って、[Virtual Environment(venv)]、[Python 3.x interpreter]、[requirements.txt] ファイルを選択します。

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

source .venv/bin/activate

コンソールに「(.venv)」と表示されます。例: (.venv) yourusername@cloudshell:

これで準備が整いました。Firestore データベースの設定に進みましょう。

3. Firestore を設定する

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

Firestore データベースの初期化

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

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

  • Firestore モード: Native.
  • [Location Type] で [Region] を選択し、リージョンとして [us-central1] ロケーションを選択します。
  • [Security Rules] で [Test rules] を選択します。
  • データベースを作成します。

61d0277510803c8d.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 ドキュメント オブジェクトのリストに変換します。各ドキュメントには、page_contentmetadata の 2 つの属性があります。メタデータ オブジェクトには、namedescriptionsanskrit_name などの属性を持つ JSON オブジェクト全体が含まれます。page_content は、いくつかのフィールドを連結した文字列テキストになります。
  2. Document オブジェクトのリストが作成されたら、FirestoreVectorStore Langchain クラスを使用します。具体的には、このドキュメントのリスト、コレクション名(test-poses を指す TEST_COLLECTION 変数を使用)、Vertex AI エンベディング クラス、Firestore 接続の詳細(PROJECT_IDDATABASE 名)を使用して、from_documents メソッドを使用します。これにより、コレクションが作成され、各属性の 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 にアクセスして Firestore データベースとコレクションを検証します。次の図のように、default データベースと poses コレクションを選択します。

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. にあります。

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

レスポンスは、推奨事項のリストとともに 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 でのヨガのポーズの Recommender ウェブ アプリケーションの開発とデプロイが完了しました。

10. 完了

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

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