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
Rust製ベクトル検索エンジンQdrant / qdrant-rust-vector-search
Search
Junichi Sato
January 24, 2022
Programming
810
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rust製ベクトル検索エンジンQdrant / qdrant-rust-vector-search
Junichi Sato
January 24, 2022
More Decks by Junichi Sato
See All by Junichi Sato
React Nativeを使ったリアルタイム配信サービスの開発 / React-Native-Matsuri-2021-BAKOON-Development
sat0b
0
1.5k
React NativeとFirebaseを使ったアプリ開発 / App Development using React Native and Firebase
sat0b
1
1.1k
React Nativeで新規事業開発に挑戦した話 / Challenging New Business Development with React Native
sat0b
0
970
Other Decks in Programming
See All in Programming
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
360
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
140
FDEが実現するAI駆動経営の現在地
gonta
2
280
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
170
the container ship “Apple Silicon”@WWDC26 Recap -Japan-\(region).swift
shingangan
0
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
560
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
760
プロポーザルを書いてもらう
pvcresin
0
300
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
210
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.5k
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
Featured
See All Featured
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
420
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Believing is Seeing
oripsolob
1
180
The Curious Case for Waylosing
cassininazir
1
450
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
460
Technical Leadership for Architectural Decision Making
baasie
3
470
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
Discover your Explorer Soul
emna__ayadi
2
1.2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
590
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Transcript
Rust製ベクトル検索エンジン Qdrantの紹介 Junichi Sato
発表の概要 • ベクトル検索エンジンとは ◦ ベクトル検索技術 • Qdrantについて ◦ 機能の紹介 •
Qdrantコードを読んでみて ◦ Rust初心者の視点で良いと思ったところ
自己紹介 • 佐藤純一 ◦ note: https://note.com/sat0b3ee • 類似画像検索に興味あり ◦ 先週、類似画像検索の本が
技術の泉シリーズで販売されました • Rustは入門したばかり ※ Qdrantの直接の関係者ではないです
ベクトル検索エンジンとは何か • 近似最近傍探索(ANN)の技術を利用して、 大規模なベクトルデータの中から近似ベクトルを探す • 活用例 ◦ 類似画像検索 ◦ セマンティックテキスト検索
• 代表的なベクトル検索エンジン(サービス) ◦ Milvus (Go) ◦ Vald (Go) ◦ Elasticsearch KNN (Java) ◦ Qdrant (Rust) 参考) https://github.com/currentsapi/awesome-vector-search
類似画像検索での活用例 ANN インデックス 数百万 ~ 数十億スケール 画像 Deep Learning 画像のベクトル化
[0.0232, -0.832, …, ]
ベクトル検索エンジンの課題 • 一般的なベクトル検索では「絞り込み」が利用できないことが多い ◦ 全文検索エンジンではよく使う機能 (Apache SolrやElasticsearchなど) ▪ 機能要件的によくある ◦
ECサイトでの商品の類似画像検索の例: 「ストアAに絞り込んで類似画像を検索したい」 • 対処法 ◦ 検索を多めに引いて、後段でフィルタする ▪ ただし、ごっそり後段のフィルタで消えてしまう可能性がある ◦ フィルタ条件ごとにインデックスを分割する ▪ ただし、構築が大変、柔軟性がない
Qdrantについて • Rust製のベクトル検索エンジン ◦ フィルタ条件による絞り込み検索が可能 ◦ 高い信頼性と高いパフォーマンス • GitHubリポジトリ ◦
https://github.com/qdrant/qdrant • 公式のデモ ◦ https://demo.qdrant.tech/#/ ◦ セマンティック検索のデモ(クエリの意味を把握して結果を返す) 余談)現在、Rustの開発者を募集しているらしいです。(LinkedIn) https://github.com/qdrant/qdrant より
Qdrantの詳細 • APIを持つサービスとして起動 ◦ REST API or gRPC API •
フィルタ検索 ◦ HNSWを元にした条件付き検索 ▪ 文字列、数値、Geo、... ◦ should / must / must_not • 分散システム(シャーディングなど)はTodo ◦ https://qdrant.tech/documentation/distributed_deployment/
フィルタ付き検索 POST /collections/{collection_name}/points/search { “filter”: { “must”: [ { “key”:
“city”, “match”: { “keyword”: “London” } } ] }, “params”: { “hnsw_ef”: 128 }, “vector”: [0.2, 0.1, 0.9, 0.7], “top”: 3 } • HNSWアルゴリズムをベース としてフィルター可能に変更 例 • キーcityがLondon のエンティティのみを検索
Qdrantのコード (Rust) を読んでみて 良いなと思ったところ 1. 列挙型とパターンマッチ 2. 排他制御
列挙型とパターンマッチ • RustではEnumでさまざまな型のデータを持てる • 例: インデックスへのUpsertとDelete ◦ それぞれ異なる型のデータを統一的に処理 pub enum
PointOperations { /// Insert or update points UpsertPoints(PointInsertOperations), /// Delete point if exists DeletePoints { ids: Vec<PointIdType> }, } pub(crate) fn process_point_operation(...) -> CollectionResult<usize> { match point_operation { PointOperations::DeletePoints { ids, .. } => delete_points(&segments.read(), op_num, &ids), PointOperations::UpsertPoints(operation) => { let (ids, vectors, payloads) = match operation { ... コードの引用: https://github.com/qdrant/qdrant/blob/bf3d8c25753188b4ca5e69a13c7f26e3c383f05b/lib/collection/src/collection_manager/segments_updater.rs#L234-L265
排他制御 • マルチスレッドでインデックスにアクセスする場合は排他制御が必要 ◦ 読み込みは同時アクセス OK、書き込みは一度に一つだけ • Arc<RwLock<Segment>> ◦ 所有権システムにより、
データ競合を起こせない 、明示的にアンロック不要 ▪ (デッドロックは起きうるので注意は必要 ) • 該当部分抜粋 ◦ read()でリードロック ◦ write()でライトロック コードの引用: https://github.com/qdrant/qdrant/blob/0f91c9a5e29ef9065c79a20e0ace25be898beff8/lib/collection/src/collection_manager/holders/segment_holder.rs // read let read_segment = segment_arc.read(); f(point, &read_segment); // write let mut write_segment = segment_arc.write(); f(point_id, *idx, &mut write_segment)?
おわりに • Qdrantはきれいに書かれていて色々勉強になる