@mastra/vectorize 0.11.2 → 0.11.3-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -450,3 +450,5 @@ Example Complex Query:
450
450
 
451
451
  exports.CloudflareVector = CloudflareVector;
452
452
  exports.VECTORIZE_PROMPT = VECTORIZE_PROMPT;
453
+ //# sourceMappingURL=index.cjs.map
454
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":["BaseFilterTranslator","MastraVector","Cloudflare","error","MastraError","ErrorDomain","ErrorCategory"],"mappings":";;;;;;;;;;;;AAsBO,IAAM,yBAAA,GAAN,cAAwCA,2BAAA,CAA4C;AAAA,EACtE,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAGA,2BAAA,CAAqB,iBAAA;AAAA,MACxB,SAAS,EAAC;AAAA,MACV,KAAA,EAAO,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,MACrB,SAAS,EAAC;AAAA,MACV,OAAO,EAAC;AAAA,MACR,QAAQ;AAAC,KACX;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAAuD;AAC/D,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,EAAG,OAAO,MAAA;AACjC,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAC1B,IAAA,OAAO,IAAA,CAAK,cAAc,MAAM,CAAA;AAAA,EAClC;AAAA,EAEQ,aAAA,CAAc,IAAA,EAA6B,WAAA,GAAsB,EAAA,EAAS;AAChF,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA,EAAG;AACtB,MAAA,MAAM,IAAI,MAAM,qCAAqC,CAAA;AAAA,IACvD;AACA,IAAA,IAAI,IAAA,CAAK,WAAA,CAAY,IAAI,CAAA,EAAG,OAAO,EAAE,GAA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AA;AAAA,CAAA","file":"index.cjs","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;\n\ntype VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;\n\ntype VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';\n\nexport type VectorizeVectorFilter = VectorFilter<\n keyof VectorizeOperatorValueMap,\n VectorizeOperatorValueMap,\n VectorizeLogicalOperatorValueMap,\n VectorizeBlacklistedRootOperators\n>;\n\nexport class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: [],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n return this.translateNode(filter);\n }\n\n private translateNode(node: VectorizeVectorFilter, currentPath: string = ''): any {\n if (this.isRegex(node)) {\n throw new Error('Regex is not supported in Vectorize');\n }\n if (this.isPrimitive(node)) return { $eq: this.normalizeComparisonValue(node) };\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n return { [operator]: this.normalizeComparisonValue(value) };\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.normalizeComparisonValue(value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n continue;\n }\n\n // Check if the nested object contains operators\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n result[newPath] = this.translateNode(value);\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n return result;\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n IndexStats,\n} from '@mastra/core/vector';\nimport Cloudflare from 'cloudflare';\n\nimport { VectorizeFilterTranslator } from './filter';\nimport type { VectorizeVectorFilter } from './filter';\n\ntype VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;\n\nexport class CloudflareVector extends MastraVector<VectorizeVectorFilter> {\n client: Cloudflare;\n accountId: string;\n\n constructor({ accountId, apiToken }: { accountId: string; apiToken: string }) {\n super();\n this.accountId = accountId;\n\n this.client = new Cloudflare({\n apiToken: apiToken,\n });\n }\n\n get indexSeparator(): string {\n return '-';\n }\n\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n // Create NDJSON string - each line is a JSON object\n const ndjson = vectors\n .map((vector, index) =>\n JSON.stringify({\n id: generatedIds[index]!,\n values: vector,\n metadata: metadata?.[index],\n }),\n )\n .join('\\n');\n\n try {\n // Note: __binaryRequest is required for proper NDJSON handling\n await this.client.vectorize.indexes.upsert(\n indexName,\n {\n account_id: this.accountId,\n body: ndjson,\n },\n {\n __binaryRequest: true,\n },\n );\n\n return generatedIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, vectorCount: vectors?.length },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: VectorizeVectorFilter) {\n const translator = new VectorizeFilterTranslator();\n return translator.translate(filter);\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n try {\n await this.client.vectorize.indexes.create({\n account_id: this.accountId,\n config: {\n dimensions: dimension,\n metric: metric === 'dotproduct' ? 'dot-product' : metric,\n },\n name: indexName,\n });\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.errors?.[0]?.message || error?.message;\n if (\n error.status === 409 ||\n (typeof message === 'string' &&\n (message.toLowerCase().includes('already exists') || message.toLowerCase().includes('duplicate')))\n ) {\n // Fetch index info and check dimensions\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n // For any other errors, propagate\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, dimension, metric },\n },\n error,\n );\n }\n }\n\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: VectorizeQueryParams): Promise<QueryResult[]> {\n try {\n const translatedFilter = this.transformFilter(filter) ?? {};\n const response = await this.client.vectorize.indexes.query(indexName, {\n account_id: this.accountId,\n vector: queryVector,\n returnValues: includeVector,\n returnMetadata: 'all',\n topK,\n filter: translatedFilter,\n });\n\n return (\n response?.matches?.map((match: any) => {\n return {\n id: match.id,\n metadata: match.metadata,\n score: match.score,\n vector: match.values,\n };\n }) || []\n );\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, topK },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const res = await this.client.vectorize.indexes.list({\n account_id: this.accountId,\n });\n\n return res?.result?.map(index => index.name!) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const index = await this.client.vectorize.indexes.get(indexName, {\n account_id: this.accountId,\n });\n\n const described = await this.client.vectorize.indexes.info(indexName, {\n account_id: this.accountId,\n });\n\n return {\n dimension: described?.dimensions!,\n // Since vector_count is not available in the response,\n // we might need a separate API call to get the count if needed\n count: described?.vectorCount || 0,\n metric: index?.config?.metric as 'cosine' | 'euclidean' | 'dotproduct',\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.vectorize.indexes.delete(indexName, {\n account_id: this.accountId,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean') {\n try {\n await this.client.vectorize.indexes.metadataIndex.create(indexName, {\n account_id: this.accountId,\n propertyName,\n indexType,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_CREATE_METADATA_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, propertyName, indexType },\n },\n error,\n );\n }\n }\n\n async deleteMetadataIndex(indexName: string, propertyName: string) {\n try {\n await this.client.vectorize.indexes.metadataIndex.delete(indexName, {\n account_id: this.accountId,\n propertyName,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DELETE_METADATA_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, propertyName },\n },\n error,\n );\n }\n }\n\n async listMetadataIndexes(indexName: string) {\n try {\n const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {\n account_id: this.accountId,\n });\n\n return res?.metadataIndexes ?? [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_LIST_METADATA_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: 'STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n text: 'No update data provided',\n details: { indexName, id },\n });\n }\n\n try {\n const updatePayload: any = {\n ids: [id],\n account_id: this.accountId,\n };\n\n if (update.vector) {\n updatePayload.vectors = [update.vector];\n }\n if (update.metadata) {\n updatePayload.metadata = [update.metadata];\n }\n\n await this.upsert({ indexName: indexName, vectors: updatePayload.vectors, metadata: updatePayload.metadata });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n await this.client.vectorize.indexes.deleteByIds(indexName, {\n ids: [id],\n account_id: this.accountId,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DELETE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Vectorize.\n */\nexport const VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"]}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { VECTORIZE_PROMPT } from './_tsup-dts-rollup.js';
2
- export { CloudflareVector } from './_tsup-dts-rollup.js';
1
+ export * from './vector/index.js';
2
+ export { VECTORIZE_PROMPT } from './vector/prompt.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -443,3 +443,5 @@ Example Complex Query:
443
443
  }`;
444
444
 
445
445
  export { CloudflareVector, VECTORIZE_PROMPT };
446
+ //# sourceMappingURL=index.js.map
447
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":[],"mappings":";;;;;;AAsBO,IAAM,yBAAA,GAAN,cAAwC,oBAAA,CAA4C;AAAA,EACtE,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAG,oBAAA,CAAqB,iBAAA;AAAA,MACxB,SAAS,EAAC;AAAA,MACV,KAAA,EAAO,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,MACrB,SAAS,EAAC;AAAA,MACV,OAAO,EAAC;AAAA,MACR,QAAQ;AAAC,KACX;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAAuD;AAC/D,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,EAAG,OAAO,MAAA;AACjC,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAC1B,IAAA,OAAO,IAAA,CAAK,cAAc,MAAM,CAAA;AAAA,EAClC;AAAA,EAEQ,aAAA,CAAc,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.js","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;\n\ntype VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;\n\ntype VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';\n\nexport type VectorizeVectorFilter = VectorFilter<\n keyof VectorizeOperatorValueMap,\n VectorizeOperatorValueMap,\n VectorizeLogicalOperatorValueMap,\n VectorizeBlacklistedRootOperators\n>;\n\nexport class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: [],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n return this.translateNode(filter);\n }\n\n private translateNode(node: VectorizeVectorFilter, currentPath: string = ''): any {\n if (this.isRegex(node)) {\n throw new Error('Regex is not supported in Vectorize');\n }\n if (this.isPrimitive(node)) return { $eq: this.normalizeComparisonValue(node) };\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n return { [operator]: this.normalizeComparisonValue(value) };\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.normalizeComparisonValue(value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n continue;\n }\n\n // Check if the nested object contains operators\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n result[newPath] = this.translateNode(value);\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n return result;\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n IndexStats,\n} from '@mastra/core/vector';\nimport Cloudflare from 'cloudflare';\n\nimport { VectorizeFilterTranslator } from './filter';\nimport type { VectorizeVectorFilter } from './filter';\n\ntype VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;\n\nexport class CloudflareVector extends MastraVector<VectorizeVectorFilter> {\n client: Cloudflare;\n accountId: string;\n\n constructor({ accountId, apiToken }: { accountId: string; apiToken: string }) {\n super();\n this.accountId = accountId;\n\n this.client = new Cloudflare({\n apiToken: apiToken,\n });\n }\n\n get indexSeparator(): string {\n return '-';\n }\n\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n // Create NDJSON string - each line is a JSON object\n const ndjson = vectors\n .map((vector, index) =>\n JSON.stringify({\n id: generatedIds[index]!,\n values: vector,\n metadata: metadata?.[index],\n }),\n )\n .join('\\n');\n\n try {\n // Note: __binaryRequest is required for proper NDJSON handling\n await this.client.vectorize.indexes.upsert(\n indexName,\n {\n account_id: this.accountId,\n body: ndjson,\n },\n {\n __binaryRequest: true,\n },\n );\n\n return generatedIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, vectorCount: vectors?.length },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: VectorizeVectorFilter) {\n const translator = new VectorizeFilterTranslator();\n return translator.translate(filter);\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n try {\n await this.client.vectorize.indexes.create({\n account_id: this.accountId,\n config: {\n dimensions: dimension,\n metric: metric === 'dotproduct' ? 'dot-product' : metric,\n },\n name: indexName,\n });\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.errors?.[0]?.message || error?.message;\n if (\n error.status === 409 ||\n (typeof message === 'string' &&\n (message.toLowerCase().includes('already exists') || message.toLowerCase().includes('duplicate')))\n ) {\n // Fetch index info and check dimensions\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n // For any other errors, propagate\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, dimension, metric },\n },\n error,\n );\n }\n }\n\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: VectorizeQueryParams): Promise<QueryResult[]> {\n try {\n const translatedFilter = this.transformFilter(filter) ?? {};\n const response = await this.client.vectorize.indexes.query(indexName, {\n account_id: this.accountId,\n vector: queryVector,\n returnValues: includeVector,\n returnMetadata: 'all',\n topK,\n filter: translatedFilter,\n });\n\n return (\n response?.matches?.map((match: any) => {\n return {\n id: match.id,\n metadata: match.metadata,\n score: match.score,\n vector: match.values,\n };\n }) || []\n );\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, topK },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const res = await this.client.vectorize.indexes.list({\n account_id: this.accountId,\n });\n\n return res?.result?.map(index => index.name!) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const index = await this.client.vectorize.indexes.get(indexName, {\n account_id: this.accountId,\n });\n\n const described = await this.client.vectorize.indexes.info(indexName, {\n account_id: this.accountId,\n });\n\n return {\n dimension: described?.dimensions!,\n // Since vector_count is not available in the response,\n // we might need a separate API call to get the count if needed\n count: described?.vectorCount || 0,\n metric: index?.config?.metric as 'cosine' | 'euclidean' | 'dotproduct',\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.vectorize.indexes.delete(indexName, {\n account_id: this.accountId,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean') {\n try {\n await this.client.vectorize.indexes.metadataIndex.create(indexName, {\n account_id: this.accountId,\n propertyName,\n indexType,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_CREATE_METADATA_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, propertyName, indexType },\n },\n error,\n );\n }\n }\n\n async deleteMetadataIndex(indexName: string, propertyName: string) {\n try {\n await this.client.vectorize.indexes.metadataIndex.delete(indexName, {\n account_id: this.accountId,\n propertyName,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DELETE_METADATA_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, propertyName },\n },\n error,\n );\n }\n }\n\n async listMetadataIndexes(indexName: string) {\n try {\n const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {\n account_id: this.accountId,\n });\n\n return res?.metadataIndexes ?? [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_LIST_METADATA_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: 'STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n text: 'No update data provided',\n details: { indexName, id },\n });\n }\n\n try {\n const updatePayload: any = {\n ids: [id],\n account_id: this.accountId,\n };\n\n if (update.vector) {\n updatePayload.vectors = [update.vector];\n }\n if (update.metadata) {\n updatePayload.metadata = [update.metadata];\n }\n\n await this.upsert({ indexName: indexName, vectors: updatePayload.vectors, metadata: updatePayload.metadata });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n await this.client.vectorize.indexes.deleteByIds(indexName, {\n ids: [id],\n account_id: this.accountId,\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_VECTORIZE_VECTOR_DELETE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Vectorize.\n */\nexport const VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"]}
@@ -0,0 +1,13 @@
1
+ import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { VectorFilter, OperatorSupport, OperatorValueMap, LogicalOperatorValueMap, BlacklistedRootOperators } from '@mastra/core/vector/filter';
3
+ type VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;
4
+ type VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;
5
+ type VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';
6
+ export type VectorizeVectorFilter = VectorFilter<keyof VectorizeOperatorValueMap, VectorizeOperatorValueMap, VectorizeLogicalOperatorValueMap, VectorizeBlacklistedRootOperators>;
7
+ export declare class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {
8
+ protected getSupportedOperators(): OperatorSupport;
9
+ translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
10
+ private translateNode;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/vector/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,KAAK,yBAAyB,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC,CAAC;AAEnH,KAAK,gCAAgC,GAAG,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC;AAExG,KAAK,iCAAiC,GAAG,wBAAwB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAErG,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAC9C,MAAM,yBAAyB,EAC/B,yBAAyB,EACzB,gCAAgC,EAChC,iCAAiC,CAClC,CAAC;AAEF,qBAAa,yBAA0B,SAAQ,oBAAoB,CAAC,qBAAqB,CAAC;cACrE,qBAAqB,IAAI,eAAe;IAW3D,SAAS,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAMhE,OAAO,CAAC,aAAa;CA+CtB"}
@@ -0,0 +1,51 @@
1
+ import { MastraVector } from '@mastra/core/vector';
2
+ import type { QueryResult, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams, IndexStats } from '@mastra/core/vector';
3
+ import Cloudflare from 'cloudflare';
4
+ import type { VectorizeVectorFilter } from './filter.js';
5
+ type VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;
6
+ export declare class CloudflareVector extends MastraVector<VectorizeVectorFilter> {
7
+ client: Cloudflare;
8
+ accountId: string;
9
+ constructor({ accountId, apiToken }: {
10
+ accountId: string;
11
+ apiToken: string;
12
+ });
13
+ get indexSeparator(): string;
14
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
15
+ transformFilter(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
16
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
17
+ query({ indexName, queryVector, topK, filter, includeVector, }: VectorizeQueryParams): Promise<QueryResult[]>;
18
+ listIndexes(): Promise<string[]>;
19
+ /**
20
+ * Retrieves statistics about a vector index.
21
+ *
22
+ * @param {string} indexName - The name of the index to describe
23
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
24
+ */
25
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
26
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
27
+ createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean'): Promise<void>;
28
+ deleteMetadataIndex(indexName: string, propertyName: string): Promise<void>;
29
+ listMetadataIndexes(indexName: string): Promise<Cloudflare.Vectorize.Indexes.MetadataIndex.MetadataIndexListResponse.MetadataIndex[]>;
30
+ /**
31
+ * Updates a vector by its ID with the provided vector and/or metadata.
32
+ * @param indexName - The name of the index containing the vector.
33
+ * @param id - The ID of the vector to update.
34
+ * @param update - An object containing the vector and/or metadata to update.
35
+ * @param update.vector - An optional array of numbers representing the new vector.
36
+ * @param update.metadata - An optional record containing the new metadata.
37
+ * @returns A promise that resolves when the update is complete.
38
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
39
+ */
40
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
41
+ /**
42
+ * Deletes a vector by its ID.
43
+ * @param indexName - The name of the index containing the vector.
44
+ * @param id - The ID of the vector to delete.
45
+ * @returns A promise that resolves when the deletion is complete.
46
+ * @throws Will throw an error if the deletion operation fails.
47
+ */
48
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
49
+ }
50
+ export {};
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,UAAU,MAAM,YA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mB,CAAC,SAAS,EAAE,MAAM;IAoB3C;;;;;;;;;OASG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsChF;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBzE"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Vector store specific prompt that details supported operators and examples.
3
+ * This prompt helps users construct valid filters for Vectorize.
4
+ */
5
+ export declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
6
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/vector/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,+5GA2E3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/vectorize",
3
- "version": "0.11.2",
3
+ "version": "0.11.3-alpha.0",
4
4
  "description": "Cloudflare Vectorize store provider for Mastra",
5
5
  "type": "module",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "default": "./dist/index.js"
16
16
  },
17
17
  "require": {
18
- "types": "./dist/index.d.cts",
18
+ "types": "./dist/index.d.ts",
19
19
  "default": "./dist/index.cjs"
20
20
  }
21
21
  },
@@ -33,15 +33,16 @@
33
33
  "tsup": "^8.5.0",
34
34
  "typescript": "^5.8.3",
35
35
  "vitest": "^3.2.4",
36
- "@mastra/core": "0.12.0",
37
- "@internal/lint": "0.0.24"
36
+ "@internal/types-builder": "0.0.1",
37
+ "@mastra/core": "0.13.0-alpha.2",
38
+ "@internal/lint": "0.0.26"
38
39
  },
39
40
  "peerDependencies": {
40
- "@mastra/core": ">=0.10.7-0 <0.13.0-0"
41
+ "@mastra/core": ">=0.10.7-0 <0.14.0-0"
41
42
  },
42
43
  "scripts": {
43
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
44
- "build:watch": "pnpm build --watch",
44
+ "build": "tsup --silent --config tsup.config.ts",
45
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
45
46
  "test": "vitest run",
46
47
  "lint": "eslint ."
47
48
  }
@@ -1,90 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
3
- import Cloudflare from 'cloudflare';
4
- import type { CreateIndexParams } from '@mastra/core/vector';
5
- import type { DeleteIndexParams } from '@mastra/core/vector';
6
- import type { DeleteVectorParams } from '@mastra/core/vector';
7
- import type { DescribeIndexParams } from '@mastra/core/vector';
8
- import type { IndexStats } from '@mastra/core/vector';
9
- import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
10
- import { MastraVector } from '@mastra/core/vector';
11
- import type { OperatorSupport } from '@mastra/core/vector/filter';
12
- import type { OperatorValueMap } from '@mastra/core/vector/filter';
13
- import type { QueryResult } from '@mastra/core/vector';
14
- import type { QueryVectorParams } from '@mastra/core/vector';
15
- import type { UpdateVectorParams } from '@mastra/core/vector';
16
- import type { UpsertVectorParams } from '@mastra/core/vector';
17
- import type { VectorFilter } from '@mastra/core/vector/filter';
18
-
19
- declare class CloudflareVector extends MastraVector<VectorizeVectorFilter> {
20
- client: Cloudflare;
21
- accountId: string;
22
- constructor({ accountId, apiToken }: {
23
- accountId: string;
24
- apiToken: string;
25
- });
26
- get indexSeparator(): string;
27
- upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
28
- transformFilter(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
29
- createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
30
- query({ indexName, queryVector, topK, filter, includeVector, }: VectorizeQueryParams): Promise<QueryResult[]>;
31
- listIndexes(): Promise<string[]>;
32
- /**
33
- * Retrieves statistics about a vector index.
34
- *
35
- * @param {string} indexName - The name of the index to describe
36
- * @returns A promise that resolves to the index statistics including dimension, count and metric
37
- */
38
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
39
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
40
- createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean'): Promise<void>;
41
- deleteMetadataIndex(indexName: string, propertyName: string): Promise<void>;
42
- listMetadataIndexes(indexName: string): Promise<Cloudflare.Vectorize.Indexes.MetadataIndex.MetadataIndexListResponse.MetadataIndex[]>;
43
- /**
44
- * Updates a vector by its ID with the provided vector and/or metadata.
45
- * @param indexName - The name of the index containing the vector.
46
- * @param id - The ID of the vector to update.
47
- * @param update - An object containing the vector and/or metadata to update.
48
- * @param update.vector - An optional array of numbers representing the new vector.
49
- * @param update.metadata - An optional record containing the new metadata.
50
- * @returns A promise that resolves when the update is complete.
51
- * @throws Will throw an error if no updates are provided or if the update operation fails.
52
- */
53
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
54
- /**
55
- * Deletes a vector by its ID.
56
- * @param indexName - The name of the index containing the vector.
57
- * @param id - The ID of the vector to delete.
58
- * @returns A promise that resolves when the deletion is complete.
59
- * @throws Will throw an error if the deletion operation fails.
60
- */
61
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
62
- }
63
- export { CloudflareVector }
64
- export { CloudflareVector as CloudflareVector_alias_1 }
65
-
66
- /**
67
- * Vector store specific prompt that details supported operators and examples.
68
- * This prompt helps users construct valid filters for Vectorize.
69
- */
70
- declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
71
- export { VECTORIZE_PROMPT }
72
- export { VECTORIZE_PROMPT as VECTORIZE_PROMPT_alias_1 }
73
-
74
- declare type VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';
75
-
76
- export declare class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {
77
- protected getSupportedOperators(): OperatorSupport;
78
- translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
79
- private translateNode;
80
- }
81
-
82
- declare type VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;
83
-
84
- declare type VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;
85
-
86
- declare type VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;
87
-
88
- export declare type VectorizeVectorFilter = VectorFilter<keyof VectorizeOperatorValueMap, VectorizeOperatorValueMap, VectorizeLogicalOperatorValueMap, VectorizeBlacklistedRootOperators>;
89
-
90
- export { }
@@ -1,90 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
3
- import Cloudflare from 'cloudflare';
4
- import type { CreateIndexParams } from '@mastra/core/vector';
5
- import type { DeleteIndexParams } from '@mastra/core/vector';
6
- import type { DeleteVectorParams } from '@mastra/core/vector';
7
- import type { DescribeIndexParams } from '@mastra/core/vector';
8
- import type { IndexStats } from '@mastra/core/vector';
9
- import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
10
- import { MastraVector } from '@mastra/core/vector';
11
- import type { OperatorSupport } from '@mastra/core/vector/filter';
12
- import type { OperatorValueMap } from '@mastra/core/vector/filter';
13
- import type { QueryResult } from '@mastra/core/vector';
14
- import type { QueryVectorParams } from '@mastra/core/vector';
15
- import type { UpdateVectorParams } from '@mastra/core/vector';
16
- import type { UpsertVectorParams } from '@mastra/core/vector';
17
- import type { VectorFilter } from '@mastra/core/vector/filter';
18
-
19
- declare class CloudflareVector extends MastraVector<VectorizeVectorFilter> {
20
- client: Cloudflare;
21
- accountId: string;
22
- constructor({ accountId, apiToken }: {
23
- accountId: string;
24
- apiToken: string;
25
- });
26
- get indexSeparator(): string;
27
- upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
28
- transformFilter(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
29
- createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
30
- query({ indexName, queryVector, topK, filter, includeVector, }: VectorizeQueryParams): Promise<QueryResult[]>;
31
- listIndexes(): Promise<string[]>;
32
- /**
33
- * Retrieves statistics about a vector index.
34
- *
35
- * @param {string} indexName - The name of the index to describe
36
- * @returns A promise that resolves to the index statistics including dimension, count and metric
37
- */
38
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
39
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
40
- createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean'): Promise<void>;
41
- deleteMetadataIndex(indexName: string, propertyName: string): Promise<void>;
42
- listMetadataIndexes(indexName: string): Promise<Cloudflare.Vectorize.Indexes.MetadataIndex.MetadataIndexListResponse.MetadataIndex[]>;
43
- /**
44
- * Updates a vector by its ID with the provided vector and/or metadata.
45
- * @param indexName - The name of the index containing the vector.
46
- * @param id - The ID of the vector to update.
47
- * @param update - An object containing the vector and/or metadata to update.
48
- * @param update.vector - An optional array of numbers representing the new vector.
49
- * @param update.metadata - An optional record containing the new metadata.
50
- * @returns A promise that resolves when the update is complete.
51
- * @throws Will throw an error if no updates are provided or if the update operation fails.
52
- */
53
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
54
- /**
55
- * Deletes a vector by its ID.
56
- * @param indexName - The name of the index containing the vector.
57
- * @param id - The ID of the vector to delete.
58
- * @returns A promise that resolves when the deletion is complete.
59
- * @throws Will throw an error if the deletion operation fails.
60
- */
61
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
62
- }
63
- export { CloudflareVector }
64
- export { CloudflareVector as CloudflareVector_alias_1 }
65
-
66
- /**
67
- * Vector store specific prompt that details supported operators and examples.
68
- * This prompt helps users construct valid filters for Vectorize.
69
- */
70
- declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
71
- export { VECTORIZE_PROMPT }
72
- export { VECTORIZE_PROMPT as VECTORIZE_PROMPT_alias_1 }
73
-
74
- declare type VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';
75
-
76
- export declare class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {
77
- protected getSupportedOperators(): OperatorSupport;
78
- translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
79
- private translateNode;
80
- }
81
-
82
- declare type VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;
83
-
84
- declare type VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;
85
-
86
- declare type VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;
87
-
88
- export declare type VectorizeVectorFilter = VectorFilter<keyof VectorizeOperatorValueMap, VectorizeOperatorValueMap, VectorizeLogicalOperatorValueMap, VectorizeBlacklistedRootOperators>;
89
-
90
- export { }
package/dist/index.d.cts DELETED
@@ -1,2 +0,0 @@
1
- export { VECTORIZE_PROMPT } from './_tsup-dts-rollup.cjs';
2
- export { CloudflareVector } from './_tsup-dts-rollup.cjs';