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
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
180
Other Decks in Technology
See All in Technology
依頼文化をやめる日 EM視点で語るPlatform EngineeringとInclusive SRE / Discussing Platform Engineering and Inclusive SRE from an EM's Perspective
shin1988
2
990
RAGの精度向上とエージェント活用
kintotechdev
2
130
Agentic AI 時代のテスト手法: Kiro とはじめるプロパティベーステスト (AWS Summit Japan 2026 | DEV212)
ymhiroki
0
200
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
140
AI駆動開発におけるQAエンジニアの役割事例 〜AI駆動開発の現場から〜
kobayashiyorimitsu
0
300
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
240
記録をかんたんに、提案をパーソナルに ── AIであすけんが目指すもの
oprstchn
0
140
AI Agentをシステムに組み込む前にゆるく向き合ってみる
hayama17
0
200
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
410
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
1
770
Compose 新機能総まとめ / What's New in Jetpack Compose
yanzm
0
100
ゼロをイチにする仕事が終わったあと
smasato
0
280
Featured
See All Featured
From π to Pie charts
rasagy
0
230
Bash Introduction
62gerente
615
220k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
880
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.7k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
A better future with KSS
kneath
240
18k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Typedesign – Prime Four
hannesfritz
42
3.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
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 に登録 ユーザーの入力によるベクトル検索を行い、複数の関連する商品を提示できた
ベクトル検索を使ってみましょう!