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
Deep Dive into Momento with LangChain
Search
Kazuki Maeda
June 22, 2023
Technology
1
380
Deep Dive into Momento with LangChain
もめんと Meet-up in June #2
Kazuki Maeda
June 22, 2023
Tweet
Share
More Decks by Kazuki Maeda
See All by Kazuki Maeda
Amazon Bedrockで実現する 新たな学習体験
kzkmaeda
2
550
日本の教育の未来 を考える テクノロジーは教育をどのように変えるのか
kzkmaeda
1
210
モノリスの認知負荷に立ち向かう、コードの所有者という思想と現実
kzkmaeda
0
210
エンジニアリング価値を黒字化する バリューベース戦略を用いた 技術戦略策定の道のり
kzkmaeda
9
5.6k
現場の種を事業の芽にする - エンジニア主導のイノベーションを事業戦略に装着する方法 -
kzkmaeda
2
5.3k
生成AIを用いた 新しい学びの体験を 提供するまでの道のり
kzkmaeda
0
290
生成AIによって変わる世界 -可能性とリスクについて考える-
kzkmaeda
2
300
新しいことを組織ではじめる、そしてつづける
kzkmaeda
5
950
20240824_JAWS_PANKRATION_2024
kzkmaeda
0
110
Other Decks in Technology
See All in Technology
Model Mondays S2E02: Model Context Protocol
nitya
0
220
Navigation3でViewModelにデータを渡す方法
mikanichinose
0
220
Witchcraft for Memory
pocke
1
330
Prox Industries株式会社 会社紹介資料
proxindustries
0
290
Microsoft Build 2025 技術/製品動向 for Microsoft Startup Tech Community
torumakabe
2
270
“社内”だけで完結していた私が、AWS Community Builder になるまで
nagisa53
1
390
Delegating the chores of authenticating users to Keycloak
ahus1
0
120
AWS CDK 実践的アプローチ N選 / aws-cdk-practical-approaches
gotok365
6
740
Uniadex__公開版_20250617-AIxIoTビジネス共創ラボ_ツナガルチカラ_.pdf
iotcomjpadmin
0
160
2025-06-26_Lightning_Talk_for_Lightning_Talks
_hashimo2
2
100
Welcome to the LLM Club
koic
0
170
Oracle Audit Vault and Database Firewall 20 概要
oracle4engineer
PRO
3
1.7k
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
124
52k
How to train your dragon (web standard)
notwaldorf
93
6.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
GraphQLとの向き合い方2022年版
quramy
48
14k
Code Review Best Practice
trishagee
68
18k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Transcript
Deep Dive into Momento with LangChain もめんと Meet-up in June
#2 kzk_maeda
Kazuki Maeda @kzk_maeda SRE @atama plus AWS Community Builders AWS
Startup Community Core Member 7+ years of experience of AWS Like: Lambda / Step Functions / Glue / MWAA / Athena 最近はGoogle CloudとLLM系を勉強中 自己紹介
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
Momento Cacheとは • Serverless Cache Service • Web上でセットアップして、SDKを埋め込むだけで クラスターセットアップなど不要で利用開始できる •
キャパシティの管理、プロビジョニング、パフォーマンスモニタリングなど オペレーション業務からの解放
LangChainとは • LLM(大規模言語モデル)を利用したアプリケーション開発に利用できる ライブラリ • 各種LLM APIの抽象化、独自データのLoader、ツール群の組み合わせなどの 様々な機能が提供されている • バージョンアップ頻度が異常
なぜLangChainとMomento? https://twitter.com/LangChainAI/status/1662138670332395520?s=20
なぜLangChainとMomento? https://python.langchain.com/docs/ecosystem/integrations/momento
なぜLangChainとMomento? https://www.gomomento.com/blog/momento-is-now-fully-integrated-into-the-langchain-ecosystem
LangChainでMomentoが使える場所 • LLM Cache • Conversation Memory
LLM Cache 通常LangChainでは、都度OpenAIなどのLLMサービスとやりとりをしますが
LLM Cache Cacheが効いていると、InterceptしてCacheからResponseを返します
LLM Cache 実装 数行のコードで実装可能
LLM Cache クエリ時間比較 同一のPromptであれば実行時間を90%以上低減
LLM Cache Token消費量比較 CacheがAnswerを返すのでOpenAIのToken消費量は0
LLM Cache 時間もコストも削減が見込める!!
Conversation Memory 通常、LangChainからLLMへのRequestは状態を持たないので独立実行 →以前の会話内容をLangChainは記憶しない
Conversation Memory ConversationChainのMemoryとしてMomentoを活用し、会話の流れを作れる
Conversation Memory 実装 こちらもシンプルなコードで実装可能
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
注 ここからLangChainのコードを眺めていきますが、 冒頭で紹介したように、LangChainの更新頻度は異常です。 以降のコードは version 0.0.207 のものとなっております。 また、説明の都合でコードの一部のみ抜粋して表示します。
LLM Cache 中で何が行われているのか追ってみましょう
LLM Cache llm_cache が有効であるとcacheに問い合わせる機構が LLMの基底クラスに定義されている
LLM Cache PromptとLLMのparameterをhash化して str castしたtextをKeyにして、Momentoに格納
LLM Cache こんな感じでCacheが衝突しないようになっている
Conversation Memory 中で何か行われているのか追ってみましょう
Conversation Memory ConversationChainの中でmemoryをセットできる
Conversation Memory デフォルトで message_store: 文字列をprefixに付与して session_id を追加したtextをKeyにしている
Conversation Memory plain textをKeyのprefixに追加することで、 CacheのKey(hash化された文字列)との衝突を 抑制している??という推測(中の人教えてください)
ここまで追ってみて • ライブラリを利用する側はシンプルに使えるようにいろんな処理が抽象化されてい る一方、実装側では衝突を防ぐための仕組みが入っていたりと工夫されていること がわかった • 実際にデバッグしてCache Keyを特定してコンソールから確認することができ、楽し かった
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
今後の期待 • Cache機構の拡大 ◦ (LangChainの対応が必要かもしれませんが) Embeddingの生成など、他にもTokenを利用し、時 間がかかる処理があるので、そこでも Cacheが効かせられると嬉しいなと思った • Vector
Storeとしての利用 ◦ 時限式で消えるVector Storeという用途がLLMアプリケーションの中ではそこそこ求められるケース がありそう ◦ Vector Storeが消えていたら新規に Embedding生成してStoreすることでデータ鮮度を高く保つとか ◦ Momentoでそれが実現できると管理が楽で嬉しいなと思った
今後の期待 • 特にVector Storeとして使えると、こういう仕組みを作る時に使い勝手が 非常にいい(気がします)
Thank you