@mastra/rag 2.0.0-beta.3 → 2.0.0-beta.5
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/CHANGELOG.md +45 -0
- package/dist/docs/README.md +32 -0
- package/dist/docs/SKILL.md +33 -0
- package/dist/docs/SOURCE_MAP.json +6 -0
- package/dist/docs/rag/01-overview.md +74 -0
- package/dist/docs/rag/02-chunking-and-embedding.md +190 -0
- package/dist/docs/rag/03-retrieval.md +549 -0
- package/dist/docs/rag/04-graph-rag.md +217 -0
- package/dist/docs/rag/05-reference.md +854 -0
- package/dist/docs/tools/01-reference.md +684 -0
- package/dist/document/extractors/keywords.d.ts +2 -2
- package/dist/document/extractors/keywords.d.ts.map +1 -1
- package/dist/document/extractors/questions.d.ts +2 -2
- package/dist/document/extractors/questions.d.ts.map +1 -1
- package/dist/document/extractors/summary.d.ts.map +1 -1
- package/dist/document/extractors/title.d.ts +2 -2
- package/dist/document/extractors/title.d.ts.map +1 -1
- package/dist/document/extractors/types.d.ts +6 -6
- package/dist/document/extractors/types.d.ts.map +1 -1
- package/dist/index.cjs +130 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +132 -61
- package/dist/index.js.map +1 -1
- package/dist/rerank/relevance/mastra-agent/index.d.ts +2 -2
- package/dist/rerank/relevance/mastra-agent/index.d.ts.map +1 -1
- package/dist/tools/graph-rag.d.ts.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/types.d.ts +171 -14
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/vector-query.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/tool-helpers.d.ts +54 -0
- package/dist/utils/tool-helpers.d.ts.map +1 -0
- package/dist/utils/vector-search.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
1
|
+
import type { MastraLanguageModel, MastraLegacyLanguageModel } from '@mastra/core/agent';
|
|
2
2
|
import type { RelevanceScoreProvider } from '@mastra/core/relevance';
|
|
3
3
|
export declare class MastraAgentRelevanceScorer implements RelevanceScoreProvider {
|
|
4
4
|
private agent;
|
|
5
|
-
constructor(name: string, model: MastraLanguageModel);
|
|
5
|
+
constructor(name: string, model: MastraLanguageModel | MastraLegacyLanguageModel);
|
|
6
6
|
getRelevanceScore(query: string, text: string): Promise<number>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/rerank/relevance/mastra-agent/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/rerank/relevance/mastra-agent/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEzF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrE,qBAAa,0BAA2B,YAAW,sBAAsB;IACvE,OAAO,CAAC,KAAK,CAAQ;gBAET,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,yBAAyB;IAkB1E,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CActE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-rag.d.ts","sourceRoot":"","sources":["../../src/tools/graph-rag.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"graph-rag.d.ts","sourceRoot":"","sources":["../../src/tools/graph-rag.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAmB,MAAM,SAAS,CAAC;AAGpE,eAAO,MAAM,kBAAkB,GAAI,SAAS,mBAAmB,KA+HvD,OAAO;;;;;;;;;;;;;;;;;;;;;kCAAqB,GAAG,CACtC,CAAC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './document-chunker.js';
|
|
2
2
|
export * from './graph-rag.js';
|
|
3
3
|
export * from './vector-query.js';
|
|
4
|
+
export type { VectorStoreResolver, VectorStoreResolverContext, VectorQueryToolOptions, GraphRagToolOptions, DatabaseConfig, PineconeConfig, PgVectorConfig, ChromaConfig, } from './types.js';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EACV,mBAAmB,EACnB,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,SAAS,CAAC"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MastraUnion } from '@mastra/core/action';
|
|
2
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { MastraVector, MastraEmbeddingModel, MastraEmbeddingOptions } from '@mastra/core/vector';
|
|
2
4
|
import type { RerankConfig } from '../rerank/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Context passed to dynamic vector store resolver functions.
|
|
7
|
+
* Enables multi-tenant setups where the vector store is selected based on request context.
|
|
8
|
+
*/
|
|
9
|
+
export interface VectorStoreResolverContext {
|
|
10
|
+
/** The request context containing tenant/schema information */
|
|
11
|
+
requestContext?: RequestContext;
|
|
12
|
+
/** The Mastra instance for accessing registered resources */
|
|
13
|
+
mastra?: MastraUnion;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A function that dynamically resolves a vector store based on the execution context.
|
|
17
|
+
* Useful for multi-tenant applications where each tenant has a separate schema/database.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const vectorStoreResolver: VectorStoreResolver = async ({ requestContext }) => {
|
|
22
|
+
* const schemaId = requestContext?.get('schemaId');
|
|
23
|
+
* return new PgVector({
|
|
24
|
+
* connectionString: process.env.DATABASE_URL,
|
|
25
|
+
* schemaName: `tenant_${schemaId}`,
|
|
26
|
+
* });
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type VectorStoreResolver = (context: VectorStoreResolverContext) => MastraVector | Promise<MastraVector>;
|
|
3
31
|
export interface PineconeConfig {
|
|
4
32
|
namespace?: string;
|
|
5
33
|
sparseVector?: {
|
|
@@ -42,38 +70,175 @@ export type DatabaseConfig = {
|
|
|
42
70
|
chroma?: ChromaConfig;
|
|
43
71
|
[key: string]: any;
|
|
44
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* Configuration options for creating a vector query tool.
|
|
75
|
+
*
|
|
76
|
+
* This type uses a discriminated union pattern for vector store configuration,
|
|
77
|
+
* allowing two mutually exclusive approaches:
|
|
78
|
+
*
|
|
79
|
+
* 1. **By name**: Use `vectorStoreName` to reference a vector store registered with Mastra
|
|
80
|
+
* 2. **Direct instance**: Use `vectorStore` to provide a vector store instance or resolver function
|
|
81
|
+
*
|
|
82
|
+
* @example Using a named vector store (registered with Mastra)
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const tool = createVectorQueryTool({
|
|
85
|
+
* vectorStoreName: 'myVectorStore',
|
|
86
|
+
* indexName: 'documents',
|
|
87
|
+
* model: openai.embedding('text-embedding-3-small'),
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Using a direct vector store instance
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const tool = createVectorQueryTool({
|
|
94
|
+
* vectorStore: new PgVector({ connectionString: '...' }),
|
|
95
|
+
* indexName: 'documents',
|
|
96
|
+
* model: openai.embedding('text-embedding-3-small'),
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example With filtering and reranking enabled
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const tool = createVectorQueryTool({
|
|
103
|
+
* vectorStoreName: 'myVectorStore',
|
|
104
|
+
* indexName: 'documents',
|
|
105
|
+
* model: openai.embedding('text-embedding-3-small'),
|
|
106
|
+
* enableFilter: true,
|
|
107
|
+
* reranker: {
|
|
108
|
+
* model: cohere.rerank('rerank-v3.5'),
|
|
109
|
+
* options: { topK: 5 },
|
|
110
|
+
* },
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
45
114
|
export type VectorQueryToolOptions = {
|
|
115
|
+
/** Custom tool ID. Defaults to `VectorQuery {storeName} {indexName} Tool` */
|
|
46
116
|
id?: string;
|
|
117
|
+
/** Custom tool description for the LLM */
|
|
47
118
|
description?: string;
|
|
119
|
+
/** Name of the index to query within the vector store */
|
|
48
120
|
indexName: string;
|
|
121
|
+
/** Embedding model used to convert query text into vectors */
|
|
49
122
|
model: MastraEmbeddingModel<string>;
|
|
123
|
+
/** When true, enables metadata filtering in queries. Adds a `filter` input to the tool schema */
|
|
50
124
|
enableFilter?: boolean;
|
|
125
|
+
/** When true, includes vector embeddings in the results. Defaults to false */
|
|
51
126
|
includeVectors?: boolean;
|
|
127
|
+
/** When true, includes source documents in the response. Defaults to true */
|
|
52
128
|
includeSources?: boolean;
|
|
129
|
+
/** Optional reranker configuration to improve result relevance */
|
|
53
130
|
reranker?: RerankConfig;
|
|
54
131
|
/** Database-specific configuration options */
|
|
55
132
|
databaseConfig?: DatabaseConfig;
|
|
56
133
|
} & ProviderOptions & ({
|
|
134
|
+
/** Name of a vector store registered with Mastra */
|
|
57
135
|
vectorStoreName: string;
|
|
58
136
|
} | {
|
|
59
137
|
vectorStoreName?: string;
|
|
60
|
-
|
|
138
|
+
/**
|
|
139
|
+
* The vector store instance or a resolver function for dynamic selection.
|
|
140
|
+
*
|
|
141
|
+
* For multi-tenant applications, pass a function that receives the request context
|
|
142
|
+
* and returns the appropriate vector store for the current tenant/schema.
|
|
143
|
+
*
|
|
144
|
+
* @example Static vector store
|
|
145
|
+
* ```typescript
|
|
146
|
+
* vectorStore: new PgVector({ connectionString: '...' })
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @example Dynamic resolver for multi-tenant
|
|
150
|
+
* ```typescript
|
|
151
|
+
* vectorStore: async ({ requestContext }) => {
|
|
152
|
+
* const schemaId = requestContext?.get('schemaId');
|
|
153
|
+
* return getVectorStoreForSchema(schemaId);
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
vectorStore: MastraVector | VectorStoreResolver;
|
|
61
158
|
});
|
|
159
|
+
/**
|
|
160
|
+
* Configuration options for creating a GraphRAG tool.
|
|
161
|
+
*
|
|
162
|
+
* GraphRAG combines vector similarity search with graph-based retrieval for improved
|
|
163
|
+
* context relevance through random walk algorithms.
|
|
164
|
+
*
|
|
165
|
+
* This type uses a discriminated union pattern for vector store configuration,
|
|
166
|
+
* allowing two mutually exclusive approaches:
|
|
167
|
+
*
|
|
168
|
+
* 1. **By name**: Use `vectorStoreName` to reference a vector store registered with Mastra
|
|
169
|
+
* 2. **Direct instance**: Use `vectorStore` to provide a vector store instance or resolver function
|
|
170
|
+
*
|
|
171
|
+
* @example Using a named vector store
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const tool = createGraphRAGTool({
|
|
174
|
+
* vectorStoreName: 'myVectorStore',
|
|
175
|
+
* indexName: 'documents',
|
|
176
|
+
* model: openai.embedding('text-embedding-3-small'),
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example With custom graph options
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const tool = createGraphRAGTool({
|
|
183
|
+
* vectorStoreName: 'myVectorStore',
|
|
184
|
+
* indexName: 'documents',
|
|
185
|
+
* model: openai.embedding('text-embedding-3-small'),
|
|
186
|
+
* graphOptions: {
|
|
187
|
+
* randomWalkSteps: 200,
|
|
188
|
+
* restartProb: 0.2,
|
|
189
|
+
* },
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
62
193
|
export type GraphRagToolOptions = {
|
|
194
|
+
/** Custom tool ID. Defaults to `GraphRAG {storeName} {indexName} Tool` */
|
|
63
195
|
id?: string;
|
|
196
|
+
/** Custom tool description for the LLM */
|
|
64
197
|
description?: string;
|
|
198
|
+
/** Name of the index to query within the vector store */
|
|
65
199
|
indexName: string;
|
|
66
|
-
|
|
200
|
+
/** Embedding model used to convert query text into vectors */
|
|
67
201
|
model: MastraEmbeddingModel<string>;
|
|
202
|
+
/** When true, enables metadata filtering in queries. Adds a `filter` input to the tool schema */
|
|
68
203
|
enableFilter?: boolean;
|
|
204
|
+
/** When true, includes source documents in the response. Defaults to true */
|
|
69
205
|
includeSources?: boolean;
|
|
206
|
+
/** Configuration options for the graph-based retrieval algorithm */
|
|
70
207
|
graphOptions?: {
|
|
208
|
+
/** Vector dimension size. Defaults to 1536 */
|
|
71
209
|
dimension?: number;
|
|
210
|
+
/** Number of steps in the random walk. Defaults to 100 */
|
|
72
211
|
randomWalkSteps?: number;
|
|
212
|
+
/** Probability of restarting the random walk. Defaults to 0.15 */
|
|
73
213
|
restartProb?: number;
|
|
214
|
+
/** Similarity threshold for graph edges. Defaults to 0.7 */
|
|
74
215
|
threshold?: number;
|
|
75
216
|
};
|
|
76
|
-
} & ProviderOptions
|
|
217
|
+
} & ProviderOptions & ({
|
|
218
|
+
vectorStoreName: string;
|
|
219
|
+
} | {
|
|
220
|
+
vectorStoreName?: string;
|
|
221
|
+
/**
|
|
222
|
+
* The vector store instance or a resolver function for dynamic selection.
|
|
223
|
+
*
|
|
224
|
+
* For multi-tenant applications, pass a function that receives the request context
|
|
225
|
+
* and returns the appropriate vector store for the current tenant/schema.
|
|
226
|
+
*
|
|
227
|
+
* @example Static vector store
|
|
228
|
+
* ```typescript
|
|
229
|
+
* vectorStore: new PgVector({ connectionString: '...' })
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example Dynamic resolver for multi-tenant
|
|
233
|
+
* ```typescript
|
|
234
|
+
* vectorStore: async ({ requestContext }) => {
|
|
235
|
+
* const schemaId = requestContext?.get('schemaId');
|
|
236
|
+
* return getVectorStoreForSchema(schemaId);
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
vectorStore: MastraVector | VectorStoreResolver;
|
|
241
|
+
});
|
|
77
242
|
export type ProviderOptions = {
|
|
78
243
|
/**
|
|
79
244
|
* Provider-specific options for the embedding model (e.g., outputDimensionality).
|
|
@@ -86,19 +251,11 @@ export type ProviderOptions = {
|
|
|
86
251
|
* **For v2 models**: Use providerOptions:
|
|
87
252
|
* ✅ providerOptions: { openai: { dimensions: 512 } }
|
|
88
253
|
*/
|
|
89
|
-
providerOptions?:
|
|
254
|
+
providerOptions?: MastraEmbeddingOptions['providerOptions'];
|
|
90
255
|
};
|
|
91
256
|
/**
|
|
92
257
|
* Default options for GraphRAG
|
|
93
|
-
* @default
|
|
94
|
-
* ```json
|
|
95
|
-
* {
|
|
96
|
-
* "dimension": 1536,
|
|
97
|
-
* "randomWalkSteps": 100,
|
|
98
|
-
* "restartProb": 0.15,
|
|
99
|
-
* "threshold": 0.7
|
|
100
|
-
* }
|
|
101
|
-
* ```
|
|
258
|
+
* @default { dimension: 1536, randomWalkSteps: 100, restartProb: 0.15, threshold: 0.7 }
|
|
102
259
|
*/
|
|
103
260
|
export declare const defaultGraphOptions: {
|
|
104
261
|
dimension: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAEtG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,+DAA+D;IAC/D,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,6DAA6D;IAC7D,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,0BAA0B,KAAK,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEhH,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE;QACb,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;CACH;AAED,MAAM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,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oEAAoE;IACpE,YAAY,CAAC,EAAE;QACb,8CAA8C;QAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,0DAA0D;QAC1D,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,kEAAkE;QAClE,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,GAAG,eAAe,GACjB,CACI;IACE,eAAe,EAAE,MAAM,CAAC;CACzB,GACD;IACE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,EAAE,YAAY,GAAG,mBAAmB,CAAC;CACjD,CACJ,CAAC;AAEJ,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;CAK/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-query.d.ts","sourceRoot":"","sources":["../../src/tools/vector-query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"vector-query.d.ts","sourceRoot":"","sources":["../../src/tools/vector-query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAmB,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEvE,eAAO,MAAM,qBAAqB,GAAI,SAAS,sBAAsB,KAoI7D,OAAO;;;;;;;;;;;;;;;;;;;;;kCAAqB,GAAG,CACtC,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { MastraUnion } from '@mastra/core/action';
|
|
2
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { MastraVector } from '@mastra/core/vector';
|
|
4
|
+
import type { VectorStoreResolver } from '../tools/types.js';
|
|
5
|
+
interface Logger {
|
|
6
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
7
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Context for resolving vector stores.
|
|
11
|
+
*/
|
|
12
|
+
export interface ResolveVectorStoreContext {
|
|
13
|
+
requestContext?: RequestContext;
|
|
14
|
+
mastra?: MastraUnion;
|
|
15
|
+
/** Fallback vector store name to look up from mastra if vectorStore option is not provided */
|
|
16
|
+
vectorStoreName: string;
|
|
17
|
+
/**
|
|
18
|
+
* When true, logs a warning and falls back to mastra.getVector if an explicitly provided
|
|
19
|
+
* vectorStore is invalid. When false (default), throws an error for invalid vectorStore.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
fallbackOnInvalid?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolves a vector store from options, supporting both static instances and dynamic resolver functions.
|
|
26
|
+
* For multi-tenant setups, the resolver function receives the request context to select the appropriate store.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Tool options object that may contain a vectorStore property
|
|
29
|
+
* @param context - Context including requestContext, mastra instance, and fallback vectorStoreName
|
|
30
|
+
* @param logger - Optional logger for warning/error reporting
|
|
31
|
+
* @returns The resolved MastraVector instance, or undefined if not found
|
|
32
|
+
* @throws Error if an explicit vectorStore was provided but is invalid (unless fallbackOnInvalid is true)
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveVectorStore(options: {
|
|
35
|
+
vectorStore?: MastraVector | VectorStoreResolver;
|
|
36
|
+
} | Record<string, unknown>, context: ResolveVectorStoreContext, logger?: Logger | null): Promise<MastraVector | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Coerces a topK value to a number, handling string inputs and providing a default.
|
|
39
|
+
* Validates that the result is a finite positive number greater than zero.
|
|
40
|
+
* @param topK - The value to coerce (number, string, or undefined)
|
|
41
|
+
* @param defaultValue - Default value if coercion fails (defaults to 10)
|
|
42
|
+
* @returns A valid positive number for topK, or defaultValue if invalid/non-finite/zero/negative
|
|
43
|
+
*/
|
|
44
|
+
export declare function coerceTopK(topK: number | string | undefined, defaultValue?: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Parses a filter value, handling both string (JSON) and object inputs.
|
|
47
|
+
* @param filter - The filter value to parse (string or object)
|
|
48
|
+
* @param logger - Optional logger for error reporting
|
|
49
|
+
* @returns Parsed filter object
|
|
50
|
+
* @throws Error if filter is a string that cannot be parsed as JSON or if filter is not a plain object
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseFilterValue(filter: unknown, logger?: Logger | null): Record<string, any>;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=tool-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/tool-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,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AAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,GAAG,eAAe,CAAC;AAEpB,UAAU,uBAAuB;IAC/B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAWD,eAAO,MAAM,iBAAiB,GAAU,+HAWrC,uBAAuB,KAAG,OAAO,CAAC,uBAAuB,CA0C3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/rag",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@paralleldrive/cuid2": "^2.3.1",
|
|
29
29
|
"big.js": "^7.0.1",
|
|
30
|
-
"js-tiktoken": "^1.0.
|
|
30
|
+
"js-tiktoken": "^1.0.21",
|
|
31
31
|
"node-html-better-parser": "^1.5.8",
|
|
32
32
|
"pathe": "^2.0.3",
|
|
33
33
|
"zeroentropy": "0.1.0-alpha.6"
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@ai-sdk/cohere": "^1.2.10",
|
|
42
42
|
"@ai-sdk/openai": "^1.3.24",
|
|
43
|
-
"@microsoft/api-extractor": "^7.52.8",
|
|
44
43
|
"@types/big.js": "^6.2.2",
|
|
45
44
|
"@types/node": "22.13.17",
|
|
46
45
|
"@vitest/coverage-v8": "4.0.12",
|
|
@@ -49,13 +48,13 @@
|
|
|
49
48
|
"dotenv": "^17.0.0",
|
|
50
49
|
"eslint": "^9.37.0",
|
|
51
50
|
"tsup": "^8.5.0",
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"vitest": "4.0.
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vitest": "4.0.16",
|
|
54
53
|
"zod": "^3.25.76",
|
|
54
|
+
"@internal/ai-sdk-v4": "0.0.0",
|
|
55
55
|
"@internal/lint": "0.0.53",
|
|
56
56
|
"@internal/types-builder": "0.0.28",
|
|
57
|
-
"@mastra/core": "1.0.0-beta.
|
|
58
|
-
"@internal/ai-sdk-v4": "0.0.0"
|
|
57
|
+
"@mastra/core": "1.0.0-beta.20"
|
|
59
58
|
},
|
|
60
59
|
"keywords": [
|
|
61
60
|
"rag",
|
|
@@ -86,8 +85,9 @@
|
|
|
86
85
|
"node": ">=22.13.0"
|
|
87
86
|
},
|
|
88
87
|
"scripts": {
|
|
89
|
-
"build": "tsup --silent --config tsup.config.ts",
|
|
90
|
-
"build:
|
|
88
|
+
"build:lib": "tsup --silent --config tsup.config.ts",
|
|
89
|
+
"build:docs": "pnpx tsx ../../scripts/generate-package-docs.ts packages/rag",
|
|
90
|
+
"build:watch": "pnpm build:lib --watch",
|
|
91
91
|
"vitest": "vitest",
|
|
92
92
|
"test": "vitest run",
|
|
93
93
|
"lint": "eslint ."
|