@mastra/astra 0.11.2 → 0.11.3

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.
@@ -1,23 +1,4 @@
1
1
 
2
- > @mastra/astra@0.11.2-alpha.0 build /home/runner/work/mastra/mastra/stores/astra
3
- > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
2
+ > @mastra/astra@0.11.3-alpha.0 build /home/runner/work/mastra/mastra/stores/astra
3
+ > tsup --silent --config tsup.config.ts
4
4
 
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.0
8
- TSC Build start
9
- TSC ⚡️ Build success in 8171ms
10
- DTS Build start
11
- CLI Target: es2022
12
- Analysis will use the bundled TypeScript version 5.8.3
13
- Writing package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.ts
14
- Analysis will use the bundled TypeScript version 5.8.3
15
- Writing package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 11935ms
17
- CLI Cleaning output folder
18
- ESM Build start
19
- CJS Build start
20
- ESM dist/index.js 14.16 KB
21
- ESM ⚡️ Build success in 803ms
22
- CJS dist/index.cjs 14.42 KB
23
- CJS ⚡️ Build success in 807ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @mastra/astra
2
2
 
3
+ ## 0.11.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
8
+ - Updated dependencies [cb36de0]
9
+ - Updated dependencies [d0496e6]
10
+ - Updated dependencies [a82b851]
11
+ - Updated dependencies [ea0c5f2]
12
+ - Updated dependencies [41a0a0e]
13
+ - Updated dependencies [2871020]
14
+ - Updated dependencies [94f4812]
15
+ - Updated dependencies [e202b82]
16
+ - Updated dependencies [e00f6a0]
17
+ - Updated dependencies [4a406ec]
18
+ - Updated dependencies [b0e43c1]
19
+ - Updated dependencies [5d377e5]
20
+ - Updated dependencies [1fb812e]
21
+ - Updated dependencies [35c5798]
22
+ - @mastra/core@0.13.0
23
+
24
+ ## 0.11.3-alpha.0
25
+
26
+ ### Patch Changes
27
+
28
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
29
+ - Updated dependencies [cb36de0]
30
+ - Updated dependencies [a82b851]
31
+ - Updated dependencies [41a0a0e]
32
+ - Updated dependencies [2871020]
33
+ - Updated dependencies [4a406ec]
34
+ - Updated dependencies [5d377e5]
35
+ - @mastra/core@0.13.0-alpha.2
36
+
3
37
  ## 0.11.2
4
38
 
5
39
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -414,3 +414,5 @@ Example Complex Query:
414
414
 
415
415
  exports.ASTRA_PROMPT = ASTRA_PROMPT;
416
416
  exports.AstraVector = AstraVector;
