@mastra/rag 2.6.6 → 2.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-guides-context-engineering.md +0 -2
- package/dist/docs/references/reference-rag-chunk.md +2 -2
- package/dist/docs/references/reference-rag-chunking-and-embedding.md +1 -1
- package/dist/docs/references/reference-rag-database-config.md +14 -2
- package/dist/docs/references/reference-rag-document.md +7 -2
- package/dist/docs/references/reference-rag-extract-params.md +5 -5
- package/dist/docs/references/reference-rag-graph-rag-guide.md +1 -1
- package/dist/docs/references/reference-rag-rerank.md +5 -4
- package/dist/docs/references/reference-rag-rerankWithScorer.md +2 -2
- package/dist/docs/references/reference-rag-retrieval.md +7 -5
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
|
@@ -210,8 +210,6 @@ Observations are added in stable chunks, which helps providers reuse the existin
|
|
|
210
210
|
|
|
211
211
|
## Signals
|
|
212
212
|
|
|
213
|
-
> **Beta:** Signals may change without a major version bump until the API is stable.
|
|
214
|
-
|
|
215
213
|
[Signals](https://mastra.ai/docs/harness/signals) add messages or system-generated context to a memory-backed thread. Delivery depends on the thread's state: a signal can wake an idle agent or enter an active loop. It can also wait for the next turn or persist without waking the agent.
|
|
216
214
|
|
|
217
215
|
State signals require memory and an existing thread. Notification inbox signals require a storage adapter with notification support.
|
|
@@ -47,7 +47,7 @@ The following parameters are available for all chunking strategies. Each strateg
|
|
|
47
47
|
|
|
48
48
|
**maxSize** (`number`): Maximum size of each chunk. Some strategy configurations (markdown with headers, HTML with headers) ignore this parameter. (Default: `4000`)
|
|
49
49
|
|
|
50
|
-
**overlap** (`number`): Number of characters/tokens that overlap between chunks. (Default: `
|
|
50
|
+
**overlap** (`number`): Number of characters/tokens that overlap between chunks. Defaults to 200 for most strategies; the 'sentence' strategy defaults to 0. (Default: `200`)
|
|
51
51
|
|
|
52
52
|
**lengthFunction** (`(text: string) => number`): Function to calculate text length. Defaults to character count.
|
|
53
53
|
|
|
@@ -130,7 +130,7 @@ The options documented below are passed directly at the top level of the configu
|
|
|
130
130
|
|
|
131
131
|
### Character
|
|
132
132
|
|
|
133
|
-
**
|
|
133
|
+
**separator** (`string`): Character or string to split text on. (Default: `'\n\n'`)
|
|
134
134
|
|
|
135
135
|
**isSeparatorRegex** (`boolean`): Whether the separator is a regex pattern (Default: `false`)
|
|
136
136
|
|
|
@@ -13,6 +13,7 @@ export type DatabaseConfig = {
|
|
|
13
13
|
pinecone?: PineconeConfig
|
|
14
14
|
pgvector?: PgVectorConfig
|
|
15
15
|
chroma?: ChromaConfig
|
|
16
|
+
mongodb?: MongoDBConfig
|
|
16
17
|
turbopuffer?: TurbopufferConfig
|
|
17
18
|
[key: string]: any // Extensible for future databases
|
|
18
19
|
}
|
|
@@ -64,9 +65,9 @@ Configuration options specific to PostgreSQL with pgvector extension.
|
|
|
64
65
|
|
|
65
66
|
Configuration options specific to Chroma vector store.
|
|
66
67
|
|
|
67
|
-
**where** (`
|
|
68
|
+
**where** (`Where`): Metadata filtering conditions. Each field maps to a literal value or an operator expression ($gt, $gte, $lt, $lte, $ne, $eq, $in, $nin). Combine conditions with $and and $or.
|
|
68
69
|
|
|
69
|
-
**whereDocument** (`
|
|
70
|
+
**whereDocument** (`WhereDocument`): Document content filtering conditions using $contains and $not\_contains. Combine conditions with $and and $or.
|
|
70
71
|
|
|
71
72
|
**Filter Syntax Examples:**
|
|
72
73
|
|
|
@@ -93,6 +94,17 @@ whereDocument: { "$contains": "API documentation" }
|
|
|
93
94
|
- Content-based document filtering
|
|
94
95
|
- Complex query combinations
|
|
95
96
|
|
|
97
|
+
### `MongoDBConfig`
|
|
98
|
+
|
|
99
|
+
Configuration options specific to MongoDB Atlas Vector Search.
|
|
100
|
+
|
|
101
|
+
**numCandidates** (`number`): Number of candidates the HNSW graph considers before selecting the top-K results. Higher values improve recall at the cost of query latency. Must be greater than or equal to topK. Defaults to 20 × topK, capped at 10,000.
|
|
102
|
+
|
|
103
|
+
**Use Cases:**
|
|
104
|
+
|
|
105
|
+
- Improving recall for large collections
|
|
106
|
+
- Lowering latency when approximate results are acceptable
|
|
107
|
+
|
|
96
108
|
### `TurbopufferConfig`
|
|
97
109
|
|
|
98
110
|
Configuration options specific to Turbopuffer vector store.
|
|
@@ -10,7 +10,7 @@ The MDocument class processes documents for RAG applications. The main methods a
|
|
|
10
10
|
|
|
11
11
|
**docs** (`Array<{ text: string, metadata?: Record<string, any> }>`): Array of document chunks with their text content and optional metadata
|
|
12
12
|
|
|
13
|
-
**type** (`'text'
|
|
13
|
+
**type** (`string`): Type of document content. Recognized values are 'text', 'html', 'markdown', 'json', and 'latex'.
|
|
14
14
|
|
|
15
15
|
## Static methods
|
|
16
16
|
|
|
@@ -53,9 +53,14 @@ static fromJSON(json: string, metadata?: Record<string, any>): MDocument
|
|
|
53
53
|
Splits document into chunks and optionally extracts metadata.
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
|
-
async chunk(
|
|
56
|
+
async chunk(
|
|
57
|
+
params?: ChunkParams,
|
|
58
|
+
options?: { observabilityContext?: ObservabilityContext },
|
|
59
|
+
): Promise<Chunk[]>
|
|
57
60
|
```
|
|
58
61
|
|
|
62
|
+
Pass `observabilityContext` to attach the chunking and metadata extraction spans to an existing trace.
|
|
63
|
+
|
|
59
64
|
See [chunk() reference](https://mastra.ai/reference/rag/chunk) for detailed options.
|
|
60
65
|
|
|
61
66
|
### `getDocs()`
|
|
@@ -46,7 +46,7 @@ The `extract` parameter accepts the following fields:
|
|
|
46
46
|
|
|
47
47
|
### `TitleExtractorsArgs`
|
|
48
48
|
|
|
49
|
-
**llm** (`MastraLanguageModel`): AI SDK language model to use for title extraction
|
|
49
|
+
**llm** (`MastraLanguageModel | MastraLegacyLanguageModel`): AI SDK language model to use for title extraction
|
|
50
50
|
|
|
51
51
|
**nodes** (`number`): Number of title nodes to extract
|
|
52
52
|
|
|
@@ -56,15 +56,15 @@ The `extract` parameter accepts the following fields:
|
|
|
56
56
|
|
|
57
57
|
### `SummaryExtractArgs`
|
|
58
58
|
|
|
59
|
-
**llm** (`MastraLanguageModel`): AI SDK language model to use for summary extraction
|
|
59
|
+
**llm** (`MastraLanguageModel | MastraLegacyLanguageModel`): AI SDK language model to use for summary extraction
|
|
60
60
|
|
|
61
|
-
**summaries** (`
|
|
61
|
+
**summaries** (`string[]`): List of summary types to generate. Defaults to \['self']. Supported values are 'self' (current chunk), 'prev' (previous chunk), and 'next' (next chunk).
|
|
62
62
|
|
|
63
63
|
**promptTemplate** (`string`): Custom prompt template for summary generation. Must include {context} placeholder
|
|
64
64
|
|
|
65
65
|
### `QuestionAnswerExtractArgs`
|
|
66
66
|
|
|
67
|
-
**llm** (`MastraLanguageModel`): AI SDK language model to use for question generation
|
|
67
|
+
**llm** (`MastraLanguageModel | MastraLegacyLanguageModel`): AI SDK language model to use for question generation
|
|
68
68
|
|
|
69
69
|
**questions** (`number`): Number of questions to generate
|
|
70
70
|
|
|
@@ -74,7 +74,7 @@ The `extract` parameter accepts the following fields:
|
|
|
74
74
|
|
|
75
75
|
### `KeywordExtractArgs`
|
|
76
76
|
|
|
77
|
-
**llm** (`MastraLanguageModel`): AI SDK language model to use for keyword extraction
|
|
77
|
+
**llm** (`MastraLanguageModel | MastraLegacyLanguageModel`): AI SDK language model to use for keyword extraction
|
|
78
78
|
|
|
79
79
|
**keywords** (`number`): Number of keywords to extract
|
|
80
80
|
|
|
@@ -23,7 +23,7 @@ For straightforward semantic search without relationship traversal, use [standar
|
|
|
23
23
|
GraphRAG combines vector similarity with knowledge graph traversal:
|
|
24
24
|
|
|
25
25
|
1. Initial vector search retrieves relevant chunks based on semantic similarity
|
|
26
|
-
2.
|
|
26
|
+
2. On the tool's first execution, a knowledge graph is constructed from the retrieved chunks. Later queries reuse this graph
|
|
27
27
|
3. The graph is traversed to find connected information
|
|
28
28
|
4. Results include both directly relevant chunks and related content
|
|
29
29
|
|
|
@@ -10,17 +10,18 @@ The `rerank()` function provides advanced reranking capabilities for vector sear
|
|
|
10
10
|
function rerank(
|
|
11
11
|
results: QueryResult[],
|
|
12
12
|
query: string,
|
|
13
|
-
|
|
14
|
-
options
|
|
13
|
+
model: MastraLanguageModel,
|
|
14
|
+
options: RerankerFunctionOptions,
|
|
15
15
|
): Promise<RerankResult[]>
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage example
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
+
import { ModelRouterLanguageModel } from '@mastra/core/llm'
|
|
21
22
|
import { rerank } from '@mastra/rag'
|
|
22
23
|
|
|
23
|
-
const model = 'openai/gpt-5.6-sol'
|
|
24
|
+
const model = new ModelRouterLanguageModel('openai/gpt-5.6-sol')
|
|
24
25
|
|
|
25
26
|
const rerankedResults = await rerank(vectorSearchResults, 'How do I deploy to production?', model, {
|
|
26
27
|
weights: {
|
|
@@ -64,7 +65,7 @@ The function returns an array of `RerankResult` objects:
|
|
|
64
65
|
|
|
65
66
|
**result** (`QueryResult`): The original query result
|
|
66
67
|
|
|
67
|
-
**score** (`number`): Combined reranking score
|
|
68
|
+
**score** (`number`): Combined reranking score. Usually between 0 and 1, but query-based adjustments can raise it slightly above 1.
|
|
68
69
|
|
|
69
70
|
**details** (`ScoringDetails`): Detailed scoring information
|
|
70
71
|
|
|
@@ -11,7 +11,7 @@ function rerankWithScorer({
|
|
|
11
11
|
results: QueryResult[],
|
|
12
12
|
query: string,
|
|
13
13
|
scorer: RelevanceScoreProvider,
|
|
14
|
-
options
|
|
14
|
+
options: RerankerFunctionOptions,
|
|
15
15
|
}): Promise<RerankResult[]>;
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -69,7 +69,7 @@ The function returns an array of `RerankResult` objects:
|
|
|
69
69
|
|
|
70
70
|
**result** (`QueryResult`): The original query result
|
|
71
71
|
|
|
72
|
-
**score** (`number`): Combined reranking score
|
|
72
|
+
**score** (`number`): Combined reranking score. Usually between 0 and 1, but query-based adjustments can raise it slightly above 1.
|
|
73
73
|
|
|
74
74
|
**details** (`ScoringDetails`): Detailed scoring information
|
|
75
75
|
|
|
@@ -50,23 +50,25 @@ console.log(results)
|
|
|
50
50
|
|
|
51
51
|
The `topK` parameter specifies the maximum number of most similar results to return from the vector search.
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Each result includes an `id`, a similarity `score`, and the stored `metadata`. When you store chunk text in metadata, it's available as `metadata.text`:
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
56
|
[
|
|
57
57
|
{
|
|
58
|
-
|
|
58
|
+
id: 'chunk-1',
|
|
59
59
|
score: 0.89,
|
|
60
|
-
metadata: { source: 'article1.txt' },
|
|
60
|
+
metadata: { text: 'Climate change poses significant challenges...', source: 'article1.txt' },
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
|
|
63
|
+
id: 'chunk-2',
|
|
64
64
|
score: 0.82,
|
|
65
|
-
metadata: { source: 'article1.txt' },
|
|
65
|
+
metadata: { text: 'Rising temperatures affect crop yields...', source: 'article1.txt' },
|
|
66
66
|
},
|
|
67
67
|
]
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
Results can also include `vector` when you set `includeVector: true`, and `document` when the store returns the original document (Chroma only).
|
|
71
|
+
|
|
70
72
|
## Advanced retrieval options
|
|
71
73
|
|
|
72
74
|
### Metadata Filtering
|
package/dist/index.cjs
CHANGED
|
@@ -634,7 +634,7 @@ var UnsupportedFunctionalityError = class extends AISDKError {
|
|
|
634
634
|
};
|
|
635
635
|
_a14 = symbol14;
|
|
636
636
|
//#endregion
|
|
637
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/nanoid/
|
|
637
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/nanoid/5.1.16/f16424b532a5e69aacddcb2977ac17378b6f79695bbd27ead3d90c703848f22f/node_modules/nanoid/non-secure/index.js
|
|
638
638
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
639
639
|
return (size = defaultSize) => {
|
|
640
640
|
let id = "";
|
|
@@ -644,7 +644,7 @@ let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
|
644
644
|
};
|
|
645
645
|
};
|
|
646
646
|
//#endregion
|
|
647
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider-utils/2.2.8/
|
|
647
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider-utils/2.2.8/fd79a5c5f5d36120acbfd746754884c17798c35178b46bd11cca9dff89c013d2/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
648
648
|
var import_secure_json_parse = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
649
649
|
const hasBuffer = typeof Buffer !== "undefined";
|
|
650
650
|
const suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
@@ -1187,7 +1187,7 @@ function withoutTrailingSlash(url) {
|
|
|
1187
1187
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
1188
1188
|
}
|
|
1189
1189
|
//#endregion
|
|
1190
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/
|
|
1190
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/016fac41d998ff168d98fde7926aa7713f8ffc38160a6b4427bfdc41fae1bc99/node_modules/@ai-sdk/openai/dist/index.mjs
|
|
1191
1191
|
function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false, systemMessageMode = "system" }) {
|
|
1192
1192
|
const messages = [];
|
|
1193
1193
|
const warnings = [];
|
|
@@ -6088,8 +6088,8 @@ var MDocument = class MDocument {
|
|
|
6088
6088
|
attributes: {
|
|
6089
6089
|
action: "chunk",
|
|
6090
6090
|
strategy,
|
|
6091
|
-
chunkSize: chunkOptions
|
|
6092
|
-
chunkOverlap: chunkOptions
|
|
6091
|
+
chunkSize: "maxSize" in chunkOptions ? chunkOptions.maxSize : void 0,
|
|
6092
|
+
chunkOverlap: "overlap" in chunkOptions ? chunkOptions.overlap : void 0
|
|
6093
6093
|
}
|
|
6094
6094
|
});
|
|
6095
6095
|
try {
|