> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Qdrant ベクターストア QdrantVector クラスは、ベクトル類似検索エンジンの [Qdrant](https://qdrant.tech/) を使用したベクトル検索を提供します。 追加のペイロードと高度なフィルタリングをサポートし、ベクトルの保存、検索、管理に便利な API を備えた本番環境対応のサービスです。 ## コンストラクターオプション **url** (`string`): Qdrant インスタンスの REST URL。例: https\://xyz-example.eu-central.aws.cloud.qdrant.io:6333 **apiKey** (`string`): 任意の Qdrant API キー **https** (`boolean`): 接続設定時に TLS を使用するかどうか。使用を推奨します。 ## メソッド ### `createIndex()` **indexName** (`string`): 作成するインデックスの名前 **dimension** (`number`): ベクトルの次元数(埋め込みモデルと一致させる必要があります)。単一ベクトルのコレクションでは必須です。 **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): 類似検索の距離メトリクス (Default: `cosine`) **namedVectors** (`Record`): 名前付きベクトル空間の設定。指定すると、複数の名前付きベクトルフィールドを持つコレクションを作成します。 #### 名前付きベクトルのコレクションを作成する ```typescript // 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()` **indexName** (`string`): upsert 先のインデックス名 **vectors** (`number[][]`): 埋め込みベクトルの配列 **metadata** (`Record[]`): 各ベクトルのメタデータ **ids** (`string[]`): 任意のベクトル ID(指定しない場合は自動生成されます) **vectorName** (`string`): 名前付きベクトルを使用する場合の upsert 先ベクトル空間の名前。 #### 名前付きベクトル空間に upsert する ```typescript // 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()` **indexName** (`string`): 検索するインデックスの名前 **queryVector** (`number[]`): 類似ベクトルを検索するためのクエリベクトル **topK** (`number`): 返す結果の数 (Default: `10`) **filter** (`Record`): クエリに適用するメタデータフィルター **includeVector** (`boolean`): 結果にベクトルを含めるかどうか (Default: `false`) **using** (`string`): 名前付きベクトルを使用する場合に検索するベクトルフィールドの名前。コレクションに複数の名前付きベクトルフィールドがある場合に使用します。 #### 名前付きベクトル Qdrant は、各ベクトルフィールドに名前を割り当てる[コレクションごとの複数ベクトル](https://qdrant.tech/documentation/concepts/vectors/#named-vectors)をサポートしています。`using` パラメーターで検索対象のベクトルフィールドを選択します。 ```typescript const results = await store.query({ indexName: 'my_index', queryVector: embedding, topK: 10, using: 'title_embedding', // Query against a specific named vector }) ``` ### `listIndexes()` インデックス名を文字列の配列として返します。 ### `describeIndex()` **indexName** (`string`): 詳細を取得するインデックスの名前 戻り値: ```typescript interface IndexStats { dimension: number count: number metric: 'cosine' | 'euclidean' | 'dotproduct' } ``` ### `deleteIndex()` **indexName** (`string`): 削除するインデックスの名前 ### `updateVector()` ID またはメタデータフィルターで単一のベクトルを更新します。`id` と `filter` のどちらか一方だけを指定する必要があります。 **indexName** (`string`): 更新するインデックスの名前 **id** (`string`): 更新するベクトルの ID(filter と同時に指定できません) **filter** (`Record`): 更新するベクトルを特定するメタデータフィルター(id と同時に指定できません) **update** (`{ vector?: number[]; metadata?: Record; }`): 更新するベクトルやメタデータを含むオブジェクト 指定したインデックス内のベクトルやメタデータを更新します。ベクトルとメタデータの両方を指定すると、両方が更新されます。いずれか一方だけを指定した場合は、その値のみが更新されます。 ### `deleteVector()` **indexName** (`string`): ベクトルを削除するインデックスの名前 **id** (`string`): 削除するベクトルの ID 指定したインデックスから ID を使用してベクトルを削除します。 ### `deleteVectors()` ID またはメタデータフィルターで複数のベクトルを削除します。`ids` と `filter` のどちらか一方だけを指定する必要があります。 **indexName** (`string`): 削除するベクトルを含むインデックスの名前 **ids** (`string[]`): 削除するベクトル ID の配列(filter と同時に指定できません) **filter** (`Record`): 削除するベクトルを特定するメタデータフィルター(ids と同時に指定できません) ### `createPayloadIndex()` 効率的なフィルタリングを可能にするため、コレクションのフィールドにペイロード(メタデータ)インデックスを作成します。これは Qdrant Cloud および `strict_mode_config = true` の Qdrant インスタンスでは**必須**です。 **indexName** (`string`): ペイロードインデックスを作成するコレクションの名前 **fieldName** (`string`): インデックスを作成するペイロードフィールドの名前 **fieldSchema** (`'keyword' | 'integer' | 'float' | 'geo' | 'text' | 'bool' | 'datetime' | 'uuid'`): ペイロードフィールドのスキーマ型 **wait** (`boolean`): 操作の完了を待つかどうか (Default: `true`) ```typescript // 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()` コレクションのフィールドからペイロードインデックスを削除します。 **indexName** (`string`): ペイロードインデックスを削除するコレクションの名前 **fieldName** (`string`): 削除するペイロードフィールドインデックスの名前 **wait** (`boolean`): 操作の完了を待つかどうか (Default: `true`) ## レスポンス型 クエリ結果は次の形式で返されます。 ```typescript interface QueryResult { id: string score: number metadata: Record vector?: number[] // Only included if includeVector is true } ``` ## エラー処理 ストアはキャッチ可能な型付きエラーをスローします。 ```typescript 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 } } ``` ## 関連情報 - [メタデータフィルター](https://mastra.zisheng.pro/ja/reference/rag/metadata-filters)