@mastra/rag 1.2.2 → 1.2.3-alpha.1

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.cjs +25 -9
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +25 -9
  5. package/dist/index.js.map +1 -1
  6. package/dist/tools/graph-rag.d.ts.map +1 -1
  7. package/dist/tools/types.d.ts +18 -5
  8. package/dist/tools/types.d.ts.map +1 -1
  9. package/dist/tools/vector-query.d.ts.map +1 -1
  10. package/dist/utils/vector-search.d.ts +6 -7
  11. package/dist/utils/vector-search.d.ts.map +1 -1
  12. package/package.json +19 -6
  13. package/.turbo/turbo-build.log +0 -4
  14. package/docker-compose.yaml +0 -22
  15. package/eslint.config.js +0 -6
  16. package/src/document/document.test.ts +0 -2975
  17. package/src/document/document.ts +0 -335
  18. package/src/document/extractors/base.ts +0 -30
  19. package/src/document/extractors/index.ts +0 -5
  20. package/src/document/extractors/keywords.test.ts +0 -125
  21. package/src/document/extractors/keywords.ts +0 -126
  22. package/src/document/extractors/questions.test.ts +0 -120
  23. package/src/document/extractors/questions.ts +0 -111
  24. package/src/document/extractors/summary.test.ts +0 -107
  25. package/src/document/extractors/summary.ts +0 -122
  26. package/src/document/extractors/title.test.ts +0 -121
  27. package/src/document/extractors/title.ts +0 -185
  28. package/src/document/extractors/types.ts +0 -40
  29. package/src/document/index.ts +0 -2
  30. package/src/document/prompts/base.ts +0 -77
  31. package/src/document/prompts/format.ts +0 -9
  32. package/src/document/prompts/index.ts +0 -15
  33. package/src/document/prompts/prompt.ts +0 -60
  34. package/src/document/prompts/types.ts +0 -29
  35. package/src/document/schema/index.ts +0 -3
  36. package/src/document/schema/node.ts +0 -187
  37. package/src/document/schema/types.ts +0 -40
  38. package/src/document/transformers/character.ts +0 -267
  39. package/src/document/transformers/html.ts +0 -346
  40. package/src/document/transformers/json.ts +0 -536
  41. package/src/document/transformers/latex.ts +0 -11
  42. package/src/document/transformers/markdown.ts +0 -239
  43. package/src/document/transformers/semantic-markdown.ts +0 -227
  44. package/src/document/transformers/sentence.ts +0 -314
  45. package/src/document/transformers/text.ts +0 -158
  46. package/src/document/transformers/token.ts +0 -137
  47. package/src/document/transformers/transformer.ts +0 -5
  48. package/src/document/types.ts +0 -145
  49. package/src/document/validation.ts +0 -158
  50. package/src/graph-rag/index.test.ts +0 -235
  51. package/src/graph-rag/index.ts +0 -306
  52. package/src/index.ts +0 -8
  53. package/src/rerank/index.test.ts +0 -150
  54. package/src/rerank/index.ts +0 -198
  55. package/src/rerank/relevance/cohere/index.ts +0 -56
  56. package/src/rerank/relevance/index.ts +0 -3
  57. package/src/rerank/relevance/mastra-agent/index.ts +0 -32
  58. package/src/rerank/relevance/zeroentropy/index.ts +0 -26
  59. package/src/tools/README.md +0 -153
  60. package/src/tools/document-chunker.ts +0 -34
  61. package/src/tools/graph-rag.test.ts +0 -115
  62. package/src/tools/graph-rag.ts +0 -154
  63. package/src/tools/index.ts +0 -3
  64. package/src/tools/types.ts +0 -110
  65. package/src/tools/vector-query-database-config.test.ts +0 -190
  66. package/src/tools/vector-query.test.ts +0 -418
  67. package/src/tools/vector-query.ts +0 -169
  68. package/src/utils/convert-sources.ts +0 -43
  69. package/src/utils/default-settings.ts +0 -38
  70. package/src/utils/index.ts +0 -3
  71. package/src/utils/tool-schemas.ts +0 -38
  72. package/src/utils/vector-prompts.ts +0 -832
  73. package/src/utils/vector-search.ts +0 -117
  74. package/tsconfig.build.json +0 -9
  75. package/tsconfig.json +0 -5
  76. package/tsup.config.ts +0 -17
  77. package/vitest.config.ts +0 -8
