@memberjunction/query-gen 6.1.4 → 6.2.0-edge.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +119 -69
- package/dist/cli/commands/export.d.ts +2 -0
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +10 -6
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +19 -15
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +2 -0
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +12 -8
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/config.d.ts +2 -0
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +5 -1
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/index.js +6 -6
- package/dist/core/EntityGrouper.d.ts +2 -0
- package/dist/core/EntityGrouper.d.ts.map +1 -1
- package/dist/core/EntityGrouper.js +13 -9
- package/dist/core/EntityGrouper.js.map +1 -1
- package/dist/core/MetadataExporter.d.ts +2 -0
- package/dist/core/MetadataExporter.d.ts.map +1 -1
- package/dist/core/MetadataExporter.js +5 -1
- package/dist/core/MetadataExporter.js.map +1 -1
- package/dist/core/QueryDatabaseWriter.d.ts +2 -0
- package/dist/core/QueryDatabaseWriter.d.ts.map +1 -1
- package/dist/core/QueryDatabaseWriter.js +7 -3
- package/dist/core/QueryDatabaseWriter.js.map +1 -1
- package/dist/core/QueryFixer.d.ts +2 -0
- package/dist/core/QueryFixer.d.ts.map +1 -1
- package/dist/core/QueryFixer.js +9 -5
- package/dist/core/QueryFixer.js.map +1 -1
- package/dist/core/QueryRefiner.d.ts +2 -0
- package/dist/core/QueryRefiner.d.ts.map +1 -1
- package/dist/core/QueryRefiner.js +12 -8
- package/dist/core/QueryRefiner.js.map +1 -1
- package/dist/core/QueryTester.d.ts +2 -0
- package/dist/core/QueryTester.d.ts.map +1 -1
- package/dist/core/QueryTester.js +9 -5
- package/dist/core/QueryTester.js.map +1 -1
- package/dist/core/QueryWriter.d.ts +2 -0
- package/dist/core/QueryWriter.d.ts.map +1 -1
- package/dist/core/QueryWriter.js +9 -5
- package/dist/core/QueryWriter.js.map +1 -1
- package/dist/core/QuestionGenerator.d.ts +2 -0
- package/dist/core/QuestionGenerator.d.ts.map +1 -1
- package/dist/core/QuestionGenerator.js +11 -7
- package/dist/core/QuestionGenerator.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/utils/category-builder.d.ts +4 -0
- package/dist/utils/category-builder.d.ts.map +1 -1
- package/dist/utils/category-builder.js +10 -2
- package/dist/utils/category-builder.js.map +1 -1
- package/dist/utils/entity-helpers.d.ts +14 -0
- package/dist/utils/entity-helpers.d.ts.map +1 -1
- package/dist/utils/entity-helpers.js +36 -8
- package/dist/utils/entity-helpers.js.map +1 -1
- package/dist/utils/error-handlers.d.ts +6 -0
- package/dist/utils/error-handlers.d.ts.map +1 -1
- package/dist/utils/error-handlers.js +15 -3
- package/dist/utils/error-handlers.js.map +1 -1
- package/dist/utils/graph-helpers.d.ts +6 -0
- package/dist/utils/graph-helpers.d.ts.map +1 -1
- package/dist/utils/graph-helpers.js +15 -3
- package/dist/utils/graph-helpers.js.map +1 -1
- package/dist/utils/prompt-helpers.d.ts +6 -0
- package/dist/utils/prompt-helpers.d.ts.map +1 -1
- package/dist/utils/prompt-helpers.js +5 -1
- package/dist/utils/prompt-helpers.js.map +1 -1
- package/dist/utils/user-helpers.d.ts +2 -0
- package/dist/utils/user-helpers.d.ts.map +1 -1
- package/dist/utils/user-helpers.js +5 -1
- package/dist/utils/user-helpers.js.map +1 -1
- package/dist/vectors/EmbeddingService.d.ts +14 -0
- package/dist/vectors/EmbeddingService.d.ts.map +1 -1
- package/dist/vectors/EmbeddingService.js +17 -5
- package/dist/vectors/EmbeddingService.js.map +1 -1
- package/dist/vectors/SimilaritySearch.d.ts +2 -0
- package/dist/vectors/SimilaritySearch.d.ts.map +1 -1
- package/dist/vectors/SimilaritySearch.js +5 -1
- package/dist/vectors/SimilaritySearch.js.map +1 -1
- package/package.json +11 -11
- package/src/__tests__/QueryGen.test.ts +22 -22
- package/src/cli/commands/export.ts +11 -6
- package/src/cli/commands/generate.ts +20 -15
- package/src/cli/commands/validate.ts +13 -8
- package/src/cli/config.ts +6 -1
- package/src/cli/index.ts +6 -6
- package/src/core/EntityGrouper.ts +17 -9
- package/src/core/MetadataExporter.ts +10 -1
- package/src/core/QueryDatabaseWriter.ts +11 -3
- package/src/core/QueryFixer.ts +15 -5
- package/src/core/QueryRefiner.ts +18 -8
- package/src/core/QueryTester.ts +13 -5
- package/src/core/QueryWriter.ts +14 -5
- package/src/core/QuestionGenerator.ts +12 -7
- package/src/index.ts +12 -12
- package/src/utils/category-builder.ts +15 -2
- package/src/utils/entity-helpers.ts +44 -9
- package/src/utils/error-handlers.ts +22 -3
- package/src/utils/graph-helpers.ts +18 -3
- package/src/utils/prompt-helpers.ts +11 -1
- package/src/utils/user-helpers.ts +6 -1
- package/src/vectors/EmbeddingService.ts +30 -5
- package/src/vectors/SimilaritySearch.ts +10 -1
|
@@ -9,9 +9,9 @@ import { AIEngine } from '@memberjunction/aiengine';
|
|
|
9
9
|
import { MJAIPromptEntityExtended } from '@memberjunction/ai-core-plus';
|
|
10
10
|
import { UserInfo, LogStatus } from '@memberjunction/core';
|
|
11
11
|
import { QueryGenConfig } from '../cli/config';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { ExtractErrorMessage } from '../utils/error-handlers';
|
|
13
|
+
import { FormatEntityGroupForPrompt } from '../utils/entity-helpers';
|
|
14
|
+
import { ExecutePromptWithOverrides } from '../utils/prompt-helpers';
|
|
15
15
|
import { EntityGroup, BusinessQuestion } from '../data/schema';
|
|
16
16
|
import { PROMPT_BUSINESS_QUESTION_GENERATOR } from '../prompts/PromptNames';
|
|
17
17
|
|
|
@@ -39,7 +39,7 @@ export class QuestionGenerator {
|
|
|
39
39
|
* @param entityGroup - Entity group to generate questions for
|
|
40
40
|
* @returns Array of validated business questions
|
|
41
41
|
*/
|
|
42
|
-
async
|
|
42
|
+
async GenerateQuestions(entityGroup: EntityGroup): Promise<BusinessQuestion[]> {
|
|
43
43
|
try {
|
|
44
44
|
// Ensure AIEngine is configured
|
|
45
45
|
const aiEngine = AIEngine.Instance;
|
|
@@ -49,7 +49,7 @@ export class QuestionGenerator {
|
|
|
49
49
|
const prompt = this.findPromptByName(aiEngine, PROMPT_BUSINESS_QUESTION_GENERATOR);
|
|
50
50
|
|
|
51
51
|
// Format entity group for prompt
|
|
52
|
-
const entityMetadata =
|
|
52
|
+
const entityMetadata = FormatEntityGroupForPrompt(entityGroup);
|
|
53
53
|
|
|
54
54
|
// Execute AI prompt
|
|
55
55
|
const result = await this.executePrompt(prompt, entityMetadata);
|
|
@@ -75,11 +75,16 @@ export class QuestionGenerator {
|
|
|
75
75
|
return validQuestions;
|
|
76
76
|
} catch (error: unknown) {
|
|
77
77
|
throw new Error(
|
|
78
|
-
|
|
78
|
+
ExtractErrorMessage(error, 'QuestionGenerator.generateQuestions')
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/** @deprecated Use {@link GenerateQuestions}. */
|
|
84
|
+
async generateQuestions(entityGroup: EntityGroup): Promise<BusinessQuestion[]> {
|
|
85
|
+
return this.GenerateQuestions(entityGroup);
|
|
86
|
+
}
|
|
87
|
+
|
|
83
88
|
/**
|
|
84
89
|
* Find prompt by name in AIEngine cache
|
|
85
90
|
* Throws if prompt not found
|
|
@@ -103,7 +108,7 @@ export class QuestionGenerator {
|
|
|
103
108
|
prompt: MJAIPromptEntityExtended,
|
|
104
109
|
entityMetadata: unknown
|
|
105
110
|
): Promise<QuestionGeneratorResult> {
|
|
106
|
-
const result = await
|
|
111
|
+
const result = await ExecutePromptWithOverrides<QuestionGeneratorResult>(
|
|
107
112
|
prompt,
|
|
108
113
|
{ entityGroupMetadata: entityMetadata },
|
|
109
114
|
this.contextUser,
|
package/src/index.ts
CHANGED
|
@@ -28,21 +28,21 @@ export * from './data/schema';
|
|
|
28
28
|
export * from './prompts/PromptNames';
|
|
29
29
|
|
|
30
30
|
// Export configuration
|
|
31
|
-
export { QueryGenConfig, loadConfig } from './cli/config';
|
|
31
|
+
export { QueryGenConfig, LoadConfig, loadConfig } from './cli/config';
|
|
32
32
|
|
|
33
33
|
// Export CLI commands
|
|
34
|
-
export { generateCommand } from './cli/commands/generate';
|
|
35
|
-
export { validateCommand } from './cli/commands/validate';
|
|
36
|
-
export { exportCommand } from './cli/commands/export';
|
|
34
|
+
export { GenerateCommand, generateCommand } from './cli/commands/generate';
|
|
35
|
+
export { ValidateCommand, validateCommand } from './cli/commands/validate';
|
|
36
|
+
export { ExportCommand, exportCommand } from './cli/commands/export';
|
|
37
37
|
|
|
38
38
|
// Export utilities
|
|
39
|
-
export { extractErrorMessage, requireValue, getPropertyOrDefault } from './utils/error-handlers';
|
|
39
|
+
export { ExtractErrorMessage, extractErrorMessage, RequireValue, requireValue, GetPropertyOrDefault, getPropertyOrDefault } from './utils/error-handlers';
|
|
40
40
|
export {
|
|
41
|
-
formatEntityMetadataForPrompt,
|
|
42
|
-
formatEntityGroupForPrompt,
|
|
43
|
-
findEntityById,
|
|
44
|
-
getPrimaryKeyFields,
|
|
45
|
-
getForeignKeyFields,
|
|
46
|
-
hasRelationships,
|
|
47
|
-
getRelationshipCount
|
|
41
|
+
FormatEntityMetadataForPrompt, formatEntityMetadataForPrompt,
|
|
42
|
+
FormatEntityGroupForPrompt, formatEntityGroupForPrompt,
|
|
43
|
+
FindEntityById, findEntityById,
|
|
44
|
+
GetPrimaryKeyFields, getPrimaryKeyFields,
|
|
45
|
+
GetForeignKeyFields, getForeignKeyFields,
|
|
46
|
+
HasRelationships, hasRelationships,
|
|
47
|
+
GetRelationshipCount, getRelationshipCount
|
|
48
48
|
} from './utils/entity-helpers';
|
|
@@ -15,7 +15,7 @@ import { QueryGenConfig } from '../cli/config';
|
|
|
15
15
|
* @param entityGroup - Entity group for the query
|
|
16
16
|
* @returns QueryCategoryInfo with full category details
|
|
17
17
|
*/
|
|
18
|
-
export function
|
|
18
|
+
export function BuildQueryCategory(
|
|
19
19
|
config: QueryGenConfig,
|
|
20
20
|
entityGroup: EntityGroup
|
|
21
21
|
): QueryCategoryInfo {
|
|
@@ -52,6 +52,14 @@ export function buildQueryCategory(
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/** @deprecated Use {@link BuildQueryCategory}. */
|
|
56
|
+
export function buildQueryCategory(
|
|
57
|
+
config: QueryGenConfig,
|
|
58
|
+
entityGroup: EntityGroup
|
|
59
|
+
): QueryCategoryInfo {
|
|
60
|
+
return BuildQueryCategory(config, entityGroup);
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
/**
|
|
56
64
|
* Extract all unique categories from validated queries
|
|
57
65
|
* Returns categories in hierarchical order (root first, then children)
|
|
@@ -62,7 +70,7 @@ export function buildQueryCategory(
|
|
|
62
70
|
* @param categories - Array of QueryCategoryInfo from validated queries
|
|
63
71
|
* @returns Unique categories sorted hierarchically (includes auto-generated parents)
|
|
64
72
|
*/
|
|
65
|
-
export function
|
|
73
|
+
export function ExtractUniqueCategories(categories: QueryCategoryInfo[]): QueryCategoryInfo[] {
|
|
66
74
|
const uniqueMap = new Map<string, QueryCategoryInfo>();
|
|
67
75
|
|
|
68
76
|
// Collect all unique categories (by path)
|
|
@@ -95,3 +103,8 @@ export function extractUniqueCategories(categories: QueryCategoryInfo[]): QueryC
|
|
|
95
103
|
|
|
96
104
|
return result;
|
|
97
105
|
}
|
|
106
|
+
|
|
107
|
+
/** @deprecated Use {@link ExtractUniqueCategories}. */
|
|
108
|
+
export function extractUniqueCategories(categories: QueryCategoryInfo[]): QueryCategoryInfo[] {
|
|
109
|
+
return ExtractUniqueCategories(categories);
|
|
110
|
+
}
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
* @param allEntities - All available entities for relationship lookups
|
|
24
24
|
* @returns Formatted entity metadata ready for AI prompts
|
|
25
25
|
*/
|
|
26
|
-
export function
|
|
26
|
+
export function FormatEntityMetadataForPrompt(entity: EntityInfo, allEntities: EntityInfo[]): EntityMetadataForPrompt {
|
|
27
27
|
return {
|
|
28
28
|
entityName: entity.Name,
|
|
29
29
|
description: entity.Description || '',
|
|
@@ -35,6 +35,11 @@ export function formatEntityMetadataForPrompt(entity: EntityInfo, allEntities: E
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** @deprecated Use {@link FormatEntityMetadataForPrompt}. */
|
|
39
|
+
export function formatEntityMetadataForPrompt(entity: EntityInfo, allEntities: EntityInfo[]): EntityMetadataForPrompt {
|
|
40
|
+
return FormatEntityMetadataForPrompt(entity, allEntities);
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
/**
|
|
39
44
|
* Format entity fields for AI prompt
|
|
40
45
|
* Includes field metadata with types, descriptions, and relationship info
|
|
@@ -91,7 +96,7 @@ function formatEntityRelationships(entity: EntityInfo, allEntities: EntityInfo[]
|
|
|
91
96
|
return entity.RelatedEntities
|
|
92
97
|
.filter(rel => entityNamesInGroup.has(rel.RelatedEntity)) // Only include relationships within the group
|
|
93
98
|
.map(rel => {
|
|
94
|
-
const relatedEntity =
|
|
99
|
+
const relatedEntity = FindEntityById(rel.RelatedEntityID, allEntities);
|
|
95
100
|
|
|
96
101
|
// Determine the foreign key field based on relationship type and available fields
|
|
97
102
|
let foreignKeyField: string;
|
|
@@ -156,40 +161,65 @@ function findEntityByName(name: string, entities: EntityInfo[]): EntityInfo | un
|
|
|
156
161
|
/**
|
|
157
162
|
* Find entity by ID in array
|
|
158
163
|
*/
|
|
159
|
-
export function
|
|
164
|
+
export function FindEntityById(id: string, entities: EntityInfo[]): EntityInfo | undefined {
|
|
160
165
|
return entities.find((e) => UUIDsEqual(e.ID, id));
|
|
161
166
|
}
|
|
162
167
|
|
|
168
|
+
/** @deprecated Use {@link FindEntityById}. */
|
|
169
|
+
export function findEntityById(id: string, entities: EntityInfo[]): EntityInfo | undefined {
|
|
170
|
+
return FindEntityById(id, entities);
|
|
171
|
+
}
|
|
172
|
+
|
|
163
173
|
/**
|
|
164
174
|
* Get primary key field(s) for an entity
|
|
165
175
|
*/
|
|
166
|
-
export function
|
|
176
|
+
export function GetPrimaryKeyFields(entity: EntityInfo): EntityFieldInfo[] {
|
|
167
177
|
return entity.Fields.filter((f) => f.IsPrimaryKey);
|
|
168
178
|
}
|
|
169
179
|
|
|
180
|
+
/** @deprecated Use {@link GetPrimaryKeyFields}. */
|
|
181
|
+
export function getPrimaryKeyFields(entity: EntityInfo): EntityFieldInfo[] {
|
|
182
|
+
return GetPrimaryKeyFields(entity);
|
|
183
|
+
}
|
|
184
|
+
|
|
170
185
|
/**
|
|
171
186
|
* Get foreign key fields for an entity
|
|
172
187
|
*/
|
|
173
|
-
export function
|
|
188
|
+
export function GetForeignKeyFields(entity: EntityInfo): EntityFieldInfo[] {
|
|
174
189
|
return entity.Fields.filter((f) => isForeignKeyField(f));
|
|
175
190
|
}
|
|
176
191
|
|
|
192
|
+
/** @deprecated Use {@link GetForeignKeyFields}. */
|
|
193
|
+
export function getForeignKeyFields(entity: EntityInfo): EntityFieldInfo[] {
|
|
194
|
+
return GetForeignKeyFields(entity);
|
|
195
|
+
}
|
|
196
|
+
|
|
177
197
|
/**
|
|
178
198
|
* Check if an entity has any relationships
|
|
179
199
|
* Uses EntityInfo.RelatedEntities getter
|
|
180
200
|
*/
|
|
181
|
-
export function
|
|
201
|
+
export function HasRelationships(entity: EntityInfo, allEntities: EntityInfo[]): boolean {
|
|
182
202
|
return entity.RelatedEntities.length > 0;
|
|
183
203
|
}
|
|
184
204
|
|
|
205
|
+
/** @deprecated Use {@link HasRelationships}. */
|
|
206
|
+
export function hasRelationships(entity: EntityInfo, allEntities: EntityInfo[]): boolean {
|
|
207
|
+
return HasRelationships(entity, allEntities);
|
|
208
|
+
}
|
|
209
|
+
|
|
185
210
|
/**
|
|
186
211
|
* Get count of relationships for an entity
|
|
187
212
|
* Uses EntityInfo.RelatedEntities getter
|
|
188
213
|
*/
|
|
189
|
-
export function
|
|
214
|
+
export function GetRelationshipCount(entity: EntityInfo, allEntities: EntityInfo[]): number {
|
|
190
215
|
return entity.RelatedEntities.length;
|
|
191
216
|
}
|
|
192
217
|
|
|
218
|
+
/** @deprecated Use {@link GetRelationshipCount}. */
|
|
219
|
+
export function getRelationshipCount(entity: EntityInfo, allEntities: EntityInfo[]): number {
|
|
220
|
+
return GetRelationshipCount(entity, allEntities);
|
|
221
|
+
}
|
|
222
|
+
|
|
193
223
|
/**
|
|
194
224
|
* Format an entire entity group for AI prompt consumption
|
|
195
225
|
* Converts all entities in the group to structured metadata
|
|
@@ -197,8 +227,13 @@ export function getRelationshipCount(entity: EntityInfo, allEntities: EntityInfo
|
|
|
197
227
|
* @param entityGroup - Entity group to format
|
|
198
228
|
* @returns Array of formatted entity metadata for Nunjucks template
|
|
199
229
|
*/
|
|
200
|
-
export function
|
|
230
|
+
export function FormatEntityGroupForPrompt(entityGroup: EntityGroup): EntityMetadataForPrompt[] {
|
|
201
231
|
return entityGroup.entities.map((entity) =>
|
|
202
|
-
|
|
232
|
+
FormatEntityMetadataForPrompt(entity, entityGroup.entities)
|
|
203
233
|
);
|
|
204
234
|
}
|
|
235
|
+
|
|
236
|
+
/** @deprecated Use {@link FormatEntityGroupForPrompt}. */
|
|
237
|
+
export function formatEntityGroupForPrompt(entityGroup: EntityGroup): EntityMetadataForPrompt[] {
|
|
238
|
+
return FormatEntityGroupForPrompt(entityGroup);
|
|
239
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Extract error message from unknown error type
|
|
9
9
|
* Uses MJ's extractErrorMessage pattern
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
11
|
+
export function ExtractErrorMessage(error: unknown, context: string): string {
|
|
12
12
|
if (error instanceof Error) {
|
|
13
13
|
return `${context}: ${error.message}`;
|
|
14
14
|
}
|
|
@@ -18,20 +18,30 @@ export function extractErrorMessage(error: unknown, context: string): string {
|
|
|
18
18
|
return `${context}: Unknown error occurred`;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** @deprecated Use {@link ExtractErrorMessage}. */
|
|
22
|
+
export function extractErrorMessage(error: unknown, context: string): string {
|
|
23
|
+
return ExtractErrorMessage(error, context);
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Validate required value is not null/undefined
|
|
23
28
|
*/
|
|
24
|
-
export function
|
|
29
|
+
export function RequireValue<T>(value: T | null | undefined, fieldName: string): T {
|
|
25
30
|
if (value === null || value === undefined) {
|
|
26
31
|
throw new Error(`Required value '${fieldName}' is missing`);
|
|
27
32
|
}
|
|
28
33
|
return value;
|
|
29
34
|
}
|
|
30
35
|
|
|
36
|
+
/** @deprecated Use {@link RequireValue}. */
|
|
37
|
+
export function requireValue<T>(value: T | null | undefined, fieldName: string): T {
|
|
38
|
+
return RequireValue(value, fieldName);
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
/**
|
|
32
42
|
* Get property with fallback value
|
|
33
43
|
*/
|
|
34
|
-
export function
|
|
44
|
+
export function GetPropertyOrDefault<T>(
|
|
35
45
|
obj: Record<string, unknown>,
|
|
36
46
|
key: string,
|
|
37
47
|
defaultValue: T
|
|
@@ -39,3 +49,12 @@ export function getPropertyOrDefault<T>(
|
|
|
39
49
|
const value = obj[key];
|
|
40
50
|
return value !== undefined ? (value as T) : defaultValue;
|
|
41
51
|
}
|
|
52
|
+
|
|
53
|
+
/** @deprecated Use {@link GetPropertyOrDefault}. */
|
|
54
|
+
export function getPropertyOrDefault<T>(
|
|
55
|
+
obj: Record<string, unknown>,
|
|
56
|
+
key: string,
|
|
57
|
+
defaultValue: T
|
|
58
|
+
): T {
|
|
59
|
+
return GetPropertyOrDefault(obj, key, defaultValue);
|
|
60
|
+
}
|
|
@@ -25,7 +25,7 @@ export interface EntityMetadataForPrompt {
|
|
|
25
25
|
* Products: → OrderDetails, → Categories
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function GenerateRelationshipGraph(entities: EntityInfo[]): string {
|
|
29
29
|
const lines: string[] = [];
|
|
30
30
|
|
|
31
31
|
for (const entity of entities) {
|
|
@@ -44,6 +44,11 @@ export function generateRelationshipGraph(entities: EntityInfo[]): string {
|
|
|
44
44
|
return lines.join('\n');
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** @deprecated Use {@link GenerateRelationshipGraph}. */
|
|
48
|
+
export function generateRelationshipGraph(entities: EntityInfo[]): string {
|
|
49
|
+
return GenerateRelationshipGraph(entities);
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
/**
|
|
48
53
|
* Generates a Mermaid diagram for richer visualization
|
|
49
54
|
*
|
|
@@ -55,7 +60,7 @@ export function generateRelationshipGraph(entities: EntityInfo[]): string {
|
|
|
55
60
|
* Orders[Orders] --> OrderDetails[OrderDetails]
|
|
56
61
|
* ```
|
|
57
62
|
*/
|
|
58
|
-
export function
|
|
63
|
+
export function GenerateMermaidDiagram(entities: EntityInfo[]): string {
|
|
59
64
|
const lines = ['graph LR'];
|
|
60
65
|
const processedPairs = new Set<string>();
|
|
61
66
|
|
|
@@ -76,6 +81,11 @@ export function generateMermaidDiagram(entities: EntityInfo[]): string {
|
|
|
76
81
|
return lines.join('\n');
|
|
77
82
|
}
|
|
78
83
|
|
|
84
|
+
/** @deprecated Use {@link GenerateMermaidDiagram}. */
|
|
85
|
+
export function generateMermaidDiagram(entities: EntityInfo[]): string {
|
|
86
|
+
return GenerateMermaidDiagram(entities);
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
/**
|
|
80
90
|
* Formats entity metadata for LLM prompt (concise version with key info)
|
|
81
91
|
*
|
|
@@ -85,7 +95,7 @@ export function generateMermaidDiagram(entities: EntityInfo[]): string {
|
|
|
85
95
|
* - Field count (as a proxy for data richness)
|
|
86
96
|
* - Related entities with relationship types
|
|
87
97
|
*/
|
|
88
|
-
export function
|
|
98
|
+
export function FormatEntitiesForPrompt(entities: EntityInfo[]): EntityMetadataForPrompt[] {
|
|
89
99
|
return entities.map(entity => ({
|
|
90
100
|
Name: entity.Name,
|
|
91
101
|
Description: entity.Description || 'No description available',
|
|
@@ -97,3 +107,8 @@ export function formatEntitiesForPrompt(entities: EntityInfo[]): EntityMetadataF
|
|
|
97
107
|
}))
|
|
98
108
|
}));
|
|
99
109
|
}
|
|
110
|
+
|
|
111
|
+
/** @deprecated Use {@link FormatEntitiesForPrompt}. */
|
|
112
|
+
export function formatEntitiesForPrompt(entities: EntityInfo[]): EntityMetadataForPrompt[] {
|
|
113
|
+
return FormatEntitiesForPrompt(entities);
|
|
114
|
+
}
|
|
@@ -22,7 +22,7 @@ import { QueryGenConfig } from '../cli/config';
|
|
|
22
22
|
* @param config - QueryGen configuration (for model/vendor overrides)
|
|
23
23
|
* @returns Promise resolving to the prompt result
|
|
24
24
|
*/
|
|
25
|
-
export async function
|
|
25
|
+
export async function ExecutePromptWithOverrides<T>(
|
|
26
26
|
prompt: MJAIPromptEntityExtended,
|
|
27
27
|
data: Record<string, unknown>,
|
|
28
28
|
contextUser: UserInfo,
|
|
@@ -46,6 +46,16 @@ export async function executePromptWithOverrides<T>(
|
|
|
46
46
|
return await runner.ExecutePrompt<T>(promptParams);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** @deprecated Use {@link ExecutePromptWithOverrides}. */
|
|
50
|
+
export async function executePromptWithOverrides<T>(
|
|
51
|
+
prompt: MJAIPromptEntityExtended,
|
|
52
|
+
data: Record<string, unknown>,
|
|
53
|
+
contextUser: UserInfo,
|
|
54
|
+
config: QueryGenConfig
|
|
55
|
+
): Promise<{ success: boolean; result?: T; errorMessage?: string }> {
|
|
56
|
+
return ExecutePromptWithOverrides(prompt, data, contextUser, config);
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
/**
|
|
50
60
|
* Resolve model/vendor names to IDs for AIPromptParams.override
|
|
51
61
|
*
|
|
@@ -14,7 +14,7 @@ import { UserCache } from '@memberjunction/generic-database-provider';
|
|
|
14
14
|
* @returns The System UserInfo object from the cache
|
|
15
15
|
* @throws Error if System user is not found in cache or doesn't have Developer role
|
|
16
16
|
*/
|
|
17
|
-
export function
|
|
17
|
+
export function GetSystemUser(): UserInfo {
|
|
18
18
|
const sysUser = UserCache.Instance.UserByName("System", false);
|
|
19
19
|
if (!sysUser) {
|
|
20
20
|
throw new Error(
|
|
@@ -37,3 +37,8 @@ export function getSystemUser(): UserInfo {
|
|
|
37
37
|
|
|
38
38
|
return sysUser;
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
/** @deprecated Use {@link GetSystemUser}. */
|
|
42
|
+
export function getSystemUser(): UserInfo {
|
|
43
|
+
return GetSystemUser();
|
|
44
|
+
}
|
|
@@ -34,7 +34,7 @@ export class EmbeddingService {
|
|
|
34
34
|
* @param query - Query to embed (partial structure with text fields)
|
|
35
35
|
* @returns Embeddings for all fields
|
|
36
36
|
*/
|
|
37
|
-
async
|
|
37
|
+
async EmbedQuery(query: {
|
|
38
38
|
userQuestion: string;
|
|
39
39
|
description: string;
|
|
40
40
|
technicalDescription: string;
|
|
@@ -55,6 +55,15 @@ export class EmbeddingService {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** @deprecated Use {@link EmbedQuery}. */
|
|
59
|
+
async embedQuery(query: {
|
|
60
|
+
userQuestion: string;
|
|
61
|
+
description: string;
|
|
62
|
+
technicalDescription: string;
|
|
63
|
+
}): Promise<QueryEmbeddings> {
|
|
64
|
+
return this.EmbedQuery(query);
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
/**
|
|
59
68
|
* Embed all golden queries for few-shot learning
|
|
60
69
|
*
|
|
@@ -65,11 +74,11 @@ export class EmbeddingService {
|
|
|
65
74
|
* @param goldenQueries - Array of golden queries to embed
|
|
66
75
|
* @returns Array of golden queries with their embeddings
|
|
67
76
|
*/
|
|
68
|
-
async
|
|
77
|
+
async EmbedGoldenQueries(goldenQueries: GoldenQuery[]): Promise<EmbeddedGoldenQuery[]> {
|
|
69
78
|
const embedded: EmbeddedGoldenQuery[] = [];
|
|
70
79
|
|
|
71
80
|
for (const query of goldenQueries) {
|
|
72
|
-
const embeddings = await this.
|
|
81
|
+
const embeddings = await this.EmbedQuery({
|
|
73
82
|
userQuestion: query.userQuestion,
|
|
74
83
|
description: query.description,
|
|
75
84
|
technicalDescription: query.technicalDescription,
|
|
@@ -84,13 +93,18 @@ export class EmbeddingService {
|
|
|
84
93
|
return embedded;
|
|
85
94
|
}
|
|
86
95
|
|
|
96
|
+
/** @deprecated Use {@link EmbedGoldenQueries}. */
|
|
97
|
+
async embedGoldenQueries(goldenQueries: GoldenQuery[]): Promise<EmbeddedGoldenQuery[]> {
|
|
98
|
+
return this.EmbedGoldenQueries(goldenQueries);
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
/**
|
|
88
102
|
* Embed multiple queries in batch
|
|
89
103
|
*
|
|
90
104
|
* @param queries - Array of queries to embed
|
|
91
105
|
* @returns Array of embeddings corresponding to input queries
|
|
92
106
|
*/
|
|
93
|
-
async
|
|
107
|
+
async EmbedQueries(
|
|
94
108
|
queries: Array<{
|
|
95
109
|
userQuestion: string;
|
|
96
110
|
description: string;
|
|
@@ -100,10 +114,21 @@ export class EmbeddingService {
|
|
|
100
114
|
const embeddings: QueryEmbeddings[] = [];
|
|
101
115
|
|
|
102
116
|
for (const query of queries) {
|
|
103
|
-
const embedding = await this.
|
|
117
|
+
const embedding = await this.EmbedQuery(query);
|
|
104
118
|
embeddings.push(embedding);
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
return embeddings;
|
|
108
122
|
}
|
|
123
|
+
|
|
124
|
+
/** @deprecated Use {@link EmbedQueries}. */
|
|
125
|
+
async embedQueries(
|
|
126
|
+
queries: Array<{
|
|
127
|
+
userQuestion: string;
|
|
128
|
+
description: string;
|
|
129
|
+
technicalDescription: string;
|
|
130
|
+
}>
|
|
131
|
+
): Promise<QueryEmbeddings[]> {
|
|
132
|
+
return this.EmbedQueries(queries);
|
|
133
|
+
}
|
|
109
134
|
}
|
|
@@ -49,7 +49,7 @@ export class SimilaritySearch extends SimpleVectorService {
|
|
|
49
49
|
* @param topK - Number of most similar queries to return (default: 5)
|
|
50
50
|
* @returns Array of top-K most similar golden queries with scores
|
|
51
51
|
*/
|
|
52
|
-
async
|
|
52
|
+
async FindSimilarQueries(
|
|
53
53
|
queryEmbeddings: QueryEmbeddings,
|
|
54
54
|
goldenEmbeddings: EmbeddedGoldenQuery[],
|
|
55
55
|
topK: number = 5
|
|
@@ -70,6 +70,15 @@ export class SimilaritySearch extends SimpleVectorService {
|
|
|
70
70
|
return this.selectTopK(similarities, topK);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/** @deprecated Use {@link FindSimilarQueries}. */
|
|
74
|
+
async findSimilarQueries(
|
|
75
|
+
queryEmbeddings: QueryEmbeddings,
|
|
76
|
+
goldenEmbeddings: EmbeddedGoldenQuery[],
|
|
77
|
+
topK: number = 5
|
|
78
|
+
): Promise<SimilarQuery[]> {
|
|
79
|
+
return this.FindSimilarQueries(queryEmbeddings, goldenEmbeddings, topK);
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
/**
|
|
74
83
|
* Calculate cosine similarity for each field separately
|
|
75
84
|
* Note: name field excluded as queries don't have names during generation
|