UNPKG

@mastra/core

Version:

The core foundation of the Mastra framework, providing essential components and interfaces for building AI-powered applications.

73 lines (69 loc) 2.65 kB
'use strict'; var chunkRO52JMKQ_cjs = require('./chunk-RO52JMKQ.cjs'); // src/vector/vector.ts var MastraVector = class extends chunkRO52JMKQ_cjs.MastraBase { constructor() { super({ name: "MastraVector", component: "VECTOR" }); } get indexSeparator() { return "_"; } baseKeys = { query: ["queryVector", "topK", "filter", "includeVector"], upsert: ["vectors", "metadata", "ids"], createIndex: ["dimension", "metric"] }; normalizeArgs(method, [first, ...rest], extendedKeys = []) { if (typeof first === "object") { return first; } this.logger.warn( `Deprecation Warning: Passing individual arguments to ${method}() is deprecated. Please use an object parameter instead. Individual arguments will be removed on May 20th.` ); const baseKeys = this.baseKeys[method] || []; const paramKeys = [...baseKeys, ...extendedKeys].slice(0, rest.length); return { indexName: first, ...Object.fromEntries(paramKeys.map((key, i) => [key, rest[i]])) }; } async updateIndexById(_indexName, _id, _update) { throw new Error("updateIndexById is not implemented yet"); } async deleteIndexById(_indexName, _id) { throw new Error("deleteById is not implemented yet"); } async validateExistingIndex(indexName, dimension, metric) { let info; try { info = await this.describeIndex(indexName); } catch (infoError) { const message = `Index "${indexName}" already exists, but failed to fetch index info for dimension check: ${infoError}`; this.logger?.error(message); throw new Error(message); } const existingDim = info?.dimension; const existingMetric = info?.metric; if (existingDim === dimension) { this.logger?.info( `Index "${indexName}" already exists with ${existingDim} dimensions and metric ${existingMetric}, skipping creation.` ); if (existingMetric !== metric) { this.logger?.warn( `Attempted to create index with metric "${metric}", but index already exists with metric "${existingMetric}". To use a different metric, delete and recreate the index.` ); } } else if (info) { const message = `Index "${indexName}" already exists with ${existingDim} dimensions, but ${dimension} dimensions were requested`; this.logger?.error(message); throw new Error(message); } else { const message = `Index "${indexName}" already exists, but could not retrieve its dimensions for validation.`; this.logger?.error(message); throw new Error(message); } } }; exports.MastraVector = MastraVector;