> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Vectors API Vectors API 提供用于在 Mastra 中处理向量嵌入的方法,可用于语义搜索和相似度匹配。 ## 使用向量 获取向量存储的实例: ```typescript const vector = mastraClient.getVector('vector-name') ``` ## Vector 方法 ### 获取向量索引详情 检索特定向量索引的信息: ```typescript const details = await vector.details('index-name') ``` ### 创建向量索引 创建新的向量索引: ```typescript const result = await vector.createIndex({ indexName: 'new-index', dimension: 128, metric: 'cosine', // 'cosine', 'euclidean', or 'dotproduct' }) ``` ### Upsert 向量 在索引中添加或更新向量: ```typescript 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 }) ``` ### 查询向量 搜索相似向量: ```typescript 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 }) ``` ### 获取所有索引 列出所有可用索引: ```typescript const indexes = await vector.getIndexes() ``` ### 删除索引 删除向量索引: ```typescript const result = await vector.delete('index-name') ```