@@ -1,117 +0,0 @@
1
- import type { MastraVector, QueryResult, QueryVectorParams } from '@mastra/core/vector';
2
- import type { VectorFilter } from '@mastra/core/vector/filter';
3
- import { embed } from 'ai';
4
- import type { EmbeddingModel } from 'ai';
5
- import type { DatabaseConfig } from '../tools/types';
6
-
7
- interface VectorQuerySearchParams {
8
- indexName: string;
9
- vectorStore: MastraVector;
10
- queryText: string;
11
- model: EmbeddingModel<string>;
12
- queryFilter?: VectorFilter;
13
- topK: number;
14
- includeVectors?: boolean;
15
- maxRetries?: number;
16
- /** Database-specific configuration options */
17
- databaseConfig?: DatabaseConfig;
18
- }
19
-
20
- interface VectorQuerySearchResult {
21
- results: QueryResult[];
22
- queryEmbedding: number[];
23
- }
24
-
25
- enum DatabaseType {
26
- Pinecone = 'pinecone',
27
- PgVector = 'pgvector',
28
- Chroma = 'chroma',
29
- }
30
-
31
- const DATABASE_TYPE_MAP = Object.keys(DatabaseType);
32
-
33
- // Helper function to handle vector query search
34
- export const vectorQuerySearch = async ({
35
- indexName,
36
- vectorStore,
37
- queryText,
38
- model,
39
- queryFilter,
40
- topK,
41
- includeVectors = false,
42
- maxRetries = 2,
43
- databaseConfig = {},
44
- }: VectorQuerySearchParams): Promise<VectorQuerySearchResult> => {
45
- const { embedding } = await embed({
46
- value: queryText,
47
- model,
48
- maxRetries,
49
- });
50
-
51
- // Build query parameters with database-specific configurations
52
- const queryParams: QueryVectorParams = {
53
- indexName,
54
- queryVector: embedding,
55
- topK,
56
- filter: queryFilter,
57
- includeVector: includeVectors,
58
- };
59
-
60
- // Get relevant chunks from the vector database
61
- const results = await vectorStore.query({ ...queryParams, ...databaseSpecificParams(databaseConfig) });
62
-
63
- return { results, queryEmbedding: embedding };
64
- };
65
-
66
- const databaseSpecificParams = (databaseConfig: DatabaseConfig) => {
67
- const databaseSpecificParams: DatabaseConfig = {};
68
-
69
- // Apply database-specific configurations
70
- if (databaseConfig) {
71
- // Pinecone-specific configurations
72
- if (databaseConfig.pinecone) {
73
- if (databaseConfig.pinecone.namespace) {
74
- databaseSpecificParams.namespace = databaseConfig.pinecone.namespace;
75
- }
76
- if (databaseConfig.pinecone.sparseVector) {
77
- databaseSpecificParams.sparseVector = databaseConfig.pinecone.sparseVector;
78
- }
79
- }
80
-
81
- // pgVector-specific configurations
82
- if (databaseConfig.pgvector) {
83
- if (databaseConfig.pgvector.minScore !== undefined) {
84
- databaseSpecificParams.minScore = databaseConfig.pgvector.minScore;
85
- }
86
- if (databaseConfig.pgvector.ef !== undefined) {
87
- databaseSpecificParams.ef = databaseConfig.pgvector.ef;
88
- }
89
- if (databaseConfig.pgvector.probes !== undefined) {
90
- databaseSpecificParams.probes = databaseConfig.pgvector.probes;
91
- }
92
- }
93
-
94
- // Chroma-specific configurations
95
- if (databaseConfig.chroma) {
96
- if (databaseConfig.chroma.where) {
97
- databaseSpecificParams.where = databaseConfig.chroma.where;
98
- }
99
- if (databaseConfig.chroma.whereDocument) {
100
- databaseSpecificParams.whereDocument = databaseConfig.chroma.whereDocument;
101
- }
102
- }
103
-
104
- // Handle any additional database configs
105
- Object.keys(databaseConfig).forEach(dbName => {
106
- if (!DATABASE_TYPE_MAP.includes(dbName)) {
107
- // For unknown database types, merge the config directly
108
- const config = databaseConfig[dbName];
109
- if (config && typeof config === 'object') {
110
- Object.assign(databaseSpecificParams, config);
111
- }
112
- }
113
- });
114
- }
115
-
116
- return databaseSpecificParams;
117
- };
@@ -1,9 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*", "tsup.config.ts"],
4
- "exclude": ["node_modules", "**/*.test.ts"]
5
- }
package/tsup.config.ts DELETED
@@ -1,17 +0,0 @@
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
- });
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node',
6
- include: ['src/**/*.test.ts'],
7
- },
8
- });