Vectors API
The Vectors API provides methods to work with vector embeddings for semantic search and similarity matching in Mastra.
Working with vectorsWorking with vectors的直接链接
Get an instance of a vector store:
const vector = mastraClient.getVector('vector-name')
Vector methodsVector methods的直接链接
Get Vector Index DetailsGet Vector Index Details的直接链接
Retrieve information about a specific vector index:
const details = await vector.details('index-name')
Create Vector IndexCreate Vector Index的直接链接
Create a new vector index:
const result = await vector.createIndex({
indexName: 'new-index',
dimension: 128,
metric: 'cosine', // 'cosine', 'euclidean', or 'dotproduct'
})
Upsert VectorsUpsert Vectors的直接链接
Add or update vectors in an index:
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
})
Query VectorsQuery Vectors的直接链接
Search for similar vectors:
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
})
Get All IndexesGet All Indexes的直接链接
List all available indexes:
const indexes = await vector.getIndexes()
Delete IndexDelete Index的直接链接
Delete a vector index:
const result = await vector.delete('index-name')