Qdrant 動作確認

ベクトルデータベース「Qdrant」の導入から基本操作まで。


Qdrantとは?

  • 高速・軽量なベクトル検索エンジン(Rust製)
  • REST APIで操作可能
  • 日本語にも強い
  • Dockerで簡単に動く

1. 用語の対応関係(RDBとの比較)

【QdrantとRDBの対応】

Qdrant用語 : 意味           : RDBの例え
----------------------------------------
Collection  : データの入れ物 : テーブル
Point       : 1件のデータ    : レコード
Vector      : 特徴ベクトル   : インデックス(検索用)
Payload     : メタ情報       : カラム

2. Qdrantの起動

Dockerがあれば以下で起動可能:

docker run -p 6333:6333 -v ./qdrant_storage:/qdrant/storage qdrant/qdrant

ダッシュボード確認:
http://localhost:6333/dashboard#/collections


3. コレクション作成

PowerShellで実行する場合:

curl -Method PUT "http://localhost:6333/collections/articles" `
 -Headers @{ "Content-Type" = "application/json" } `
 -Body '{
   "vectors": {
     "size": 4,
     "distance": "Cosine"
   }
 }'

4. ポイント登録(Upsert)

curl -Method PUT "http://localhost:6333/collections/articles/points" `
 -Headers @{ "Content-Type" = "application/json" } `
 -Body '{
   "points": [
     {
       "id": 1,
       "vector": [0.1, 0.2, 0.3, 0.4],
       "payload": {
         "title": "AI",
         "category": "tech"
       }
     }
   ]
 }'

5. ポイント削除

curl -Method POST "http://localhost:6333/collections/articles/points/delete" `
  -Headers @{ "Content-Type" = "application/json" } `
  -Body '{
    "points": [2,3]
  }'

6. 類似検索

curl -Method POST "http://localhost:6333/collections/articles/points/search" `
 -Headers @{ "Content-Type" = "application/json" } `
 -Body '{
   "vector": [0.1, 0.2, 0.3, 0.4],
   "top": 3,
   "with_payload": true
 }'

7. ユーザーごとのデータ管理

RDBのカラム追加のようなこともPayloadで柔軟にできます:

"payload": {
  "title": "AIとは",
  "user_id": 42
}

検索時には以下でフィルタ可能:

"filter": {
  "must": [
    { "key": "user_id", "match": { "value": 42 } }
  ]
}

まとめ

  • Qdrantは柔軟で軽量なベクトルDB
  • Payloadで情報追加・検索も自由自在
  • PowerShellで簡単に操作できる
  • ダッシュボードもあり確認しやすい

返信を残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です