417
+ //# sourceMappingURL=index.cjs.map
418
+ //# 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","DataAPIClient","MastraError","ErrorDomain","ErrorCategory","error","UUID"],"mappings":";;;;;;;;AA8BO,IAAM,qBAAA,GAAN,cAAoCA,2BAAA,CAAwC;AAAA,EAC9D,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAGA,2BAAA,CAAqB,iBAAA;AAAA,MACxB,KAAA,EAAO,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAM,CAAA;AAAA,MAC7B,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAM,CAAA;AAAA,MAC/B,OAAO,EAAC;AAAA,MACR,MAAA,EAAQ,CAAC,OAAO;AAAA,KAClB;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAA+C;AACvD,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,EAAG,OAAO,MAAA;AACjC,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UACxB,OAAA,EAAS,EAAE,SAAA,EAAW,EAAA;AAAG,SAC3B;AAAA,QACAC;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;AC/TO,IAAM,YAAA,GAAe,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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.cjs","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype AstraOperatorValueMap = Omit<OperatorValueMap, '$elemMatch' | '$regex' | '$options'> & {\n $size: number; // Astra-specific\n};\n\ntype AstraLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;\n\ntype AstraBlacklisted = BlacklistedRootOperators | '$nor' | '$size';\n\nexport type AstraVectorFilter = VectorFilter<\n keyof AstraOperatorValueMap,\n AstraOperatorValueMap,\n AstraLogicalOperatorValueMap,\n AstraBlacklisted\n>;\n\n/**\n * Translator for Astra DB filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class AstraFilterTranslator extends BaseFilterTranslator<AstraVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n array: ['$all', '$in', '$nin'],\n logical: ['$and', '$or', '$not'],\n regex: [],\n custom: ['$size'],\n };\n }\n\n translate(filter?: AstraVectorFilter): AstraVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: AstraVectorFilter): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is not supported in Astra DB');\n }\n if (this.isPrimitive(node) || Array.isArray(node)) {\n return node;\n }\n\n const entries = Object.entries(node as Record<string, any>);\n const translatedEntries = entries.map(([key, value]) => {\n // Handle operators\n if (this.isOperator(key)) {\n return [key, this.translateOperatorValue(key, value)];\n }\n\n // Handle nested paths and objects\n return [key, this.translateNode(value)];\n });\n\n return Object.fromEntries(translatedEntries);\n }\n\n private translateOperatorValue(operator: QueryOperator, value: any): any {\n if (this.isBasicOperator(operator) || this.isNumericOperator(operator)) {\n return this.normalizeComparisonValue(value);\n }\n\n if (this.isArrayOperator(operator) && Array.isArray(value)) {\n return this.normalizeArrayValues(value);\n }\n\n return this.translateNode(value);\n }\n}\n","import type { Db } from '@datastax/astra-db-ts';\nimport { DataAPIClient, UUID } from '@datastax/astra-db-ts';\nimport { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport type { AstraVectorFilter } from './filter';\nimport { AstraFilterTranslator } from './filter';\n\n// Mastra and Astra DB agree on cosine and euclidean, but Astra DB uses dot_product instead of dotproduct.\nconst metricMap = {\n cosine: 'cosine',\n euclidean: 'euclidean',\n dotproduct: 'dot_product',\n} as const;\n\nexport interface AstraDbOptions {\n token: string;\n endpoint: string;\n keyspace?: string;\n}\n\ntype AstraQueryVectorParams = QueryVectorParams<AstraVectorFilter>;\n\nexport class AstraVector extends MastraVector<AstraVectorFilter> {\n readonly #db: Db;\n\n constructor({ token, endpoint, keyspace }: AstraDbOptions) {\n super();\n const client = new DataAPIClient(token);\n this.#db = client.db(endpoint, { keyspace });\n }\n\n /**\n * Creates a new collection with the specified configuration.\n *\n * @param {string} indexName - The name of the collection to create.\n * @param {number} dimension - The dimension of the vectors to be stored in the collection.\n * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.\n * @returns {Promise<void>} A promise that resolves when the collection is created.\n */\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: 'ASTRA_VECTOR_CREATE_INDEX_INVALID_DIMENSION',\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n });\n }\n try {\n await this.#db.createCollection(indexName, {\n vector: {\n dimension,\n metric: metricMap[metric],\n },\n checkExists: false,\n });\n } catch (error: any) {\n new MastraError(\n {\n id: 'ASTRA_VECTOR_CREATE_INDEX_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Inserts or updates vectors in the specified collection.\n *\n * @param {string} indexName - The name of the collection to upsert into.\n * @param {number[][]} vectors - An array of vectors to upsert.\n * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.\n * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.\n * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.\n */\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const collection = this.#db.collection(indexName);\n\n // Generate IDs if not provided\n const vectorIds = ids || vectors.map(() => UUID.v7().toString());\n\n const records = vectors.map((vector, i) => ({\n id: vectorIds[i],\n $vector: vector,\n metadata: metadata?.[i] || {},\n }));\n\n try {\n await collection.insertMany(records);\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_UPSERT_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n return vectorIds;\n }\n\n transformFilter(filter?: AstraVectorFilter) {\n const translator = new AstraFilterTranslator();\n return translator.translate(filter);\n }\n\n /**\n * Queries the specified collection using a vector and optional filter.\n *\n * @param {string} indexName - The name of the collection to query.\n * @param {number[]} queryVector - The vector to query with.\n * @param {number} [topK] - The maximum number of results to return.\n * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators\n * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.\n * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.\n */\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: AstraQueryVectorParams): Promise<QueryResult[]> {\n const collection = this.#db.collection(indexName);\n\n const translatedFilter = this.transformFilter(filter);\n\n try {\n const cursor = collection.find(translatedFilter ?? {}, {\n sort: { $vector: queryVector },\n limit: topK,\n includeSimilarity: true,\n projection: {\n $vector: includeVector ? true : false,\n },\n });\n\n const results = await cursor.toArray();\n\n return results.map(result => ({\n id: result.id,\n score: result.$similarity,\n metadata: result.metadata,\n ...(includeVector && { vector: result.$vector }),\n }));\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_QUERY_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Lists all collections in the database.\n *\n * @returns {Promise<string[]>} A promise that resolves to an array of collection names.\n */\n async listIndexes(): Promise<string[]> {\n try {\n return await this.#db.listCollections({ nameOnly: true });\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_LIST_INDEXES_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\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 const collection = this.#db.collection(indexName);\n try {\n const optionsPromise = collection.options();\n const countPromise = collection.countDocuments({}, 100);\n const [options, count] = await Promise.all([optionsPromise, countPromise]);\n\n const keys = Object.keys(metricMap) as (keyof typeof metricMap)[];\n const metric = keys.find(key => metricMap[key] === options.vector?.metric);\n return {\n dimension: options.vector?.dimension!,\n metric,\n count: count,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_DESCRIBE_INDEX_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes the specified collection.\n *\n * @param {string} indexName - The name of the collection to delete.\n * @returns {Promise<void>} A promise that resolves when the collection is deleted.\n */\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n const collection = this.#db.collection(indexName);\n try {\n await collection.drop();\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_DELETE_INDEX_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\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: 'ASTRA_VECTOR_UPDATE_NO_PAYLOAD',\n text: 'No updates provided for vector',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName, id },\n });\n }\n\n try {\n const collection = this.#db.collection(indexName);\n const updateDoc: Record<string, any> = {};\n\n if (update.vector) {\n updateDoc.$vector = update.vector;\n }\n\n if (update.metadata) {\n updateDoc.metadata = update.metadata;\n }\n\n await collection.findOneAndUpdate({ id }, { $set: updateDoc });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_UPDATE_FAILED_UNHANDLED',\n domain: ErrorDomain.MASTRA_VECTOR,\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 const collection = this.#db.collection(indexName);\n await collection.deleteOne({ id });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_DELETE_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\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 Astra Vector.\n */\nexport const ASTRA_PROMPT = `When querying Astra, 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Only logical operators ($and, $or, $not) can be used at the top level\n- All other 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- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other 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 { \"tags\": { \"$all\": [\"premium\"] } },\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,3 +1,3 @@
1
- export { ASTRA_PROMPT } from './_tsup-dts-rollup.js';
2
- export { AstraDbOptions } from './_tsup-dts-rollup.js';
3
- export { AstraVector } from './_tsup-dts-rollup.js';
1
+ export * from './vector/index.js';
2
+ export { ASTRA_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,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -411,3 +411,5 @@ Example Complex Query:
411
411
  }`;
412
412
 
413
413
  export { ASTRA_PROMPT, AstraVector };
414
+ //# sourceMappingURL=index.js.map
415
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"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AAA,EASA,MAAM,YAAA,CAAa,EAAE,SAAA,EAAW,IAAG,EAAsC;AACvE,IAAA,IAAI;AACF,MAAA,MAAM,UAAA,GAAa,IAAA,CAAK,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA;AAChD,MAAA,MAAM,UAAA,CAAW,SAAA,CAAU,EAAE,EAAA,EAAI,CAAA;AAAA,IACnC,SAAS,KAAA,EAAY;AACnB,MAAA,IAAI,KAAA,YAAiB,aAAa,MAAM,KAAA;AACxC,MAAA,MAAM,IAAI,WAAA;AAAA,QACR;AAAA,UACE,EAAA,EAAI,4BAAA;AAAA,UACJ,QAAQ,WAAA,CAAY,aAAA;AAAA,UACpB,UAAU,aAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS,EAAE,SAAA,EAAW,EAAA;AAAG,SAC3B;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;AC/TO,IAAM,YAAA,GAAe,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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 QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype AstraOperatorValueMap = Omit<OperatorValueMap, '$elemMatch' | '$regex' | '$options'> & {\n $size: number; // Astra-specific\n};\n\ntype AstraLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;\n\ntype AstraBlacklisted = BlacklistedRootOperators | '$nor' | '$size';\n\nexport type AstraVectorFilter = VectorFilter<\n keyof AstraOperatorValueMap,\n AstraOperatorValueMap,\n AstraLogicalOperatorValueMap,\n AstraBlacklisted\n>;\n\n/**\n * Translator for Astra DB filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class AstraFilterTranslator extends BaseFilterTranslator<AstraVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n array: ['$all', '$in', '$nin'],\n logical: ['$and', '$or', '$not'],\n regex: [],\n custom: ['$size'],\n };\n }\n\n translate(filter?: AstraVectorFilter): AstraVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: AstraVectorFilter): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is not supported in Astra DB');\n }\n if (this.isPrimitive(node) || Array.isArray(node)) {\n return node;\n }\n\n const entries = Object.entries(node as Record<string, any>);\n const translatedEntries = entries.map(([key, value]) => {\n // Handle operators\n if (this.isOperator(key)) {\n return [key, this.translateOperatorValue(key, value)];\n }\n\n // Handle nested paths and objects\n return [key, this.translateNode(value)];\n });\n\n return Object.fromEntries(translatedEntries);\n }\n\n private translateOperatorValue(operator: QueryOperator, value: any): any {\n if (this.isBasicOperator(operator) || this.isNumericOperator(operator)) {\n return this.normalizeComparisonValue(value);\n }\n\n if (this.isArrayOperator(operator) && Array.isArray(value)) {\n return this.normalizeArrayValues(value);\n }\n\n return this.translateNode(value);\n }\n}\n","import type { Db } from '@datastax/astra-db-ts';\nimport { DataAPIClient, UUID } from '@datastax/astra-db-ts';\nimport { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport type { AstraVectorFilter } from './filter';\nimport { AstraFilterTranslator } from './filter';\n\n// Mastra and Astra DB agree on cosine and euclidean, but Astra DB uses dot_product instead of dotproduct.\nconst metricMap = {\n cosine: 'cosine',\n euclidean: 'euclidean',\n dotproduct: 'dot_product',\n} as const;\n\nexport interface AstraDbOptions {\n token: string;\n endpoint: string;\n keyspace?: string;\n}\n\ntype AstraQueryVectorParams = QueryVectorParams<AstraVectorFilter>;\n\nexport class AstraVector extends MastraVector<AstraVectorFilter> {\n readonly #db: Db;\n\n constructor({ token, endpoint, keyspace }: AstraDbOptions) {\n super();\n const client = new DataAPIClient(token);\n this.#db = client.db(endpoint, { keyspace });\n }\n\n /**\n * Creates a new collection with the specified configuration.\n *\n * @param {string} indexName - The name of the collection to create.\n * @param {number} dimension - The dimension of the vectors to be stored in the collection.\n * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.\n * @returns {Promise<void>} A promise that resolves when the collection is created.\n */\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: 'ASTRA_VECTOR_CREATE_INDEX_INVALID_DIMENSION',\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n });\n }\n try {\n await this.#db.createCollection(indexName, {\n vector: {\n dimension,\n metric: metricMap[metric],\n },\n checkExists: false,\n });\n } catch (error: any) {\n new MastraError(\n {\n id: 'ASTRA_VECTOR_CREATE_INDEX_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Inserts or updates vectors in the specified collection.\n *\n * @param {string} indexName - The name of the collection to upsert into.\n * @param {number[][]} vectors - An array of vectors to upsert.\n * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.\n * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.\n * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.\n */\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const collection = this.#db.collection(indexName);\n\n // Generate IDs if not provided\n const vectorIds = ids || vectors.map(() => UUID.v7().toString());\n\n const records = vectors.map((vector, i) => ({\n id: vectorIds[i],\n $vector: vector,\n metadata: metadata?.[i] || {},\n }));\n\n try {\n await collection.insertMany(records);\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_UPSERT_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n return vectorIds;\n }\n\n transformFilter(filter?: AstraVectorFilter) {\n const translator = new AstraFilterTranslator();\n return translator.translate(filter);\n }\n\n /**\n * Queries the specified collection using a vector and optional filter.\n *\n * @param {string} indexName - The name of the collection to query.\n * @param {number[]} queryVector - The vector to query with.\n * @param {number} [topK] - The maximum number of results to return.\n * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators\n * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.\n * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.\n */\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: AstraQueryVectorParams): Promise<QueryResult[]> {\n const collection = this.#db.collection(indexName);\n\n const translatedFilter = this.transformFilter(filter);\n\n try {\n const cursor = collection.find(translatedFilter ?? {}, {\n sort: { $vector: queryVector },\n limit: topK,\n includeSimilarity: true,\n projection: {\n $vector: includeVector ? true : false,\n },\n });\n\n const results = await cursor.toArray();\n\n return results.map(result => ({\n id: result.id,\n score: result.$similarity,\n metadata: result.metadata,\n ...(includeVector && { vector: result.$vector }),\n }));\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_QUERY_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Lists all collections in the database.\n *\n * @returns {Promise<string[]>} A promise that resolves to an array of collection names.\n */\n async listIndexes(): Promise<string[]> {\n try {\n return await this.#db.listCollections({ nameOnly: true });\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_LIST_INDEXES_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\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 const collection = this.#db.collection(indexName);\n try {\n const optionsPromise = collection.options();\n const countPromise = collection.countDocuments({}, 100);\n const [options, count] = await Promise.all([optionsPromise, countPromise]);\n\n const keys = Object.keys(metricMap) as (keyof typeof metricMap)[];\n const metric = keys.find(key => metricMap[key] === options.vector?.metric);\n return {\n dimension: options.vector?.dimension!,\n metric,\n count: count,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_DESCRIBE_INDEX_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes the specified collection.\n *\n * @param {string} indexName - The name of the collection to delete.\n * @returns {Promise<void>} A promise that resolves when the collection is deleted.\n */\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n const collection = this.#db.collection(indexName);\n try {\n await collection.drop();\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_DELETE_INDEX_DB_ERROR',\n domain: ErrorDomain.MASTRA_VECTOR,\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: 'ASTRA_VECTOR_UPDATE_NO_PAYLOAD',\n text: 'No updates provided for vector',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName, id },\n });\n }\n\n try {\n const collection = this.#db.collection(indexName);\n const updateDoc: Record<string, any> = {};\n\n if (update.vector) {\n updateDoc.$vector = update.vector;\n }\n\n if (update.metadata) {\n updateDoc.metadata = update.metadata;\n }\n\n await collection.findOneAndUpdate({ id }, { $set: updateDoc });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_UPDATE_FAILED_UNHANDLED',\n domain: ErrorDomain.MASTRA_VECTOR,\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 const collection = this.#db.collection(indexName);\n await collection.deleteOne({ id });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'ASTRA_VECTOR_DELETE_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\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 Astra Vector.\n */\nexport const ASTRA_PROMPT = `When querying Astra, 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Only logical operators ($and, $or, $not) can be used at the top level\n- All other 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- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other 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 { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"]}
@@ -0,0 +1,21 @@
1
+ import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { VectorFilter, OperatorSupport, OperatorValueMap, LogicalOperatorValueMap, BlacklistedRootOperators } from '@mastra/core/vector/filter';
3
+ type AstraOperatorValueMap = Omit<OperatorValueMap, '$elemMatch' | '$regex' | '$options'> & {
4
+ $size: number;
5
+ };
6
+ type AstraLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
7
+ type AstraBlacklisted = BlacklistedRootOperators | '$nor' | '$size';
8
+ export type AstraVectorFilter = VectorFilter<keyof AstraOperatorValueMap, AstraOperatorValueMap, AstraLogicalOperatorValueMap, AstraBlacklisted>;
9
+ /**
10
+ * Translator for Astra DB filter queries.
11
+ * Maintains MongoDB-compatible syntax while ensuring proper validation
12
+ * and normalization of values.
13
+ */
14
+ export declare class AstraFilterTranslator extends BaseFilterTranslator<AstraVectorFilter> {
15
+ protected getSupportedOperators(): OperatorSupport;
16
+ translate(filter?: AstraVectorFilter): AstraVectorFilter;
17
+ private translateNode;
18
+ private translateOperatorValue;
19
+ }
20
+ export {};
21
+ //# 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,EAEf,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,KAAK,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAC,GAAG;IAC1F,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,4BAA4B,GAAG,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AAE1E,KAAK,gBAAgB,GAAG,wBAAwB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpE,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAC1C,MAAM,qBAAqB,EAC3B,qBAAqB,EACrB,4BAA4B,EAC5B,gBAAgB,CACjB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;cAC7D,qBAAqB,IAAI,eAAe;IAU3D,SAAS,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,iBAAiB;IAOxD,OAAO,CAAC,aAAa;IAuBrB,OAAO,CAAC,sBAAsB;CAW/B"}
@@ -0,0 +1,85 @@
1
+ import { MastraVector } from '@mastra/core/vector';
2
+ import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
3
+ import type { AstraVectorFilter } from './filter.js';
4
+ export interface AstraDbOptions {
5
+ token: string;
6
+ endpoint: string;
7
+ keyspace?: string;
8
+ }
9
+ type AstraQueryVectorParams = QueryVectorParams<AstraVectorFilter>;
10
+ export declare class AstraVector extends MastraVector<AstraVectorFilter> {
11
+ #private;
12
+ constructor({ token, endpoint, keyspace }: AstraDbOptions);
13
+ /**
14
+ * Creates a new collection with the specified configuration.
15
+ *
16
+ * @param {string} indexName - The name of the collection to create.
17
+ * @param {number} dimension - The dimension of the vectors to be stored in the collection.
18
+ * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
19
+ * @returns {Promise<void>} A promise that resolves when the collection is created.
20
+ */
21
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
22
+ /**
23
+ * Inserts or updates vectors in the specified collection.
24
+ *
25
+ * @param {string} indexName - The name of the collection to upsert into.
26
+ * @param {number[][]} vectors - An array of vectors to upsert.
27
+ * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
28
+ * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
29
+ * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
30
+ */
31
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
32
+ transformFilter(filter?: AstraVectorFilter): AstraVectorFilter;
33
+ /**
34
+ * Queries the specified collection using a vector and optional filter.
35
+ *
36
+ * @param {string} indexName - The name of the collection to query.
37
+ * @param {number[]} queryVector - The vector to query with.
38
+ * @param {number} [topK] - The maximum number of results to return.
39
+ * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators
40
+ * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
41
+ * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
42
+ */
43
+ query({ indexName, queryVector, topK, filter, includeVector, }: AstraQueryVectorParams): Promise<QueryResult[]>;
44
+ /**
45
+ * Lists all collections in the database.
46
+ *
47
+ * @returns {Promise<string[]>} A promise that resolves to an array of collection names.
48
+ */
49
+ listIndexes(): Promise<string[]>;
50
+ /**
51
+ * Retrieves statistics about a vector index.
52
+ *
53
+ * @param {string} indexName - The name of the index to describe
54
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
55
+ */
56
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
57
+ /**
58
+ * Deletes the specified collection.
59
+ *
60
+ * @param {string} indexName - The name of the collection to delete.
61
+ * @returns {Promise<void>} A promise that resolves when the collection is deleted.
62
+ */
63
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
64
+ /**
65
+ * Updates a vector by its ID with the provided vector and/or metadata.
66
+ * @param indexName - The name of the index containing the vector.
67
+ * @param id - The ID of the vector to update.
68
+ * @param update - An object containing the vector and/or metadata to update.
69
+ * @param update.vector - An optional array of numbers representing the new vector.
70
+ * @param update.metadata - An optional record containing the new metadata.
71
+ * @returns A promise that resolves when the update is complete.
72
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
73
+ */
74
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
75
+ /**
76
+ * Deletes a vector by its ID.
77
+ * @param indexName - The name of the index containing the vector.
78
+ * @param id - The ID of the vector to delete.
79
+ * @returns A promise that resolves when the deletion is complete.
80
+ * @throws Will throw an error if the deletion operation fails.
81
+ */
82
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAUlD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,sBAAsB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AAEnE,qBAAa,WAAY,SAAQ,YAAY,CAAC,iBAAiB,CAAC;;gBAGlD,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,cAAc;IAMzD;;;;;;;OAOG;IACG,WAAW,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,MAAiB,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BhG;;;;;;;;OAQG;IACG,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA4B1F,eAAe,CAAC,MAAM,CAAC,EAAE,iBAAiB;IAK1C;;;;;;;;;OASG;IACG,KAAK,CAAC,EACV,SAAS,EACT,WAAW,EACX,IAAS,EACT,MAAM,EACN,aAAqB,GACtB,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAoClD;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAetC;;;;;OAKG;IACG,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IA4B5E;;;;;OAKG;IACG,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlE;;;;;;;;;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;CAiBzE"}
@@ -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 Astra Vector.
4
+ */
5
+ export declare const ASTRA_PROMPT = "When querying Astra, 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Only logical operators ($and, $or, $not) can be used at the top level\n- All other 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- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other 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 { \"tags\": { \"$all\": [\"premium\"] } },\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,YAAY,0sHAsFvB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/astra",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "Astra DB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "default": "./dist/index.js"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/index.d.cts",
15
+ "types": "./dist/index.d.ts",
16
16
  "default": "./dist/index.cjs"
17
17
  }
18
18
  },
