メインコンテンツへ移動

Vectors API

Vectors API は、Mastra でセマンティック検索や類似度マッチングのためのベクトル埋め込みを扱うメソッドを提供します。

ベクトルの操作
ベクトルの操作への直接リンク

ベクトルストアのインスタンスを取得します。

const vector = mastraClient.getVector('vector-name')

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

Vector インデックスの詳細を取得
Vector インデックスの詳細を取得への直接リンク

特定の Vector インデックスに関する情報を取得します。

const details = await vector.details('index-name')

Vector インデックスを作成
Vector インデックスを作成への直接リンク

新しい Vector インデックスを作成します。

const result = await vector.createIndex({
indexName: 'new-index',
dimension: 128,
metric: 'cosine', // 'cosine', 'euclidean', or 'dotproduct'
})

ベクトルを upsert
ベクトルを upsertへの直接リンク

インデックスにベクトルを追加または更新します。

const ids = await vector.upsert({
indexName: 'my-index',
vectors: [
[0.1, 0.2, 0.3], // First vector
[0.4, 0.5, 0.6], // Second vector
],
metadata: [{ label: 'first' }, { label: 'second' }],
ids: ['id1', 'id2'], // Optional: Custom IDs
})

ベクトルを検索
ベクトルを検索への直接リンク

類似するベクトルを検索します。

const results = await vector.query({
indexName: 'my-index',
queryVector: [0.1, 0.2, 0.3],
topK: 10,
filter: { label: 'first' }, // Optional: Metadata filter
includeVector: true, // Optional: Include vectors in results
})

すべてのインデックスを取得
すべてのインデックスを取得への直接リンク

利用可能なすべてのインデックスを一覧表示します。

const indexes = await vector.getIndexes()

インデックスを削除
インデックスを削除への直接リンク

Vector インデックスを削除します。

const result = await vector.delete('index-name')