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
生成AIで本番アプリをリリースするためのAWS, LangChain, ベクターデータ...
Search
吉田真吾
October 18, 2023
Programming
1
1.4k
生成AIで本番アプリをリリースするためのAWS, LangChain, ベクターデータベース実践入門 / LangChain-Bedrock
AWS AI Week For Developers
https://pages.awscloud.com/AIW4Dev.html
10/18(水) Day2トラックで話した資料です。
吉田真吾
October 18, 2023
Tweet
Share
More Decks by 吉田真吾
See All by 吉田真吾
Serverless Meetup #21
yoshidashingo
1
140
リモートMCPサーバーが便利な話
yoshidashingo
1
82
20250728 MCP, A2A and Multi-Agents in the future
yoshidashingo
1
270
20250619 AIコーディング道場 成果発表会
yoshidashingo
0
8
AIコーディング道場成果発表【予告】
yoshidashingo
0
9
20250426 LT
yoshidashingo
0
7
Difyで作る生成AIアプリ完全入門解説
yoshidashingo
1
18
AIエージェント時代のエンジニアになろう #jawsug #jawsdays2025 / 20250301 Agentic AI Engineering
yoshidashingo
10
7.1k
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
2.3k
Other Decks in Programming
See All in Programming
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
24
12k
アセットのコンパイルについて
ojun9
0
130
testingを眺める
matumoto
1
140
AIを活用し、今後に備えるための技術知識 / Basic Knowledge to Utilize AI
kishida
22
5.8k
詳解!defer panic recover のしくみ / Understanding defer, panic, and recover
convto
0
240
私の後悔をAWS DMSで解決した話
hiramax
4
210
アプリの "かわいい" を支えるアニメーションツールRiveについて
uetyo
0
270
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
690
概念モデル→論理モデルで気をつけていること
sunnyone
2
270
Reading Rails 1.0 Source Code
okuramasafumi
0
240
Rancher と Terraform
fufuhu
2
550
Deep Dive into Kotlin Flow
jmatsu
1
350
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
525
40k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
The Art of Programming - Codeland 2020
erikaheidi
56
13k
Why Our Code Smells
bkeepers
PRO
339
57k
GitHub's CSS Performance
jonrohan
1032
460k
Building Adaptive Systems
keathley
43
2.7k
Visualization
eitanlees
148
16k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
The Pragmatic Product Professional
lauravandoore
36
6.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Transcript
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AI Week for Developers ⽣成AIで本番アプリをリリースするための AWS, LangChain, ベクターデータベース実践⼊⾨ 吉⽥真吾 取締役CTO 株式会社サイダス
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 吉田真吾 AWS Serverless Hero n p Oracle SA p 113 / pAWS n ( ) CTO p SaaS ( ) pAWS DevOps n pAWS (2012 ) pAWS Samurai 2014 / 2016 pAWS Serverless Hero AWS AWS Lambda Amazon S3
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. https://www.cydas.co.jp/news/press/202304_people-gpt/ 「CYDAS PEOPLE」に、社員からの問い合わせに⾃動で答 えるChatGPT機能「CYDAS Copilot Chat」をリリース
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 6
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ChatGPT/LangChainによる チャットシステム構築[実践]⼊⾨ 本書ではまず、OpenAI APIとLangChainについて解説します。 ChatGPTのようなしくみを業務システムなどに組み込むために は、単にLLMに1つ⼊⼒して1つ出⼒を得るような実装ではな く、複数のタスクを⼀連のワークフロー処理として実現する必 要があります。また、ChatGPTが知識を持たない専⾨知識を答 えてほしいとか、意図した形式で応答が欲しいなど、実⽤性を ⾼める必要も出てきます。これらを実現するためのLangChain のつかいかたをわかりやすく解説します。 後半では、ステートレスなOpenAI APIに記憶を持たせたり、 必要に応じてWeb検索などを⾏うエージェント処理、さらに それらチャット形式の処理を、ステップバイステップでWeb アプリやSlackアプリとして実装します。 さらに、LLMアプリを本番稼働させるうえで必要となる、 ユーザー体験、セキュリティ、コンプライアンスへの準拠など のためのヒントや注意点も解説します。 7
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ChatGPT/LangChainによるチャットシステム構築[実践]⼊⾨ 8 質問に対してDuckDuckGoで外部検索して 答えるWebアプリ LLM を組み込んだチャットアプリケーションを写経しながら実装できる「ChatGPT/LangChain によるチャットシステム構築[実践]⼊⾨」を読んだ https://kakakakakku.hatenablog.com/entry/2023/10/16/085525 アップロードしたドキュメントについて 答えるSlackアプリ
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ⽣成AIでできること 1.⾔語⽣成 2.画像⽣成・動画⽣成 3.⾳声⽣成 4.マルチモーダル = 画像+⾔語→⾔語、⾔語→動画+⾔語、など ⾔語⽣成 • ⽂章⽣成、⽂章要約 • RAG(検索拡張⽣成) • 外部エージェントを利⽤した さまざまなアシスタント 9 メール⽂章の作成
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ⽣成AIでできること 10 事業企画アシスタント 1on1相⼿ コード⽣成 最新のマーケットリサーチ
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LLMアプリをつくるときに開発者が考えること 1.モデルの開発や選定について 基盤モデルから作る = コスト「超⼤」 カスタマイズ(ファインチューニング) = コスト「中」 RAGなどLLM性能+外部知識を利⽤する = コスト「低」 2.モデルをホストする計算資源(CPU/GPU)について ⾃社でホストする = コスト「⼤」 APIで利⽤する = コスト「低」 3.既存のシステムとの統合(ガバナンス) マルチクラウドで実装する = コスト「中」 ファーストパーティのみで実装する = コスト「低」 → 現有のモデル+API利⽤+ファーストパーティ(AWSユーザーならAWS)が 開発者にとってもっともROIが⾼い 11
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Bedrock 12 https://aws.amazon.com/jp/bedrock/
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LLMの能⼒をシステムに組み込みたい 1.API経由で使うモデルの選定 Amazon Bedrock > ClaudeやTitanFM、HuggingFace上のモデルの選定 2.アプリケーションフレームワークからユースケースに合わせて抽象化して 利⽤する LangChainなどのフレームワークで - 品質の安定したプロンプティング - モデルやパラメータの変更耐性に強いコード - キャッシュ、データベース、プラグインなどの統合利⽤ 3.ベクターデータベースや追加オプションなど、新たな技術スタックの統合 データ中⼼のアプローチ > Data Gravity tl;dr データ移動やコピーはコストがかかる、ロバスト性や完全性の懸念 13
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangChainとは 14 • LLMをつかったアプリケーション開発 のフレームワークライブラリ • モデル/メモリ/エージェント/Retriever などの機能が抽象化されており、少な いコードで効率的な開発・アウトプッ トが得られる • 開発初期において複雑なプロンプトエ ンジニアリングにかかる⼿間がユース ケースに合致したテンプレートを⾒つ けることで⼀気に短縮することも可能
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ベクターデータベースとは AWSで利⽤可能なベクターDBオプション • Amazon RDS for PostgreSQL - pgvector • Amazon Aurora PostgreSQL – pgvector • Amazon OpenSearch Service • Amazon Neptune ML LangChainでつかえるさまざまなベクターDB • Pinecone • Chroma (ローカル) • Momento Vector Index • PGVector • Redis (Redisearchオプション) • Elasticsearch • MongoDB Atlas • Supabase (Postgres) • OpenSearch • etc… 15 ⽂章や画像から、コンピューターが⾔語処理や解析しやすいベクトル空間の数値データに変換した「⾼次元ベクトル」の データをホストすることで、インプットと類似度で検索が可能なデータベース。 単語やフレーズをインプットとして、意味の類似する⽂書のチャンクを取り出す⽬的などに利⽤される。 https://python.langchain.com/docs/integrations/vectorstores/ https://aws.amazon.com/jp/what-is/vector-databases/ https://aws.amazon.com/jp/about-aws/whats- new/2023/07/amazon-aurora-postgresql-pgvector-vector-storage- similarity-search/
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangChain + Amazon Bedrock(Titan/Claude) + Pinecone 16 aws-samples/amazon-bedrock-workshop https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/03_QuestionAnswering/02_rag_claude_titan_pinecone.ipynb
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 本番リリースする前に[観測・テスト・評価] • ユースケースにあわせたテスト評価セットの事前作成 • 現在、独⾃の知識をもちいたRAGや、エージェントツールに対し て万能に精度を評価する有効性の⾼いソリューションはない。 • LangSmithで以下の値を参考にしてテストする • P99 Latency • Tokens (消費) • Input / Retrival結果 / Output 17
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangSmith 18
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangSmith 19
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 本番リリースする前に[セキュリティについて] • 意図しないコンテンツの⼊⼒防⽌ チャットボットの質問など、⼊⼒コンテンツに意図しないものを 含まないよう、アプリケーションのUIでガイダンスを設置する。 ⼊⼒フィルター機能が使える場合は使う • 不適切な出⼒の回避 暴⼒的な発⾔や偏⾒、不快なコンテンツのチェック→排除。 出⼒フィルター機能が使える場合は使う レイテンシと安全性のトレードオフを加味する。 • プロンプトインジェクションの防⽌ ⼊⼒コンテンツで指⽰を上書きし、任意の指⽰を可能にする攻撃。 ⼊⼒プロンプトによって指⽰が上書きされないようなプロンプト テンプレートの構成をおこなうこと。 • トークンを⼤量に消費させる攻撃の防⽌ ⼊⼒コンテンツの⻑さチェックや、⼀定時間内の実⾏回数やトー クン消費量に上限を設けるなどして、リクエスト内容に制限をか ける。 20 • 安全でない出⼒コンテンツのチェック LLMアプリケーションの出⼒内容が、システム全体にとって安全 でない内容(たとえばXSSやCSRFを引き起こすコードなど)を出⼒ しないように、出⼒コンテンツのチェックをおこない、⼀律の⽂ 字列エンコード処理などをおこなう。 • 脆弱性の排除 新しいライブラリやフレームワークの導⼊、リリースパイプライ ンの構築で、脆弱性が混⼊しうるポイントが増える。現⾏システ ムと同等の脆弱性対応を実施する。 • エージェントを暴⾛させない 外部接続性・実⾏性が⾼いエージェントを暴⾛させない。 エージェント = 前⼯程でLLMが⽣成したコンテンツから次⼯程の 指⽰を推論することでワークフローを達成しようと動作する.。 実⾏可能な外部機能を最⼩限にし、操作対象の権限(データの取 得・編集・削除など)を最⼩化する。 ⼗分なケースでテストを実施する。 OWASP Top 10 for Large Language Model Applications https://owasp.org/www-project-top-10-for-large-language-model-applications/
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Thank you! © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.