Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
20240425_nakamura.pdf
Search
Kazutaka Nakamura
April 26, 2024
Technology
230
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
20240425_nakamura.pdf
Kazutaka Nakamura
April 26, 2024
More Decks by Kazutaka Nakamura
See All by Kazutaka Nakamura
htmx for backend engineer
nakamurakzz
0
190
Other Decks in Technology
See All in Technology
ブラウザアプリの継続的パフォーマンスモニタリング (序) / Continuous Browser Application Performance Monitoring; Act 1
moznion
0
110
Amazon S3 Tablesに全部任せてみた結果——コンパクション/スナップショット管理は本当に手放せるか
shigeruoda
0
410
AI活用の現在地、 ちゃんと見えてますか?/XPfest-2026
visional_engineering_and_design
0
160
Jetpack Compose で挑む新聞紙面UI ─ 複合ジェスチャー・ポリゴン記事領域・適応的ページ構成という3つの壁/droidkaigi2026
nikkei_engineer_recruiting
0
240
エンタープライズInnerSourceと開発者ポータル
nogikazuma
1
110
【Oracle AI Spotlight ウェビナー】AWSか、Azureか、Google Cloudか。その議論にオラクルを含める意義。
oracle4engineer
PRO
2
240
Bet AI Day 2026丨AIを「使う」から、AIが「働く」へ ― LayerXが進める「組織AI」の社会実装
layerx
PRO
3
2.8k
Azure App Service / Container Apps の組み込み認証
kuniteru
0
210
AI 駆動 Terraform 開発/SRE_BizReach_MIXI_2
visional_engineering_and_design
2
1.9k
なぜSRE・セキュリティは評価されないのか?守りの組織を事業成長エンジンに変えた実践
cscengineer
PRO
3
2.3k
設計の世代交代を乗り越える、14年続くAndroidアプリの開発戦略
sansantech
PRO
1
150
Bet AI Day 2026丨AIによって本質に戻るシステムリスク管理
layerx
PRO
0
1.3k
Featured
See All Featured
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
230
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
270
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
320
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
230
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
We Have a Design System, Now What?
morganepeng
55
8.3k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Exploring anti-patterns in Rails
aemeredith
3
490
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Transcript
Firestore の ベクトル検索で衣料品レコメンド機能を作ってみる 2024/04/25 Lazuli 株式会社 中村 和貴
自己紹介 所属: Lazuli 株式会社 ロール: Software Engineer 言語: Go, TypeScript
普段触っているサービス: Cloud Run, Pub/Sub 興味: システムアーキテクチャ・ソフトウェアアーキテクチャ ラスベガス歴: re:Invent 2022 に参加して以来 2 回目
本日のテーマ Firestore の Vector Search で 衣料品レコメンド機能を作ってみる
Opening Keynote でのデモ
Opening Keynote でのデモ
Opening Keynote でのデモ 誰でも簡単にベクトル検索を実装できるようになった
Vector Search
Vector Search https://cloud.google.com/blog/products/ai-machine-learning/grounding-gen-ai-in-enterprise-truth?hl=en
What's Vector Search ? データをベクトル(数値の配列)で表現し、類似度に基づいて検索する技術 従来のキーワード検索とは異なり、意味的な類似性を捉えることができる https://www.youtube.com/watch?v=7XI45ll8fqQ https://www.youtube.com/watch?v=MyIsz2BLTYc
Firestore の Vector Search を使用して作ったもの
まとめ 公開されているデータセットを使用して、商品の説明文を Gemini Pro 1.0 で生成 説明文のベクトルを生成し、プロダクトデータといっしょに Firestore に登録 ユーザーの入力によるベクトル検索を行い、複数の関連する商品を提示できた
ベクトル検索を使ってみましょう!
以下、ベクトル検索を実装してみた、の話
使用したデータセット BigQuery の公開プロダクトデータセットを使用 デモでは 500 件のデータを使用
プロダクトの説明文の生成 model: gemini-1.0-pro で商品の説明文を生成 Gemini models: https://ai.google.dev/gemini-api/docs/models/gemini?hl=ja アクセスレート(無料使用分) Gemini Pro
1.0 Gemini Pro 1.5 (Preview) - 15 req / 分 - 32,000 トークン / 分 - 1,500 req / 分 - 2 req / 分 - 32,000 トークン / 分 - 50 req / 分 https://ai.google.dev/pricing?hl=ja
プロダクトの説明文の生成 プロダクトデータを元に説明文を生成 func generateProductInfo(ctx context.Context, products string) (string, error) {
prompt := fmt.Sprintf(` あなたはオンラインショップのダミーデータを生成するAI アシスタントです。商品データは以下の通りです。 '''csv id,cost,category,name,brand,retail_price,department,sku,distribution_center_id %s ''' 商品の説明文を各商品の特長や素材、シーズン、対象、サイズ等をふまえ、100~150 文字程度で1 行の英語で記述してください。`, products) resp, _ := model.GenerateContent(ctx, genai.Text(prompt)) content := resp.Candidates[0].Content.Parts[0].(genai.Text) return string(content), nil } Go SDK for Google Generative AI: https://github.com/google/generative-ai-go
生成された説明文例 プロダクト名: Calvin Klein Men's 3 Pack No Show Liner
Socks 生成された説明文: " カルバン・クラインの男性用ノーショーライナーソックス3 足組で、快適な履き心地 をキープしよう。コットンとスパンデックス製でソフトで通気性に優れたフィット 感。普段履きに最適なこのソックスは、便利な3 足組で滑り止めグリップ付き"
(memo) 生成エラー! Input: 10576,3218,Intimates,Calvin Klein Women's Sexy Signature Demi Bra,Calvin
Klein,41.900001525878906,Women,433F3EB6C5B7BD3FB4A2D0E8756C6836, 3 Error: blocked: candidate: FinishReasonSafety
説明文のベクトル化 Embedding (ベクトル化)モデル: embedding-001 を使用 func generateEmbbedingValue(ctx context.Context, text string)
([]float32, error) { vertexAIClient, _ := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("API_KEY"))) embedder := vertexAIClient.EmbeddingModel("embedding-001") resp, _ := embedder.EmbedContent(ctx, genai.Text(text)) return resp.Embedding.Values, nil } Go SDK for Google Generative AI: https://github.com/google/generative-ai-go embedding-001: https://ai.google.dev/gemini- api/tutorials/document_search#api_changes_to_embeddings_with_model_embedding-001
プロダクトデータと説明文のベクトルを Firestore に登録 import { Firestore, FieldValue } from "@google-cloud/firestore";
import fs from "fs"; const db = new Firestore({ projectId: process.env.PJ_ID, databaseId: process.env.DB_ID,}); const addDocuments = async () => { const records = parseToJson(fs.readFileSync("products.csv")); for (const record of records) { const vector = parseVector(rowVector); // 文字の行列データを整形 const doc = { ...record, embedding_field: FieldValue.vector(vector) }; await db.collection(process.env.COLLECTION_NAME).add(doc); } }; Google AI JavaScript SDK: https://github.com/google-gemini/generative-ai-js
ベクトルを含むプロダクトデータと Firestore に登録
Firestore のベクトル検索 ベクトルの類似度の計算方法を選択可能 EUCLIDEAN 距離 コサイン類似度 ドット積 制限事項 ベクトル検索では、リアルタイムデータの取得は出来ない 不等式フィルタを使用してデータを事前にフィルタリングが出来ない
Firestore のベクトル検索がサポートされているのは、Node.js と Python のみ https://cloud.google.com/firestore/docs/vector-search?hl=ja
Firestore のベクトル検索 import { Firestore, FieldValue, VectorQuery, VectorQuerySnapshot } from
"@google-cloud/firestore"; import { GoogleGenerativeAI } from "@google/generative-ai"; const genAI = new GoogleGenerativeAI(process.env.API_KEY ?? ""); const model = genAI.getGenerativeModel({model: "embedding-001"}); const searchDoc = async (message: string) => { const result = await model.embedContent(message); const vectorQuery: VectorQuery = db.collection("products").findNearest( "embedding_field", FieldValue.vector(result.embedding.values), { limit: 5, distanceMeasure: "COSINE" } ); const vectorQuerySnapshot: VectorQuerySnapshot = await vectorQuery.get(); const res: any[] = []; vectorQuerySnapshot.forEach((doc) => res.push(doc.data())); return res; };
Demo "I'm going to the beach this summer, so I'd
like to get a new swimsuit."
まとめ 公開されているデータセットを使用して、商品の説明文を Gemini Pro 1.0 で生成 説明文のベクトルを生成し、プロダクトデータといっしょに Firestore に登録 ユーザーの入力によるベクトル検索を行い、複数の関連する商品を提示できた
ベクトル検索を使ってみましょう!