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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kazutaka Nakamura
April 26, 2024
Technology
220
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
170
Other Decks in Technology
See All in Technology
AI駆動開発を通して感じた、 AI時代のデザイナーの役割変化
whisaiyo
2
1.9k
How Timee Delivers Day 1 Production Ready LLM Features
tomoyks
0
180
2026TECHFRESH畢業分享會 - 葬送的通靈師:化系統與用戶雜訊成行動訊號
line_developers_tw
PRO
0
910
AmazonRoute 53ではじめてのドメイン取得!HTTPS化までの道のりを整理してみた
usanchuu
3
130
LLMにもCAP定理があるという話
harukasakihara
0
310
AIエージェントが名古屋の猛暑からあなたを守る
happysamurai294
0
100
Disciplined Vibes: Scaling AI-Assisted Engineering
sheharyar
0
140
新しいVibe Codingと”自走”について
watany
6
310
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development with AI-DLC
yoshidashingo
0
180
Claude Codeをどのように キャッチアップしているか
oikon48
12
7.3k
Android の公式 Skill / Android skills
yanzm
0
140
NAB Show 2026 動画技術関連レポート / NAB Show 2026 Report
cyberagentdevelopers
PRO
0
180
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
55
8.2k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
What's in a price? How to price your products and services
michaelherold
247
13k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
How STYLIGHT went responsive
nonsquared
100
6.2k
Color Theory Basics | Prateek | Gurzu
gurzu
0
360
Code Reviewing Like a Champion
maltzj
528
40k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
200
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
A Tale of Four Properties
chriscoyier
163
24k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
380
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
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 に登録 ユーザーの入力によるベクトル検索を行い、複数の関連する商品を提示できた
ベクトル検索を使ってみましょう!