> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/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') ```