@@ -29,15 +29,16 @@
29
29
  "tsup": "^8.5.0",
30
30
  "typescript": "^5.8.3",
31
31
  "vitest": "^3.2.4",
32
- "@internal/lint": "0.0.24",
33
- "@mastra/core": "0.12.0"
32
+ "@internal/lint": "0.0.27",
33
+ "@internal/types-builder": "0.0.2",
34
+ "@mastra/core": "0.13.0"
34
35
  },
35
36
  "peerDependencies": {
36
- "@mastra/core": ">=0.10.7-0 <0.13.0-0"
37
+ "@mastra/core": ">=0.10.7-0 <0.14.0-0"
37
38
  },
38
39
  "scripts": {
39
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
40
- "build:watch": "pnpm build --watch",
40
+ "build": "tsup --silent --config tsup.config.ts",
41
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
41
42
  "test": "vitest run",
42
43
  "lint": "eslint ."
43
44
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { generateTypes } from '@internal/types-builder';
2
+ import { defineConfig } from 'tsup';
3
+
4
+ export default defineConfig({
5
+ entry: ['src/index.ts'],
6
+ format: ['esm', 'cjs'],
7
+ clean: true,
8
+ dts: false,
9
+ splitting: true,
10
+ treeshake: {
11
+ preset: 'smallest',
12
+ },
13
+ sourcemap: true,
14
+ onSuccess: async () => {
15
+ await generateTypes(process.cwd());
16
+ },
17
+ });
@@ -1,135 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
3
- import type { CreateIndexParams } from '@mastra/core/vector';
4
- import type { DeleteIndexParams } from '@mastra/core/vector';
5
- import type { DeleteVectorParams } from '@mastra/core/vector';
6
- import type { DescribeIndexParams } from '@mastra/core/vector';
7
- import type { IndexStats } from '@mastra/core/vector';
8
- import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
9
- import { MastraVector } from '@mastra/core/vector';
10
- import type { OperatorSupport } from '@mastra/core/vector/filter';
11
- import type { OperatorValueMap } from '@mastra/core/vector/filter';
12
- import type { QueryResult } from '@mastra/core/vector';
13
- import type { QueryVectorParams } from '@mastra/core/vector';
14
- import type { UpdateVectorParams } from '@mastra/core/vector';
15
- import type { UpsertVectorParams } from '@mastra/core/vector';
16
- import type { VectorFilter } from '@mastra/core/vector/filter';
17
-
18
- /**
19
- * Vector store specific prompt that details supported operators and examples.
20
- * This prompt helps users construct valid filters for Astra Vector.
21
- */
22
- declare const ASTRA_PROMPT = "When querying Astra, 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Only logical operators ($and, $or, $not) can be used at the top level\n- All other 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- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other 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 { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
23
- export { ASTRA_PROMPT }
24
- export { ASTRA_PROMPT as ASTRA_PROMPT_alias_1 }
25
-
26
- declare type AstraBlacklisted = BlacklistedRootOperators | '$nor' | '$size';
27
-
28
- declare interface AstraDbOptions {
29
- token: string;
30
- endpoint: string;
31
- keyspace?: string;
32
- }
33
- export { AstraDbOptions }
34
- export { AstraDbOptions as AstraDbOptions_alias_1 }
35
-
36
- /**
37
- * Translator for Astra DB filter queries.
38
- * Maintains MongoDB-compatible syntax while ensuring proper validation
39
- * and normalization of values.
40
- */
41
- export declare class AstraFilterTranslator extends BaseFilterTranslator<AstraVectorFilter> {
42
- protected getSupportedOperators(): OperatorSupport;
43
- translate(filter?: AstraVectorFilter): AstraVectorFilter;
44
- private translateNode;
45
- private translateOperatorValue;
46
- }
47
-
48
- declare type AstraLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
49
-
50
- declare type AstraOperatorValueMap = Omit<OperatorValueMap, '$elemMatch' | '$regex' | '$options'> & {
51
- $size: number;
52
- };
53
-
54
- declare type AstraQueryVectorParams = QueryVectorParams<AstraVectorFilter>;
55
-
56
- declare class AstraVector extends MastraVector<AstraVectorFilter> {
57
- #private;
58
- constructor({ token, endpoint, keyspace }: AstraDbOptions);
59
- /**
60
- * Creates a new collection with the specified configuration.
61
- *
62
- * @param {string} indexName - The name of the collection to create.
63
- * @param {number} dimension - The dimension of the vectors to be stored in the collection.
64
- * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
65
- * @returns {Promise<void>} A promise that resolves when the collection is created.
66
- */
67
- createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
68
- /**
69
- * Inserts or updates vectors in the specified collection.
70
- *
71
- * @param {string} indexName - The name of the collection to upsert into.
72
- * @param {number[][]} vectors - An array of vectors to upsert.
73
- * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
74
- * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
75
- * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
76
- */
77
- upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
78
- transformFilter(filter?: AstraVectorFilter): AstraVectorFilter;
79
- /**
80
- * Queries the specified collection using a vector and optional filter.
81
- *
82
- * @param {string} indexName - The name of the collection to query.
83
- * @param {number[]} queryVector - The vector to query with.
84
- * @param {number} [topK] - The maximum number of results to return.
85
- * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators
86
- * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
87
- * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
88
- */
89
- query({ indexName, queryVector, topK, filter, includeVector, }: AstraQueryVectorParams): Promise<QueryResult[]>;
90
- /**
91
- * Lists all collections in the database.
92
- *
93
- * @returns {Promise<string[]>} A promise that resolves to an array of collection names.
94
- */
95
- listIndexes(): Promise<string[]>;
96
- /**
97
- * Retrieves statistics about a vector index.
98
- *
99
- * @param {string} indexName - The name of the index to describe
100
- * @returns A promise that resolves to the index statistics including dimension, count and metric
101
- */
102
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
103
- /**
104
- * Deletes the specified collection.
105
- *
106
- * @param {string} indexName - The name of the collection to delete.
107
- * @returns {Promise<void>} A promise that resolves when the collection is deleted.
108
- */
109
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
110
- /**
111
- * Updates a vector by its ID with the provided vector and/or metadata.
112
- * @param indexName - The name of the index containing the vector.
113
- * @param id - The ID of the vector to update.
114
- * @param update - An object containing the vector and/or metadata to update.
115
- * @param update.vector - An optional array of numbers representing the new vector.
116
- * @param update.metadata - An optional record containing the new metadata.
117
- * @returns A promise that resolves when the update is complete.
118
- * @throws Will throw an error if no updates are provided or if the update operation fails.
119
- */
120
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
121
- /**
122
- * Deletes a vector by its ID.
123
- * @param indexName - The name of the index containing the vector.
124
- * @param id - The ID of the vector to delete.
125
- * @returns A promise that resolves when the deletion is complete.
126
- * @throws Will throw an error if the deletion operation fails.
127
- */
128
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
129
- }
130
- export { AstraVector }
131
- export { AstraVector as AstraVector_alias_1 }
132
-
133
- export declare type AstraVectorFilter = VectorFilter<keyof AstraOperatorValueMap, AstraOperatorValueMap, AstraLogicalOperatorValueMap, AstraBlacklisted>;
134
-
135
- export { }
@@ -1,135 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
3
- import type { CreateIndexParams } from '@mastra/core/vector';
4
- import type { DeleteIndexParams } from '@mastra/core/vector';
5
- import type { DeleteVectorParams } from '@mastra/core/vector';
6
- import type { DescribeIndexParams } from '@mastra/core/vector';
7
- import type { IndexStats } from '@mastra/core/vector';
8
- import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
9
- import { MastraVector } from '@mastra/core/vector';
10
- import type { OperatorSupport } from '@mastra/core/vector/filter';
11
- import type { OperatorValueMap } from '@mastra/core/vector/filter';
12
- import type { QueryResult } from '@mastra/core/vector';
13
- import type { QueryVectorParams } from '@mastra/core/vector';
14
- import type { UpdateVectorParams } from '@mastra/core/vector';
15
- import type { UpsertVectorParams } from '@mastra/core/vector';
16
- import type { VectorFilter } from '@mastra/core/vector/filter';
17
-
18
- /**
19
- * Vector store specific prompt that details supported operators and examples.
20
- * This prompt helps users construct valid filters for Astra Vector.
21
- */
22
- declare const ASTRA_PROMPT = "When querying Astra, 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Only logical operators ($and, $or, $not) can be used at the top level\n- All other 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- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other 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 { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
23
- export { ASTRA_PROMPT }
24
- export { ASTRA_PROMPT as ASTRA_PROMPT_alias_1 }
25
-
26
- declare type AstraBlacklisted = BlacklistedRootOperators | '$nor' | '$size';
27
-
28
- declare interface AstraDbOptions {
29
- token: string;
30
- endpoint: string;
31
- keyspace?: string;
32
- }
33
- export { AstraDbOptions }
34
- export { AstraDbOptions as AstraDbOptions_alias_1 }
35
-
36
- /**
37
- * Translator for Astra DB filter queries.
38
- * Maintains MongoDB-compatible syntax while ensuring proper validation
39
- * and normalization of values.
40
- */
41
- export declare class AstraFilterTranslator extends BaseFilterTranslator<AstraVectorFilter> {
42
- protected getSupportedOperators(): OperatorSupport;
43
- translate(filter?: AstraVectorFilter): AstraVectorFilter;
44
- private translateNode;
45
- private translateOperatorValue;
46
- }
47
-
48
- declare type AstraLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
49
-
50
- declare type AstraOperatorValueMap = Omit<OperatorValueMap, '$elemMatch' | '$regex' | '$options'> & {
51
- $size: number;
52
- };
53
-
54
- declare type AstraQueryVectorParams = QueryVectorParams<AstraVectorFilter>;
55
-
56
- declare class AstraVector extends MastraVector<AstraVectorFilter> {
57
- #private;
58
- constructor({ token, endpoint, keyspace }: AstraDbOptions);
59
- /**
60
- * Creates a new collection with the specified configuration.
61
- *
62
- * @param {string} indexName - The name of the collection to create.
63
- * @param {number} dimension - The dimension of the vectors to be stored in the collection.
64
- * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
65
- * @returns {Promise<void>} A promise that resolves when the collection is created.
66
- */
67
- createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
68
- /**
69
- * Inserts or updates vectors in the specified collection.
70
- *
71
- * @param {string} indexName - The name of the collection to upsert into.
72
- * @param {number[][]} vectors - An array of vectors to upsert.
73
- * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
74
- * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
75
- * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
76
- */
77
- upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
78
- transformFilter(filter?: AstraVectorFilter): AstraVectorFilter;
79
- /**
80
- * Queries the specified collection using a vector and optional filter.
81
- *
82
- * @param {string} indexName - The name of the collection to query.
83
- * @param {number[]} queryVector - The vector to query with.
84
- * @param {number} [topK] - The maximum number of results to return.
85
- * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators
86
- * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
87
- * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
88
- */
89
- query({ indexName, queryVector, topK, filter, includeVector, }: AstraQueryVectorParams): Promise<QueryResult[]>;
90
- /**
91
- * Lists all collections in the database.
92
- *
93
- * @returns {Promise<string[]>} A promise that resolves to an array of collection names.
94
- */
95
- listIndexes(): Promise<string[]>;
96
- /**
97
- * Retrieves statistics about a vector index.
98
- *
99
- * @param {string} indexName - The name of the index to describe
100
- * @returns A promise that resolves to the index statistics including dimension, count and metric
101
- */
102
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
103
- /**
104
- * Deletes the specified collection.
105
- *
106
- * @param {string} indexName - The name of the collection to delete.
107
- * @returns {Promise<void>} A promise that resolves when the collection is deleted.
108
- */
109
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
110
- /**
111
- * Updates a vector by its ID with the provided vector and/or metadata.
112
- * @param indexName - The name of the index containing the vector.
113
- * @param id - The ID of the vector to update.
114
- * @param update - An object containing the vector and/or metadata to update.
115
- * @param update.vector - An optional array of numbers representing the new vector.
116
- * @param update.metadata - An optional record containing the new metadata.
117
- * @returns A promise that resolves when the update is complete.
118
- * @throws Will throw an error if no updates are provided or if the update operation fails.
119
- */
120
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
121
- /**
122
- * Deletes a vector by its ID.
123
- * @param indexName - The name of the index containing the vector.
124
- * @param id - The ID of the vector to delete.
125
- * @returns A promise that resolves when the deletion is complete.
126
- * @throws Will throw an error if the deletion operation fails.
127
- */
128
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
129
- }
130
- export { AstraVector }
131
- export { AstraVector as AstraVector_alias_1 }
132
-
133
- export declare type AstraVectorFilter = VectorFilter<keyof AstraOperatorValueMap, AstraOperatorValueMap, AstraLogicalOperatorValueMap, AstraBlacklisted>;
134
-
135
- export { }
package/dist/index.d.cts DELETED
@@ -1,3 +0,0 @@
1
- export { ASTRA_PROMPT } from './_tsup-dts-rollup.cjs';
2
- export { AstraDbOptions } from './_tsup-dts-rollup.cjs';
3
- export { AstraVector } from './_tsup-dts-rollup.cjs';