メインコンテンツへ移動

Qdrant ベクターストア

QdrantVector クラスは、ベクトル類似検索エンジンの Qdrant を使用したベクトル検索を提供します。 追加のペイロードと高度なフィルタリングをサポートし、ベクトルの保存、検索、管理に便利な API を備えた本番環境対応のサービスです。

コンストラクターオプション
コンストラクターオプションへの直接リンク

url:

string
Qdrant インスタンスの REST URL。例: https://xyz-example.eu-central.aws.cloud.qdrant.io:6333

apiKey:

string
任意の Qdrant API キー

https:

boolean
接続設定時に TLS を使用するかどうか。使用を推奨します。

メソッド
メソッドへの直接リンク

createIndex()
createindexへの直接リンク

indexName:

string
作成するインデックスの名前

dimension:

number
ベクトルの次元数(埋め込みモデルと一致させる必要があります)。単一ベクトルのコレクションでは必須です。

metric?:

'cosine' | 'euclidean' | 'dotproduct'
= cosine
類似検索の距離メトリクス

namedVectors?:

Record<string, { size: number; distance: 'cosine' | 'euclidean' | 'dotproduct' }>
名前付きベクトル空間の設定。指定すると、複数の名前付きベクトルフィールドを持つコレクションを作成します。

名前付きベクトルのコレクションを作成する
名前付きベクトルのコレクションを作成するへの直接リンク

// Create a collection with multiple named vector spaces
await store.createIndex({
indexName: 'multi_modal',
dimension: 768, // fallback
namedVectors: {
text: { size: 768, distance: 'cosine' },
image: { size: 512, distance: 'euclidean' },
},
})

upsert()
upsertへの直接リンク

indexName:

string
upsert 先のインデックス名

vectors:

number[][]
埋め込みベクトルの配列

metadata?:

Record<string, any>[]
各ベクトルのメタデータ

ids?:

string[]
任意のベクトル ID(指定しない場合は自動生成されます)

vectorName?:

string
名前付きベクトルを使用する場合の upsert 先ベクトル空間の名前。

名前付きベクトル空間に upsert する
名前付きベクトル空間に upsert するへの直接リンク

// Upsert into the "text" vector space
await store.upsert({
indexName: 'multi_modal',
vectors: textEmbeddings,
metadata: textMetadata,
vectorName: 'text',
})

// Upsert into the "image" vector space
await store.upsert({
indexName: 'multi_modal',
vectors: imageEmbeddings,
metadata: imageMetadata,
vectorName: 'image',
})

query()
queryへの直接リンク

indexName:

string
検索するインデックスの名前

queryVector:

number[]
類似ベクトルを検索するためのクエリベクトル

topK?:

number
= 10
返す結果の数

filter?:

Record<string, any>
クエリに適用するメタデータフィルター

includeVector?:

boolean
= false
結果にベクトルを含めるかどうか

using?:

string
名前付きベクトルを使用する場合に検索するベクトルフィールドの名前。コレクションに複数の名前付きベクトルフィールドがある場合に使用します。

名前付きベクトル
名前付きベクトルへの直接リンク

Qdrant は、各ベクトルフィールドに名前を割り当てるコレクションごとの複数ベクトルをサポートしています。using パラメーターで検索対象のベクトルフィールドを選択します。

const results = await store.query({
indexName: 'my_index',
queryVector: embedding,
topK: 10,
using: 'title_embedding', // Query against a specific named vector
})

listIndexes()
listindexesへの直接リンク

インデックス名を文字列の配列として返します。

describeIndex()
describeindexへの直接リンク

indexName:

string
詳細を取得するインデックスの名前

戻り値:

interface IndexStats {
dimension: number
count: number
metric: 'cosine' | 'euclidean' | 'dotproduct'
}

deleteIndex()
deleteindexへの直接リンク

indexName:

string
削除するインデックスの名前

updateVector()
updatevectorへの直接リンク

ID またはメタデータフィルターで単一のベクトルを更新します。idfilter のどちらか一方だけを指定する必要があります。

indexName:

string
更新するインデックスの名前

id?:

string
更新するベクトルの ID(filter と同時に指定できません)

filter?:

Record<string, any>
更新するベクトルを特定するメタデータフィルター(id と同時に指定できません)

update:

{ vector?: number[]; metadata?: Record<string, any>; }
更新するベクトルやメタデータを含むオブジェクト

指定したインデックス内のベクトルやメタデータを更新します。ベクトルとメタデータの両方を指定すると、両方が更新されます。いずれか一方だけを指定した場合は、その値のみが更新されます。

deleteVector()
deletevectorへの直接リンク

indexName:

string
ベクトルを削除するインデックスの名前

id:

string
削除するベクトルの ID

指定したインデックスから ID を使用してベクトルを削除します。

deleteVectors()
deletevectorsへの直接リンク

ID またはメタデータフィルターで複数のベクトルを削除します。idsfilter のどちらか一方だけを指定する必要があります。

indexName:

string
削除するベクトルを含むインデックスの名前

ids?:

string[]
削除するベクトル ID の配列(filter と同時に指定できません)

filter?:

Record<string, any>
削除するベクトルを特定するメタデータフィルター(ids と同時に指定できません)

createPayloadIndex()
createpayloadindexへの直接リンク

効率的なフィルタリングを可能にするため、コレクションのフィールドにペイロード(メタデータ)インデックスを作成します。これは Qdrant Cloud および strict_mode_config = true の Qdrant インスタンスでは必須です。

indexName:

string
ペイロードインデックスを作成するコレクションの名前

fieldName:

string
インデックスを作成するペイロードフィールドの名前

fieldSchema:

'keyword' | 'integer' | 'float' | 'geo' | 'text' | 'bool' | 'datetime' | 'uuid'
ペイロードフィールドのスキーマ型

wait?:

boolean
= true
操作の完了を待つかどうか
// Create a keyword index for filtering by source
await store.createPayloadIndex({
indexName: 'my_index',
fieldName: 'source',
fieldSchema: 'keyword',
})

const results = await store.query({
indexName: 'my_index',
queryVector: queryVector,
filter: { source: 'document-a' },
})

deletePayloadIndex()
deletepayloadindexへの直接リンク

コレクションのフィールドからペイロードインデックスを削除します。

indexName:

string
ペイロードインデックスを削除するコレクションの名前

fieldName:

string
削除するペイロードフィールドインデックスの名前

wait?:

boolean
= true
操作の完了を待つかどうか

レスポンス型
レスポンス型への直接リンク

クエリ結果は次の形式で返されます。

interface QueryResult {
id: string
score: number
metadata: Record<string, any>
vector?: number[] // Only included if includeVector is true
}

エラー処理
エラー処理への直接リンク

ストアはキャッチ可能な型付きエラーをスローします。

try {
await store.query({
indexName: 'index_name',
queryVector: queryVector,
})
} catch (error) {
if (error instanceof VectorStoreError) {
console.log(error.code) // 'connection_failed' | 'invalid_dimension' | etc
console.log(error.details) // Additional error context
}
}