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')