@memberjunction/ai-vector-sync 2.0.0 → 2.1.0
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/index.d.ts +73 -220
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EmbedTextsResult, Embeddings } from '@memberjunction/ai';
|
|
1
|
+
import { Embeddings, EmbedTextsResult } from '@memberjunction/ai';
|
|
3
2
|
import { VectorDBBase } from '@memberjunction/ai-vectordb';
|
|
4
|
-
import {
|
|
3
|
+
import { BaseEntity, RunViewParams, UserInfo, EntityField, EntityInfo } from '@memberjunction/core';
|
|
5
4
|
import { TemplateEntityExtended } from '@memberjunction/templates-base-types';
|
|
6
|
-
|
|
7
|
-
type VectorSyncRequest = {
|
|
8
|
-
entityID: string;
|
|
9
|
-
entityDocumentID?: string;
|
|
10
|
-
batchCount?: number;
|
|
11
|
-
options?: any;
|
|
12
|
-
};
|
|
13
|
-
type vectorSyncResponse = {
|
|
14
|
-
success: boolean;
|
|
15
|
-
status: string;
|
|
16
|
-
errorMessage: string;
|
|
17
|
-
};
|
|
18
|
-
type EmbeddingData = {
|
|
19
|
-
ID: number;
|
|
20
|
-
Vector: number[];
|
|
21
|
-
VectorID?: unknown;
|
|
22
|
-
EntityData: Record<string, any>;
|
|
23
|
-
__mj_recordID: unknown;
|
|
24
|
-
__mj_compositeKey?: unknown;
|
|
25
|
-
EntityDocument?: Record<string, unknown>;
|
|
26
|
-
TemplateContent?: string;
|
|
27
|
-
VectorIndexID?: unknown;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type EntitySyncConfig = {
|
|
31
|
-
EntityDocumentID: string;
|
|
32
|
-
Interval: number;
|
|
33
|
-
RunViewParams: RunViewParams;
|
|
34
|
-
IncludeInSync: boolean;
|
|
35
|
-
LastRunDate: string;
|
|
36
|
-
VectorIndexID: number;
|
|
37
|
-
VectorID: number;
|
|
38
|
-
};
|
|
5
|
+
import { VectorBase } from '@memberjunction/ai-vectors';
|
|
39
6
|
|
|
40
7
|
/**
|
|
41
8
|
* AI Models - strongly typed entity sub-class
|
|
42
9
|
* * Schema: __mj
|
|
43
10
|
* * Base Table: AIModel
|
|
44
11
|
* * Base View: vwAIModels
|
|
45
|
-
* * @description Catalog of all AI Models configured in the system
|
|
12
|
+
* * @description Catalog of all AI Models configured in the system.
|
|
46
13
|
* * Primary Key: ID
|
|
47
14
|
* @extends {BaseEntity}
|
|
48
15
|
* @class
|
|
@@ -298,6 +265,27 @@ declare class EntityDocumentEntity extends BaseEntity {
|
|
|
298
265
|
* * SQL Data Type: nvarchar(255)
|
|
299
266
|
*/
|
|
300
267
|
get Entity(): string;
|
|
268
|
+
/**
|
|
269
|
+
* * Field Name: VectorDatabase
|
|
270
|
+
* * Display Name: Vector Database
|
|
271
|
+
* * SQL Data Type: nvarchar(100)
|
|
272
|
+
* * Default Value: null
|
|
273
|
+
*/
|
|
274
|
+
get VectorDatabase(): string;
|
|
275
|
+
/**
|
|
276
|
+
* * Field Name: Template
|
|
277
|
+
* * Display Name: Template
|
|
278
|
+
* * SQL Data Type: nvarchar(255)
|
|
279
|
+
* * Default Value: null
|
|
280
|
+
*/
|
|
281
|
+
get Template(): string;
|
|
282
|
+
/**
|
|
283
|
+
* * Field Name: AIModel
|
|
284
|
+
* * Display Name: AIModel
|
|
285
|
+
* * SQL Data Type: nvarchar(50)
|
|
286
|
+
* * Default Value: null
|
|
287
|
+
*/
|
|
288
|
+
get AIModel(): string;
|
|
301
289
|
}
|
|
302
290
|
/**
|
|
303
291
|
* Template Contents - strongly typed entity sub-class
|
|
@@ -407,169 +395,6 @@ declare class TemplateContentEntity extends BaseEntity {
|
|
|
407
395
|
*/
|
|
408
396
|
get Type(): string;
|
|
409
397
|
}
|
|
410
|
-
/**
|
|
411
|
-
* Template Params - strongly typed entity sub-class
|
|
412
|
-
* * Schema: __mj
|
|
413
|
-
* * Base Table: TemplateParam
|
|
414
|
-
* * Base View: vwTemplateParams
|
|
415
|
-
* * @description Parameters allowed for use inside the template
|
|
416
|
-
* * Primary Key: ID
|
|
417
|
-
* @extends {BaseEntity}
|
|
418
|
-
* @class
|
|
419
|
-
* @public
|
|
420
|
-
*/
|
|
421
|
-
declare class TemplateParamEntity extends BaseEntity {
|
|
422
|
-
/**
|
|
423
|
-
* Loads the Template Params record from the database
|
|
424
|
-
* @param ID: string - primary key value to load the Template Params record.
|
|
425
|
-
* @param EntityRelationshipsToLoad - (optional) the relationships to load
|
|
426
|
-
* @returns {Promise<boolean>} - true if successful, false otherwise
|
|
427
|
-
* @public
|
|
428
|
-
* @async
|
|
429
|
-
* @memberof TemplateParamEntity
|
|
430
|
-
* @method
|
|
431
|
-
* @override
|
|
432
|
-
*/
|
|
433
|
-
Load(ID: string, EntityRelationshipsToLoad?: string[]): Promise<boolean>;
|
|
434
|
-
/**
|
|
435
|
-
* Template Params - AllowDeleteAPI is set to 0 in the database. Delete is not allowed, so this method is generated to override the base class method and throw an error. To enable delete for this entity, set AllowDeleteAPI to 1 in the database.
|
|
436
|
-
* @public
|
|
437
|
-
* @method
|
|
438
|
-
* @override
|
|
439
|
-
* @memberof TemplateParamEntity
|
|
440
|
-
* @throws {Error} - Delete is not allowed for Template Params, to enable it set AllowDeleteAPI to 1 in the database.
|
|
441
|
-
*/
|
|
442
|
-
Delete(): Promise<boolean>;
|
|
443
|
-
/**
|
|
444
|
-
* * Field Name: ID
|
|
445
|
-
* * Display Name: ID
|
|
446
|
-
* * SQL Data Type: uniqueidentifier
|
|
447
|
-
* * Default Value: newsequentialid()
|
|
448
|
-
*/
|
|
449
|
-
get ID(): string;
|
|
450
|
-
/**
|
|
451
|
-
* * Field Name: TemplateID
|
|
452
|
-
* * Display Name: Template ID
|
|
453
|
-
* * SQL Data Type: uniqueidentifier
|
|
454
|
-
* * Related Entity/Foreign Key: Templates (vwTemplates.ID)
|
|
455
|
-
*/
|
|
456
|
-
get TemplateID(): string;
|
|
457
|
-
set TemplateID(value: string);
|
|
458
|
-
/**
|
|
459
|
-
* * Field Name: Name
|
|
460
|
-
* * Display Name: Name
|
|
461
|
-
* * SQL Data Type: nvarchar(255)
|
|
462
|
-
* * Description: Name of the parameter
|
|
463
|
-
*/
|
|
464
|
-
get Name(): string;
|
|
465
|
-
set Name(value: string);
|
|
466
|
-
/**
|
|
467
|
-
* * Field Name: Description
|
|
468
|
-
* * Display Name: Description
|
|
469
|
-
* * SQL Data Type: nvarchar(MAX)
|
|
470
|
-
* * Description: Description of the parameter
|
|
471
|
-
*/
|
|
472
|
-
get Description(): string | null;
|
|
473
|
-
set Description(value: string | null);
|
|
474
|
-
/**
|
|
475
|
-
* * Field Name: Type
|
|
476
|
-
* * Display Name: Type
|
|
477
|
-
* * SQL Data Type: nvarchar(20)
|
|
478
|
-
* * Default Value: Scalar
|
|
479
|
-
* * Value List Type: List
|
|
480
|
-
* * Possible Values
|
|
481
|
-
* * Scalar
|
|
482
|
-
* * Array
|
|
483
|
-
* * Object
|
|
484
|
-
* * Record
|
|
485
|
-
* * Entity
|
|
486
|
-
* * Description: Type of the parameter - Record is an individual record within the entity specified by EntityID. Entity means an entire Entity or an entity filtered by the LinkedParameterName/Field attributes and/or ExtraFilter. Object is any valid JSON object. Array and Scalar have their common meanings.
|
|
487
|
-
*/
|
|
488
|
-
get Type(): 'Scalar' | 'Array' | 'Object' | 'Record' | 'Entity';
|
|
489
|
-
set Type(value: 'Scalar' | 'Array' | 'Object' | 'Record' | 'Entity');
|
|
490
|
-
/**
|
|
491
|
-
* * Field Name: DefaultValue
|
|
492
|
-
* * Display Name: Default Value
|
|
493
|
-
* * SQL Data Type: nvarchar(MAX)
|
|
494
|
-
* * Description: Default value of the parameter
|
|
495
|
-
*/
|
|
496
|
-
get DefaultValue(): string | null;
|
|
497
|
-
set DefaultValue(value: string | null);
|
|
498
|
-
/**
|
|
499
|
-
* * Field Name: IsRequired
|
|
500
|
-
* * Display Name: Is Required
|
|
501
|
-
* * SQL Data Type: bit
|
|
502
|
-
* * Default Value: 0
|
|
503
|
-
*/
|
|
504
|
-
get IsRequired(): boolean;
|
|
505
|
-
set IsRequired(value: boolean);
|
|
506
|
-
/**
|
|
507
|
-
* * Field Name: LinkedParameterName
|
|
508
|
-
* * Display Name: Linked Parameter Name
|
|
509
|
-
* * SQL Data Type: nvarchar(255)
|
|
510
|
-
* * Description: Only used when Type=Entity, this is used to link an Entity parameter with another parameter so that the rows in the Entity parameter can be filtered automatically based on the FKEY relationship between the Record and this Entity parameter. For example, if the Entity-based parameter is for an entity like Activities and there is another parameter of type Record for an entity like Contacts, in that situation the Activities Parameter would point to the Contacts parameter as the LinkedParameterName because we would filter down the Activities in each template render to only those linked to the Contact.
|
|
511
|
-
*/
|
|
512
|
-
get LinkedParameterName(): string | null;
|
|
513
|
-
set LinkedParameterName(value: string | null);
|
|
514
|
-
/**
|
|
515
|
-
* * Field Name: LinkedParameterField
|
|
516
|
-
* * Display Name: Linked Parameter Field
|
|
517
|
-
* * SQL Data Type: nvarchar(500)
|
|
518
|
-
* * Description: If the LinkedParameterName is specified, this is an optional setting to specify the field within the LinkedParameter that will be used for filtering. This is only needed if there is more than one foreign key relationship between the Entity parameter and the Linked parameter, or if there is no defined foreign key in the database between the two entities.
|
|
519
|
-
*/
|
|
520
|
-
get LinkedParameterField(): string | null;
|
|
521
|
-
set LinkedParameterField(value: string | null);
|
|
522
|
-
/**
|
|
523
|
-
* * Field Name: ExtraFilter
|
|
524
|
-
* * Display Name: Extra Filter
|
|
525
|
-
* * SQL Data Type: nvarchar(MAX)
|
|
526
|
-
* * Description: Only used when Type = Entity, used to specify an optional filter to reduce the set of rows that are returned for each of the templates being rendered.
|
|
527
|
-
*/
|
|
528
|
-
get ExtraFilter(): string | null;
|
|
529
|
-
set ExtraFilter(value: string | null);
|
|
530
|
-
/**
|
|
531
|
-
* * Field Name: EntityID
|
|
532
|
-
* * Display Name: Entity ID
|
|
533
|
-
* * SQL Data Type: uniqueidentifier
|
|
534
|
-
* * Related Entity/Foreign Key: Entities (vwEntities.ID)
|
|
535
|
-
*/
|
|
536
|
-
get EntityID(): string | null;
|
|
537
|
-
set EntityID(value: string | null);
|
|
538
|
-
/**
|
|
539
|
-
* * Field Name: RecordID
|
|
540
|
-
* * Display Name: Record ID
|
|
541
|
-
* * SQL Data Type: nvarchar(2000)
|
|
542
|
-
* * Description: Record ID, used only when Type is Record and a specific hardcoded record ID is desired, this is an uncommon use case, helpful for pulling in static types and metadata in some cases.
|
|
543
|
-
*/
|
|
544
|
-
get RecordID(): string | null;
|
|
545
|
-
set RecordID(value: string | null);
|
|
546
|
-
/**
|
|
547
|
-
* * Field Name: __mj_CreatedAt
|
|
548
|
-
* * Display Name: Created At
|
|
549
|
-
* * SQL Data Type: datetimeoffset
|
|
550
|
-
* * Default Value: getutcdate()
|
|
551
|
-
*/
|
|
552
|
-
get __mj_CreatedAt(): Date;
|
|
553
|
-
/**
|
|
554
|
-
* * Field Name: __mj_UpdatedAt
|
|
555
|
-
* * Display Name: Updated At
|
|
556
|
-
* * SQL Data Type: datetimeoffset
|
|
557
|
-
* * Default Value: getutcdate()
|
|
558
|
-
*/
|
|
559
|
-
get __mj_UpdatedAt(): Date;
|
|
560
|
-
/**
|
|
561
|
-
* * Field Name: Template
|
|
562
|
-
* * Display Name: Template
|
|
563
|
-
* * SQL Data Type: nvarchar(255)
|
|
564
|
-
*/
|
|
565
|
-
get Template(): string;
|
|
566
|
-
/**
|
|
567
|
-
* * Field Name: Entity
|
|
568
|
-
* * Display Name: Entity
|
|
569
|
-
* * SQL Data Type: nvarchar(255)
|
|
570
|
-
*/
|
|
571
|
-
get Entity(): string | null;
|
|
572
|
-
}
|
|
573
398
|
/**
|
|
574
399
|
* Templates - strongly typed entity sub-class
|
|
575
400
|
* * Schema: __mj
|
|
@@ -785,6 +610,36 @@ declare class VectorDatabaseEntity extends BaseEntity {
|
|
|
785
610
|
get __mj_UpdatedAt(): Date;
|
|
786
611
|
}
|
|
787
612
|
|
|
613
|
+
type VectorizeEntityParams = {
|
|
614
|
+
entityID: string;
|
|
615
|
+
entityDocumentID?: string;
|
|
616
|
+
batchCount?: number;
|
|
617
|
+
options?: any;
|
|
618
|
+
};
|
|
619
|
+
type VectorizeEntityResponse = {
|
|
620
|
+
success: boolean;
|
|
621
|
+
status: string;
|
|
622
|
+
errorMessage: string;
|
|
623
|
+
};
|
|
624
|
+
type EmbeddingData = {
|
|
625
|
+
ID: number;
|
|
626
|
+
Vector: number[];
|
|
627
|
+
VectorID?: unknown;
|
|
628
|
+
EntityData: Record<string, any>;
|
|
629
|
+
__mj_recordID: unknown;
|
|
630
|
+
__mj_compositeKey?: unknown;
|
|
631
|
+
EntityDocument?: Record<string, unknown>;
|
|
632
|
+
TemplateContent?: string;
|
|
633
|
+
VectorIndexID?: unknown;
|
|
634
|
+
};
|
|
635
|
+
type VectorEmeddingData = {
|
|
636
|
+
embedding: Embeddings;
|
|
637
|
+
vectorDB: VectorDBBase;
|
|
638
|
+
vectorDBClassKey: string;
|
|
639
|
+
vectorDBAPIKey: string;
|
|
640
|
+
embeddingDriverClass: string;
|
|
641
|
+
embeddingAPIKey: string;
|
|
642
|
+
};
|
|
788
643
|
type AnnotateWorkerContext = {
|
|
789
644
|
executionId: number;
|
|
790
645
|
entity: BaseEntity;
|
|
@@ -807,40 +662,38 @@ type ArchiveWorkerContext = {
|
|
|
807
662
|
};
|
|
808
663
|
type TemplateParamData = {
|
|
809
664
|
ParamName: string;
|
|
810
|
-
Data:
|
|
665
|
+
Data: unknown[];
|
|
811
666
|
};
|
|
667
|
+
|
|
668
|
+
type EntitySyncConfig = {
|
|
669
|
+
EntityDocumentID: string;
|
|
670
|
+
Interval: number;
|
|
671
|
+
RunViewParams: RunViewParams;
|
|
672
|
+
IncludeInSync: boolean;
|
|
673
|
+
LastRunDate: string;
|
|
674
|
+
VectorIndexID: number;
|
|
675
|
+
VectorID: number;
|
|
676
|
+
};
|
|
677
|
+
|
|
812
678
|
declare class EntityVectorSyncer extends VectorBase {
|
|
813
679
|
_startTime: Date;
|
|
814
680
|
_endTime: Date;
|
|
815
681
|
constructor();
|
|
816
|
-
Config(contextUser?: UserInfo): Promise<void>;
|
|
817
|
-
VectorizeEntity(
|
|
682
|
+
Config(forceRefresh: boolean, contextUser?: UserInfo): Promise<void>;
|
|
683
|
+
VectorizeEntity(params: VectorizeEntityParams, contextUser?: UserInfo): Promise<VectorizeEntityResponse>;
|
|
818
684
|
CreateDefaultEntityDocument(EntityID: string, VectorDatabase: VectorDatabaseEntity, AIModel: AIModelEntity): Promise<EntityDocumentEntity>;
|
|
819
|
-
protected GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(entityDocumentID: string, createDocumentIfNotFound?: boolean): Promise<
|
|
820
|
-
embedding: Embeddings;
|
|
821
|
-
vectorDB: VectorDBBase;
|
|
822
|
-
vectorDBClassKey: string;
|
|
823
|
-
vectorDBAPIKey: string;
|
|
824
|
-
embeddingDriverClass: string;
|
|
825
|
-
embeddingAPIKey: string;
|
|
826
|
-
}>;
|
|
685
|
+
protected GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(entityDocumentID: string, createDocumentIfNotFound?: boolean): Promise<VectorEmeddingData>;
|
|
827
686
|
GetEntityDocument(EntityDocumentID: string): Promise<EntityDocumentEntity | null>;
|
|
828
687
|
GetEntityDocumentByName(EntityDocumentName: string, ContextUser?: UserInfo): Promise<EntityDocumentEntity | null>;
|
|
829
|
-
GetFirstActiveEntityDocumentForEntity(entityID: string): Promise<EntityDocumentEntity | null>;
|
|
830
688
|
GetActiveEntityDocuments(entityNames?: string[]): Promise<EntityDocumentEntity[]>;
|
|
831
689
|
private GetOrCreateVectorIndex;
|
|
832
690
|
protected CreateTemplateForEntityDocument(entityDocument: EntityDocumentEntity): Promise<TemplateEntity>;
|
|
833
691
|
protected BuildTemplateContent(entityFields: EntityField[]): string;
|
|
834
692
|
protected GetEntityFieldsForSimilaritySearch(entityID: string): Promise<EntityField[]>;
|
|
835
|
-
|
|
836
|
-
private convertPrimaryKeysToList;
|
|
837
|
-
private ConvertEntityFieldsToString;
|
|
838
|
-
private delay;
|
|
839
|
-
protected GetTemplateData(entity: EntityInfo, record: BaseEntity, template: TemplateEntityExtended, relatedData: TemplateParamData[]): Promise<{
|
|
693
|
+
protected GetTemplateData(entity: EntityInfo, record: unknown, template: TemplateEntityExtended, relatedData: TemplateParamData[]): Promise<{
|
|
840
694
|
[key: string]: any;
|
|
841
695
|
}>;
|
|
842
|
-
protected
|
|
843
|
-
protected GetRelatedTemplateDataForBatch(entity: EntityInfo, records: BaseEntity[], template: TemplateEntityExtended): Promise<TemplateParamData[]>;
|
|
696
|
+
protected GetRelatedTemplateDataForBatch(entity: EntityInfo, records: unknown[], template: TemplateEntityExtended): Promise<TemplateParamData[]>;
|
|
844
697
|
protected UpsertEntityRecordDocumentRecords(embeddingData: EmbeddingData, contextUser: UserInfo): Promise<void>;
|
|
845
698
|
protected ValidateTemplateContextParamAlignment(template: TemplateEntityExtended): boolean;
|
|
846
699
|
}
|
|
@@ -863,4 +716,4 @@ declare class EntityDocumentTemplateParser extends EntityDocumentTemplateParserB
|
|
|
863
716
|
protected Relationship(entityID: string, entityRecord: any, ContextUser: UserInfo, relationshipName: string, maxRows: number, entityDocumentName: string): Promise<string>;
|
|
864
717
|
}
|
|
865
718
|
|
|
866
|
-
export { type AnnotateWorkerContext, type ArchiveWorkerContext, type EmbeddingData, EntityDocumentTemplateParser, type EntitySyncConfig, EntityVectorSyncer, type TemplateParamData, type
|
|
719
|
+
export { type AnnotateWorkerContext, type ArchiveWorkerContext, type EmbeddingData, EntityDocumentTemplateParser, type EntitySyncConfig, EntityVectorSyncer, type TemplateParamData, type VectorEmeddingData, type VectorizeEntityParams, type VectorizeEntityResponse };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var M=Object.defineProperty;var f=(p,e)=>M(p,"name",{value:e,configurable:!0});var P=require("@memberjunction/ai"),K=require("@memberjunction/ai-vectordb"),U=require("@memberjunction/ai-vectors"),l=require("@memberjunction/core"),S=require("@memberjunction/global"),k=require("node:stream/promises"),N=require("node:stream"),O=require("node:worker_threads"),L=require("node:path"),$=require("@memberjunction/aiengine"),v=require("@memberjunction/templates");const B="JONATHAN - FIX THIS TO USE BaseEngine DERVIED SUB-CLASS";class x extends N.Transform{static{f(this,"BatchWorker")}_batchSize=10;_workerFile="./worker.js";_workerContext={};_concurrencyLimit=4;_running=0;_buffer=[];_queue=[];_contextUser=void 0;constructor(e={}){super({objectMode:!0}),this._batchSize=e.batchSize??this._batchSize,this._workerFile=e.workerFile??this._workerFile,this._workerContext=e.workerContext??this._workerContext,this._concurrencyLimit=e.concurrencyLimit??this._concurrencyLimit,this._contextUser=e.contextUser??this._contextUser}_next(){if(this._queue.length>0&&this._running<this._concurrencyLimit){const e=this._queue.shift();e&&e().then(()=>this._next())}}_enqueue(e){this._queue.push(e),this._next()}async _transform(e,t,r){if(this._buffer.push(e),this._buffer.length>=this._batchSize){const n=this._buffer.splice(0,this._batchSize);this._enqueue(()=>this._processBatchInWorker(n).then(()=>r()).catch(r))}else r()}async _flush(e){this._buffer.length>0&&this._enqueue(()=>this._processBatchInWorker(this._buffer)),Promise.all(this._queue).then(()=>e()).catch(e)}_processBatchInWorker(e){return new Promise((t,r)=>{this._running++;const n=new O.Worker(this._workerFile,{workerData:{batch:e,context:this._workerContext}});n.on("message",({batch:s})=>{s.forEach(a=>this.push(a)),this._running--,t()}),n.on("error",s=>{this._running--,r(s)})})}}class _{static{f(this,"EntityDocumentCache")}static _instance;_loaded=!1;_cache={};_contextUser=null;constructor(){this._cache={}}static get Instance(){return _._instance||(_._instance=new _),_._instance}get IsLoaded(){return this._loaded}Cache(){return this._cache}GetDocument(e){let t=this._cache[e];return t||l.LogStatus(`EntityDocumentCache.GetDocument: Cache miss for EntityDocumentID: ${e}`),t||null}GetDocumentByName(e){const t=e.trim().toLowerCase();let r=Object.values(this._cache).find(n=>{n.Name.trim().toLowerCase()});return r||l.LogStatus(`EntityDocumentCache.GetDocumentByName: Cache miss for EntityDocumentName: ${e}`),r||null}SetCurrentUser(e){this._contextUser=e}async Refresh(e){l.LogStatus("Refreshing Entity Document Cache"),this._cache={};const r=await new l.RunView().RunView({EntityName:"Entity Documents",ResultType:"entity_object"},e||this._contextUser);if(r&&r.Success){for(const n of r.Results)this._cache[n.ID]=n;this._loaded=!0}}}class q extends N.Readable{static{f(this,"PagedRecords")}constructor(){super({objectMode:!0})}_read(){}addPage(e){e.forEach(t=>this.push(t))}endStream(){this.push(null)}}class G extends U.VectorBase{static{f(this,"EntityVectorSyncer")}_startTime;_endTime;constructor(){super()}async Config(e){super.CurrentUser=e,await _.Instance.Refresh(e),await $.AIEngine.Instance.Config(!1,e),await v.TemplateEngineServer.Instance.Config(!1,e)}async VectorizeEntity(e,t){if(!t)throw new Error("ContextUser is required to vectorize the entity");const r=250,n=new Date().getTime();super.CurrentUser=t,await v.TemplateEngineServer.Instance.Config(!1,t);const s=await this.GetEntityDocument(e.entityDocumentID),a=await this.GetOrCreateVectorIndex(s),i=await this.GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(e.entityDocumentID),o=new l.Metadata().Entities.find(h=>h.ID===e.entityID);if(!o)throw new Error(`Entity with ID ${e.entityID} not found.`);const u=v.TemplateEngineServer.Instance.Templates.find(h=>h.ID===s.TemplateID);if(!u)throw new Error(`Template not found with ID ${s.TemplateID}`);if(u.Content.length===0)throw new Error(`Template ${u.ID} does not have an associated Template Content record`);if(u.Content.length>1)throw new Error("Templates used by Entity Documents should only have one associated Template Content record.");this.ValidateTemplateContextParamAlignment(u);const d=15,m=new q;let y={...u.GetAll(),Params:u.Params.map(h=>h.GetAll())};const D={executionId:Date.now(),entity:o,entityDocument:s.GetAll(),template:y,templateContent:u.Content[0].GetAll(),vectorDBClassKey:i.vectorDBClassKey,vectorDBAPIKey:i.vectorDBAPIKey,embeddingDriverClass:i.embeddingDriverClass,embeddingAPIKey:i.embeddingAPIKey,delayTimeMS:r},E=new x({workerFile:L.resolve(__dirname,"workers/VectorizeTemplates.js"),batchSize:3,concurrencyLimit:2,contextUser:super.CurrentUser,workerContext:D}),b=new x({workerFile:L.resolve(__dirname,"workers/UpsertVectors.js"),batchSize:4,contextUser:super.CurrentUser,workerContext:D}),R=new N.Transform({objectMode:!0,transform:(h,C,I)=>{this.UpsertEntityRecordDocumentRecords(h,super.CurrentUser).then(()=>I(null)).catch(I)}});f(async()=>{let h=0,C=!0;for(;C;){const I=await super.pageRecordsByEntityID(e.entityID,h,d),j=await this.GetRelatedTemplateDataForBatch(o,I,u),F=[];for(const V of I){const T=await this.GetTemplateData(o,V,u,j);T.__mj_recordID=V.FirstPrimaryKey.Value,T.__mj_compositeKey=V.PrimaryKey.ToConcatenatedString(),T.VectorIndexID=a.ID,T.TemplateContent=u.Content[0].TemplateText,F.push(T)}if(m.addPage(F),I.length<d){C=!1;break}h++}m.endStream()},"getData")(),console.log("Starting pipeline"),await k.pipeline(m,E,b,R,new N.PassThrough({objectMode:!0}));const w=new Date().getTime();return l.LogStatus(`Finished vectorizing ${s.Entity} entity in ${w-n} ms`),null}async CreateDefaultEntityDocument(e,t,r){const n=new l.Metadata,s=n.Entities.find(o=>o.ID===e);if(!s)throw new Error(`Entity with ID ${e} not found.`);const a=s.Fields.map(o=>`${o.Name}: \${${o.Name}}`).join(" "),i=await n.GetEntityObject("Entity Documents");if(i.NewRecord(),i.Name=`Default duplicate record Entity Document for the ${s.Name} entity using vector database ${t.Name} and AI Model ${r.Name}`,i.EntityID=e,i.TypeID=B,i.Status="Active",i.TemplateID=a,i.VectorDatabaseID=t.ID,i.AIModelID=r.ID,await this.SaveEntity(i))return i;throw new Error(`Failed to save Entity Document for ${e}`)}async GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(e,t=!1){let r=await this.GetEntityDocument(e)||await this.GetFirstActiveEntityDocumentForEntity(e);if(!r)if(t){if(!r){l.LogStatus(`No active Entity Document found for entity ${e}, creating one`);const d=this.getVectorDatabase(),m=this.getAIModel();r=await this.CreateDefaultEntityDocument(e,d,m)}}else throw new Error(`No Entity Document found for ID=${e}`);const n=this.getVectorDatabase(r.VectorDatabaseID),s=this.getAIModel(r.AIModelID),a=P.GetAIAPIKey(s.DriverClass),i=P.GetAIAPIKey(n.ClassKey);if(!a)throw Error(`No API Key found for AI Model ${s.DriverClass}`);if(!i)throw Error(`No API Key found for Vector Database ${n.ClassKey}`);const c=S.MJGlobal.Instance.ClassFactory.CreateInstance(P.Embeddings,s.DriverClass,a),o=S.MJGlobal.Instance.ClassFactory.CreateInstance(K.VectorDBBase,n.ClassKey,i);if(!c)throw Error(`Failed to create Embeddings instance for AI Model ${s.DriverClass}`);if(!o)throw Error(`Failed to create Vector Database instance for ${n.ClassKey}`);return l.LogStatus(`Using vector database ${n.Name} and AI Model ${s.Name}`),{embedding:c,vectorDB:o,vectorDBClassKey:n.ClassKey,vectorDBAPIKey:i,embeddingDriverClass:s.DriverClass,embeddingAPIKey:a}}async GetEntityDocument(e){const t=_.Instance;return t.IsLoaded||await t.Refresh(super.CurrentUser),t.GetDocument(e)}async GetEntityDocumentByName(e,t){const r=_.Instance;return r.IsLoaded||await r.Refresh(t),r.GetDocumentByName(e)}async GetFirstActiveEntityDocumentForEntity(e){const t=$.AIEngine.EntityDocumentTypes.find(n=>n.Name==="Record Duplicate");if(!t)throw new Error("Entity Document Type not found");const r=await this.runViewForSingleValue("Entity Documents",`EntityID = '${e}' AND TypeID = '${t.ID}' AND Status = 'Active'`);return r||(l.LogError(`No active Entity Document with entityID=${e} found`),null)}async GetActiveEntityDocuments(e){await $.AIEngine.Instance.Config(!1,super.CurrentUser);const t=$.AIEngine.EntityDocumentTypes.find(i=>i.Name==="Record Duplicate");if(!t)throw new Error("Entity Document Type not found");let r=`TypeID = '${t}' AND Status = 'Active' `;e&&(r+=` AND Entity IN (${e.map(i=>`'${i}'`).join(",")})`);const n=await super.RunView.RunView({EntityName:"Entity Documents",ExtraFilter:r,ResultType:"entity_object"},super.CurrentUser);if(!n.Success)throw new Error(n.ErrorMessage);let s=[],a=[];for(const i of n.Results)a.includes(i.EntityID)||(s.push(i),a.push(i.EntityID));return s}async GetOrCreateVectorIndex(e){let t=await super.runViewForSingleValue("Vector Indexes",`VectorDatabaseID = '${e.VectorDatabaseID}' AND EmbeddingModelID = '${e.AIModelID}'`);if(t)return t;l.LogStatus(`No Vector Index found for entityDocument ${e.ID}, creating one`);try{return t=await super.Metadata.GetEntityObject("Vector Indexes"),t.NewRecord(),t.VectorDatabaseID=e.VectorDatabaseID,t.EmbeddingModelID=e.AIModelID,t.Name=`Vector Index for entityDocument ${e.EntityID}`,t.Set("EntityRecordUpdatedAt",new Date),t.Set("EntityDocumentID",e.ID),t.Description=`Vector Index that uses the Vector database ${e.VectorDatabaseID} and ${e.AIModelID} as the embedding model`,await super.SaveEntity(t)?(l.LogStatus("Successfully created new Vector Index Entity"),t):(l.LogError("Error saving Vector Index Entity"),null)}catch(r){return console.error(JSON.stringify(r)),l.LogError(r),null}}async CreateTemplateForEntityDocument(e){const t=await super.Metadata.GetEntityObject("Templates");if(t.NewRecord(),t.Name=`Template for EntityDocument ${e.EntityID}`,t.Description=`The template used by EntityDocument ${e.ID}`,t.UserID=super.CurrentUser.ID,t.IsActive=!0,t.CategoryID=null,!await super.SaveEntity(t))throw l.LogError("Error saving Template Entity",void 0,t.LatestResult),new Error(t.LatestResult.Message);l.LogStatus(`Successfully created new Template Entity ${t.ID}`),await v.TemplateEngineServer.Instance.Config(!1,super.CurrentUser);const n=v.TemplateEngineServer.Instance.TemplateContentTypes.find(u=>u.Name==="Text");if(!n)throw new Error("Text template content type not found");const s=await this.GetEntityFieldsForSimilaritySearch(e.EntityID),a=await super.Metadata.GetEntityObject("Template Contents");if(a.NewRecord(),a.TemplateID=t.ID,a.TypeID=n.ID,a.Priority=1,a.IsActive=!0,a.TemplateText=this.BuildTemplateContent(s),!await super.SaveEntity(a))throw l.LogError("Error saving Template Entity",void 0,a.LatestResult),new Error(a.LatestResult.Message);l.LogStatus(`Successfully created new Template Content Entity ${a.ID}`);const c=await super.Metadata.GetEntityObject("Template Params");if(c.NewRecord(),c.TemplateID=t.ID,c.Name="Entity",c.Description="The entity object to be used in the template",c.Type="Record",c.DefaultValue=null,c.IsRequired=!0,c.LinkedParameterName=null,c.LinkedParameterField=null,c.ExtraFilter=null,c.EntityID=e.EntityID,c.RecordID=null,!await super.SaveEntity(c))throw l.LogError("Error saving Template Entity",void 0,c.LatestResult),new Error(c.LatestResult.Message);return l.LogStatus(`Successfully created new Template Param Entity ${c.ID}`),t.Content.push(a),t.Params.push(c),v.TemplateEngineServer.Instance.AddTemplate(t),t}BuildTemplateContent(e){return e.map(t=>`{{Entity.${t.Name}}}`).join(" ")}async GetEntityFieldsForSimilaritySearch(e){const t=await super.RunView.RunView({EntityName:"Entity Fields",ExtraFilter:`EntityID = '${e}' AND IsPrimaryKey = 0 AND IsUnique = 0 AND AutoIncrement = 0 and Type NOT IN ('datetimeoffset', 'datetime')`,ResultType:"entity_object"},super.CurrentUser);if(!t.Success)throw new Error(t.ErrorMessage);return t.Results}chunkArray(e,t){let r=[...e],n=[];for(;r.length;)n.push(r.splice(0,t));return n}convertPrimaryKeysToList(e){return e.map(t=>`${t.Name}=${t.Value}`)}ConvertEntityFieldsToString(e){let t={};for(const r of e.Fields)t[r.Name]=r.Value;return JSON.stringify(t)}delay=e=>new Promise(t=>setTimeout(t,e));async GetTemplateData(e,t,r,n){const s={};for(const a of r.Params)if(!s[a.Name])switch(a.Type){case"Record":s[a.Name]=t.GetAll();break;case"Entity":const i=n.find(o=>o.ParamName===a.Name);if(!i){l.LogError(`No related data found for param ${a.Name} in template ${r.ID}`);break}const c=i.Data.filter(o=>o.Get(a.LinkedParameterField)===t.Get(e.FirstPrimaryKey.Name));s[a.Name]=c.map(o=>o.GetAll());break;case"Array":case"Scalar":case"Object":l.LogError(`Unsupported parameter type ${a.Type} for parameter ${a.Name} in template ${r.ID}`);break}return s}async GetRelatedTemplateData(e,t,r){const n=r.Entity,s=r.LinkedParameterField,a=e.FirstPrimaryKey.NeedsQuotes?"'":"",i=`${s} = ${a}${t[e.FirstPrimaryKey.Name]}${a}`,c=r.ExtraFilter?`(${i}) AND (${r.ExtraFilter})`:i,o=await super.RunView.RunView({EntityName:n,ExtraFilter:c,ResultType:"entity_object"},super.CurrentUser);if(o&&o.Success){const u={ParamName:"",Data:[]};return u.ParamName=r.Name,u.Data=o.Results,u}return l.LogError(`Error getting related data for entity ${n} with filter ${c}`,void 0,o.ErrorMessage),null}async GetRelatedTemplateDataForBatch(e,t,r){const n=[];for(const s of r.Params){if(s.Type!=="Entity")continue;const a=s.Entity,i=s.LinkedParameterField,c=e.FirstPrimaryKey.NeedsQuotes?"'":"",o=`${i} in (${t.map(m=>`${c}${m[e.FirstPrimaryKey.Name]}${c}`).join(",")})`,u=s.ExtraFilter?`(${o}) AND (${s.ExtraFilter})`:o,d=await super.RunView.RunView({EntityName:a,ExtraFilter:u,ResultType:"entity_object"},super.CurrentUser);if(d&&d.Success){const m={ParamName:"",Data:[]};m.ParamName=s.Name,m.Data=d.Results,n.push(m)}else l.LogError(`Error getting related data for entity ${a} with filter ${u}`,void 0,d.ErrorMessage)}return n}async UpsertEntityRecordDocumentRecords(e,t){let r=super.Metadata,n=super.RunView;if(!await(await r.GetEntityObject("Vector Indexes",t)).Load(e.VectorIndexID.toString())){l.LogError(`Vector Index with ID ${e.VectorIndexID} not found`);return}let i=e.EntityDocument,c=i.EntityID,o=[];const u=await n.RunView({EntityName:"Entity Record Documents",ExtraFilter:`EntityID = '${c}' AND EntityDocumentID = '${i.ID}' AND RecordID in (${e.__mj_recordID})`,ResultType:"entity_object"},t);u.Success?o=u.Results:l.LogError("Error getting existing Entity Record Documents",void 0,u.ErrorMessage);let d=o.find(y=>y.RecordID.toString()===e.__mj_recordID.toString());d||(d=await r.GetEntityObject("Entity Record Documents",t),d.NewRecord()),d.EntityID=c.toString(),d.RecordID=e.__mj_recordID.toString(),d.DocumentText=e.TemplateContent,d.VectorID=e.VectorID.toString(),d.VectorJSON=JSON.stringify(e.Vector),d.VectorIndexID=e.VectorIndexID.toString(),d.EntityRecordUpdatedAt=new Date,d.EntityDocumentID=e.EntityDocument.ID.toString(),d.ContextCurrentUser=t,await d.Save()||l.LogError("Error saving Entity Record Document Entity",void 0,d.LatestResult),l.LogStatus("Upserting Entity Record Documents: Complete")}ValidateTemplateContextParamAlignment(e){const t={};for(const r of e.Params){const n=t[r.Name];if(n&&n.Type!==r.Type)throw new Error(`Parameter ${n.Name} has different types in different templates`);t[r.Name]=r}return!0}}class g{static{f(this,"EntityDocumentTemplateParserBase")}static ClearCache(){g.__cache={}}static CreateCacheKey(e,t,r){return`${e}___${t}___${r}`}static __cache={};static get _cache(){return g.__cache}async Parse(e,t,r,n){if(!n)throw new Error("ContextUser is required to parse the template");const a=new l.Metadata().Entities.find(y=>y.ID===t);if(!a)throw new Error(`Entity with ID ${t} not found.`);let i=new l.CompositeKey;i.LoadFromEntityInfoAndRecord(a,r);const c=/\$\{([^{}]+)\}/g,o=e.matchAll(c),u=Array.from(o).map(async y=>{const D=y[1],E=g.CreateCacheKey(t,i.ToString(),D);return g._cache[E]||(g._cache[E]=await this.evalSingleArgument(D,t,r,n)),{old:y[0],new:g._cache[E]}}),d=await Promise.all(u);let m=e;return d.forEach(y=>{m=m.replace(y.old,y.new)}),m}async evalSingleArgument(e,t,r,n){const s=e.match(/(\w+)\(([^)]*)\)/);if(s){const[,a,i]=s,c=i.split(",").map(o=>(o=o.trim(),o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'")?o.slice(1,-1):o));if(typeof this[a]=="function")return this[a](t,r,n,...c);throw new Error(`Function ${a} is not defined.`)}else return r[e]!==void 0?r[e]:""}}var z=Object.defineProperty,J=Object.getOwnPropertyDescriptor,W=f((p,e,t,r)=>{for(var n=r>1?void 0:r?J(e,t):e,s=p.length-1,a;s>=0;s--)(a=p[s])&&(n=(r?a(e,t,n):a(n))||n);return r&&n&&z(e,t,n),n},"__decorateClass");exports.EntityDocumentTemplateParser=class extends g{static{f(this,"EntityDocumentTemplateParser")}static CreateInstance(){return S.MJGlobal.Instance.ClassFactory.CreateInstance(exports.EntityDocumentTemplateParser)}async Relationship(e,t,r,n,s,a){const i=new l.Metadata,c=new G;c.CurrentUser=r;const o=i.Entities.find(E=>E.ID===e);if(!o)throw new Error(`Entity with ID ${e} not found.`);const u=o.RelatedEntities.find(E=>E.RelatedEntity===n);if(!u)throw new Error(`Relationship ${n} not found for entity ${o.Name}`);const d=await i.GetEntityObject(o.Name,r);let m=new l.CompositeKey;if(m.LoadFromEntityInfoAndRecord(o,t),!await d.InnerLoad(m))return l.LogError(`Failed to load entity ${o.Name} with ID ${m.ToString()}`),"";const D=await d.GetRelatedEntityDataExt(u,null,s);if(D&&D.Data)if(a&&a.trim().length>0){const E=await c.GetEntityDocumentByName(a,r);if(E){const b=exports.EntityDocumentTemplateParser.CreateInstance(),R=10,A=[];for(let w=0;w<D.Data.length;w+=R){const h=D.Data.slice(w,w+R).map(I=>b.Parse(E.Template,u.RelatedEntityID,I,r)),C=await Promise.all(h);A.push(...C)}return A.map(w=>w+`
|
|
1
|
+
"use strict";var K=Object.defineProperty;var f=(I,e)=>K(I,"name",{value:e,configurable:!0});var V=require("@memberjunction/ai"),B=require("@memberjunction/ai-vectordb"),O=require("@memberjunction/ai-vectors"),l=require("@memberjunction/core"),R=require("@memberjunction/global"),U=require("node:stream/promises"),N=require("node:stream"),q=require("node:worker_threads"),G=require("node:path"),k=require("@memberjunction/aiengine"),C=require("@memberjunction/templates");const z="JONATHAN - FIX THIS TO USE BaseEngine DERVIED SUB-CLASS";class F extends N.Transform{static{f(this,"BatchWorker")}_batchSize=10;_workerFile="./worker.js";_workerContext={};_concurrencyLimit=4;_running=0;_buffer=[];_queue=[];_contextUser=void 0;constructor(e={}){super({objectMode:!0}),this._batchSize=e.batchSize??this._batchSize,this._workerFile=e.workerFile??this._workerFile,this._workerContext=e.workerContext??this._workerContext,this._concurrencyLimit=e.concurrencyLimit??this._concurrencyLimit,this._contextUser=e.contextUser??this._contextUser}_next(){if(this._queue.length>0&&this._running<this._concurrencyLimit){const e=this._queue.shift();e&&e().then(()=>this._next())}}_enqueue(e){this._queue.push(e),this._next()}async _transform(e,t,r){if(this._buffer.push(e),this._buffer.length>=this._batchSize){const n=this._buffer.splice(0,this._batchSize);this._enqueue(()=>this._processBatchInWorker(n).then(()=>r()).catch(r))}else r()}async _flush(e){this._buffer.length>0&&this._enqueue(()=>this._processBatchInWorker(this._buffer)),Promise.all(this._queue).then(()=>e()).catch(e)}_processBatchInWorker(e){return new Promise((t,r)=>{this._running++;const n=new q.Worker(this._workerFile,{workerData:{batch:e,context:this._workerContext}});n.on("message",({batch:a})=>{a.forEach(s=>this.push(s)),this._running--,t()}),n.on("error",a=>{this._running--,r(a)})})}}class p{static{f(this,"EntityDocumentCache")}static _instance;_loaded=!1;_cache={};_typeCache={};_contextUser=null;constructor(){this._cache={},this._typeCache={}}static get Instance(){return p._instance||(p._instance=new p),p._instance}get IsLoaded(){return this._loaded}Cache(){return this._cache}TypeCache(){return this._typeCache}GetDocument(e){let t=this._cache[e];return t||l.LogStatus(`EntityDocumentCache.GetDocument: Cache miss for EntityDocumentID: ${e}`),t||null}GetFirstActiveDocumentForEntityByID(e){let t=this.GetDocumentTypeByName("Record Duplicate");return t?Object.values(this._cache).find(r=>{r.EntityID===e&&r.Status==="Active"&&(r.TypeID,t.ID)}):null}GetFirstActiveDocumentForEntityByName(e){let t=this.GetDocumentTypeByName("Record Duplicate");return t?Object.values(this._cache).find(r=>{r.Entity===e&&r.Status==="Active"&&(r.TypeID,t.ID)}):null}GetDocumentByName(e){const t=e.trim().toLowerCase();let r=Object.values(this._cache).find(n=>{n.Name.trim().toLowerCase()});return r||l.LogStatus(`EntityDocumentCache.GetDocumentByName: Cache miss for EntityDocumentName: ${e}`),r||null}GetDocumentType(e){let t=this._typeCache[e];return t||(l.LogStatus(`EntityDocumentCache.GetDocument: Cache miss for EntityDocumentID: ${e}`),null)}GetDocumentTypeByName(e){const t=e.trim().toLowerCase();let r=Object.values(this._typeCache).find(n=>n.Name.trim().toLowerCase()===t);return r||(l.LogStatus(`EntityDocumentCache.GetDocumentByName: Cache miss for EntityDocumentName: ${e}`),null)}SetCurrentUser(e){this._contextUser=e}async Refresh(e,t){if(!e&&this._loaded)return;l.LogStatus("Refreshing Entity Document Cache"),this._cache={},this._typeCache={};const n=await new l.RunView().RunViews([{EntityName:"Entity Documents",ResultType:"entity_object"},{EntityName:"Entity Document Types",ResultType:"entity_object"}],t||this._contextUser);if(n[0]&&n[0].Success)for(const a of n[0].Results)this._cache[a.ID]=a;if(n[1]&&n[1].Success)for(const a of n[1].Results)this._typeCache[a.ID]=a;this._loaded=!0}}class J extends N.Readable{static{f(this,"PagedRecords")}constructor(){super({objectMode:!0})}_read(){}addPage(e){e.forEach(t=>this.push(t))}endStream(){this.push(null)}}class j extends O.VectorBase{static{f(this,"EntityVectorSyncer")}_startTime;_endTime;constructor(){super()}async Config(e,t){super.CurrentUser=t,await p.Instance.Refresh(e,t),await k.AIEngine.Instance.Config(e,t),await C.TemplateEngineServer.Instance.Config(e,t)}async VectorizeEntity(e,t){if(!t)throw new Error("ContextUser is required to vectorize the entity");const r=250,n=new Date().getTime();super.CurrentUser=t,await C.TemplateEngineServer.Instance.Config(!1,t);const a=await this.GetEntityDocument(e.entityDocumentID),s=await this.GetOrCreateVectorIndex(a),o=await this.GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(e.entityDocumentID),i=new l.Metadata().Entities.find(E=>E.ID===e.entityID);if(!i)throw new Error(`Entity with ID ${e.entityID} not found.`);const u=C.TemplateEngineServer.Instance.Templates.find(E=>E.ID===a.TemplateID);if(!u)throw new Error(`Template not found with ID ${a.TemplateID}`);if(u.Content.length===0)throw new Error(`Template ${u.ID} does not have an associated Template Content record`);if(u.Content.length>1)throw new Error("Templates used by Entity Documents should only have one associated Template Content record.");this.ValidateTemplateContextParamAlignment(u);const d=e.batchCount||20,y=new J;let m={...u.GetAll(),Params:u.Params.map(E=>E.GetAll())};const D={executionId:Date.now(),entity:i,entityDocument:a.GetAll(),template:m,templateContent:u.Content[0].GetAll(),vectorDBClassKey:o.vectorDBClassKey,vectorDBAPIKey:o.vectorDBAPIKey,embeddingDriverClass:o.embeddingDriverClass,embeddingAPIKey:o.embeddingAPIKey,delayTimeMS:r},h=new F({workerFile:G.resolve(__dirname,"workers/VectorizeTemplates.js"),batchSize:3,concurrencyLimit:2,contextUser:super.CurrentUser,workerContext:D}),b=new F({workerFile:G.resolve(__dirname,"workers/UpsertVectors.js"),batchSize:4,contextUser:super.CurrentUser,workerContext:D}),T=new N.Transform({objectMode:!0,transform:(E,S,_)=>{this.UpsertEntityRecordDocumentRecords(E,super.CurrentUser).then(()=>_(null)).catch(_)}});f(async()=>{let E=0,S=!0;for(;S;){let _={EntityID:e.entityID,PageNumber:E,PageSize:d,ResultType:"simple"};const A=await super.PageRecordsByEntityID(_),M=await this.GetRelatedTemplateDataForBatch(i,A,u),L=[];for(const P of A){const v=await this.GetTemplateData(i,P,u,M);v.__mj_recordID=P[i.FirstPrimaryKey.Name],v.__mj_compositeKey=i.PrimaryKeys.map(x=>`${x.Name}|${P[x.Name]}`).join("||"),v.VectorIndexID=s.ID,v.TemplateContent=u.Content[0].TemplateText,L.push(v)}if(y.addPage(L),A.length<d){S=!1;break}E++}y.endStream()},"getData")(),console.log("Starting pipeline"),await U.pipeline(y,h,b,T,new N.PassThrough({objectMode:!0}));const w=new Date().getTime();return l.LogStatus(`Finished vectorizing ${a.Entity} entity in ${w-n} ms`),null}async CreateDefaultEntityDocument(e,t,r){const n=new l.Metadata,a=n.Entities.find(i=>i.ID===e);if(!a)throw new Error(`Entity with ID ${e} not found.`);const s=a.Fields.map(i=>`${i.Name}: \${${i.Name}}`).join(" "),o=await n.GetEntityObject("Entity Documents");if(o.NewRecord(),o.Name=`Default duplicate record Entity Document for the ${a.Name} entity using vector database ${t.Name} and AI Model ${r.Name}`,o.EntityID=e,o.TypeID=z,o.Status="Active",o.TemplateID=s,o.VectorDatabaseID=t.ID,o.AIModelID=r.ID,await this.SaveEntity(o))return o;throw new Error(`Failed to save Entity Document for ${e}`)}async GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(e,t){let r=p.Instance.GetDocument(e);if(!r)if(t){l.LogStatus(`No active Entity Document found for entity ${e}, creating one`);const d=this.GetVectorDatabase(),y=this.GetAIModel();r=await this.CreateDefaultEntityDocument(e,d,y)}else throw new Error(`No Entity Document found for ID=${e}`);const n=this.GetVectorDatabase(r.VectorDatabaseID),a=this.GetAIModel(r.AIModelID),s=V.GetAIAPIKey(a.DriverClass),o=V.GetAIAPIKey(n.ClassKey);if(!s)throw Error(`No API Key found for AI Model ${a.DriverClass}`);if(!o)throw Error(`No API Key found for Vector Database ${n.ClassKey}`);const c=R.MJGlobal.Instance.ClassFactory.CreateInstance(V.Embeddings,a.DriverClass,s),i=R.MJGlobal.Instance.ClassFactory.CreateInstance(B.VectorDBBase,n.ClassKey,o);if(!c)throw Error(`Failed to create Embeddings instance for AI Model ${a.DriverClass}`);if(!i)throw Error(`Failed to create Vector Database instance for ${n.ClassKey}`);return l.LogStatus(`Using vector database ${n.Name} and AI Model ${a.Name}`),{embedding:c,vectorDB:i,vectorDBClassKey:n.ClassKey,vectorDBAPIKey:o,embeddingDriverClass:a.DriverClass,embeddingAPIKey:s}}async GetEntityDocument(e){const t=p.Instance;return t.IsLoaded||await t.Refresh(!1,super.CurrentUser),t.GetDocument(e)}async GetEntityDocumentByName(e,t){const r=p.Instance;return r.IsLoaded||await r.Refresh(!1,t),r.GetDocumentByName(e)}async GetActiveEntityDocuments(e){await p.Instance.Refresh(!1,super.CurrentUser);const t=p.Instance.GetDocumentTypeByName("Record Duplicate");if(!t)throw new Error("Entity Document Type not found");let r=`TypeID = '${t.ID}' AND Status = 'Active' `;e&&e.length>0&&(r+=` AND Entity IN (${e.map(o=>`'${o}'`).join(",")})`);const n=await super.RunView.RunView({EntityName:"Entity Documents",ExtraFilter:r,ResultType:"entity_object"},super.CurrentUser);if(!n.Success)throw new Error(n.ErrorMessage);let a=[],s=[];for(const o of n.Results)s.includes(o.EntityID)||(a.push(o),s.push(o.EntityID));return a}async GetOrCreateVectorIndex(e){let t=await super.RunViewForSingleValue("Vector Indexes",`VectorDatabaseID = '${e.VectorDatabaseID}' AND EmbeddingModelID = '${e.AIModelID}'`);if(t)return t;l.LogStatus(`No Vector Index found for entityDocument ${e.ID}, creating one`);try{return t=await super.Metadata.GetEntityObject("Vector Indexes"),t.NewRecord(),t.VectorDatabaseID=e.VectorDatabaseID,t.EmbeddingModelID=e.AIModelID,t.Name=`Vector Index for entityDocument ${e.EntityID}`,t.Set("EntityRecordUpdatedAt",new Date),t.Set("EntityDocumentID",e.ID),t.Description=`Vector Index that uses the Vector database ${e.VectorDatabaseID} and ${e.AIModelID} as the embedding model`,await super.SaveEntity(t)?(l.LogStatus("Successfully created new Vector Index Entity"),t):(l.LogError("Error saving Vector Index Entity"),null)}catch(r){return console.error(JSON.stringify(r)),l.LogError(r),null}}async CreateTemplateForEntityDocument(e){const t=await super.Metadata.GetEntityObject("Templates");if(t.NewRecord(),t.Name=`Template for EntityDocument ${e.EntityID}`,t.Description=`The template used by EntityDocument ${e.ID}`,t.UserID=super.CurrentUser.ID,t.IsActive=!0,t.CategoryID=null,!await super.SaveEntity(t))throw l.LogError("Error saving Template Entity",void 0,t.LatestResult),new Error(t.LatestResult.Message);l.LogStatus(`Successfully created new Template Entity ${t.ID}`),await C.TemplateEngineServer.Instance.Config(!1,super.CurrentUser);const n=C.TemplateEngineServer.Instance.TemplateContentTypes.find(u=>u.Name==="Text");if(!n)throw new Error("Text template content type not found");const a=await this.GetEntityFieldsForSimilaritySearch(e.EntityID),s=await super.Metadata.GetEntityObject("Template Contents");if(s.NewRecord(),s.TemplateID=t.ID,s.TypeID=n.ID,s.Priority=1,s.IsActive=!0,s.TemplateText=this.BuildTemplateContent(a),!await super.SaveEntity(s))throw l.LogError("Error saving Template Entity",void 0,s.LatestResult),new Error(s.LatestResult.Message);l.LogStatus(`Successfully created new Template Content Entity ${s.ID}`);const c=await super.Metadata.GetEntityObject("Template Params");if(c.NewRecord(),c.TemplateID=t.ID,c.Name="Entity",c.Description="The entity object to be used in the template",c.Type="Record",c.DefaultValue=null,c.IsRequired=!0,c.LinkedParameterName=null,c.LinkedParameterField=null,c.ExtraFilter=null,c.EntityID=e.EntityID,c.RecordID=null,!await super.SaveEntity(c))throw l.LogError("Error saving Template Entity",void 0,c.LatestResult),new Error(c.LatestResult.Message);return l.LogStatus(`Successfully created new Template Param Entity ${c.ID}`),t.Content.push(s),t.Params.push(c),C.TemplateEngineServer.Instance.AddTemplate(t),t}BuildTemplateContent(e){return e.map(t=>`{{Entity.${t.Name}}}`).join(" ")}async GetEntityFieldsForSimilaritySearch(e){const t=await super.RunView.RunView({EntityName:"Entity Fields",ExtraFilter:`EntityID = '${e}' AND IsPrimaryKey = 0 AND IsUnique = 0 AND AutoIncrement = 0 and Type NOT IN ('datetimeoffset', 'datetime')`,ResultType:"entity_object"},super.CurrentUser);if(!t.Success)throw new Error(t.ErrorMessage);return t.Results}async GetTemplateData(e,t,r,n){const a={};for(const s of r.Params)if(!a[s.Name])switch(s.Type){case"Record":a[s.Name]=t;break;case"Entity":const o=n.find(c=>c.ParamName===s.Name);if(!o){l.LogError(`No related data found for param ${s.Name} in template ${r.ID}`);break}a[s.Name]=o.Data.filter(c=>c[s.LinkedParameterField]===t[e.FirstPrimaryKey.Name]);break;case"Array":case"Scalar":case"Object":l.LogError(`Unsupported parameter type ${s.Type} for parameter ${s.Name} in template ${r.ID}`);break}return a}async GetRelatedTemplateDataForBatch(e,t,r){const n=[];t.forEach(a=>{console.log(JSON.stringify(a,null,4)),console.log(a[e.FirstPrimaryKey.Name])});for(const a of r.Params){if(a.Type!=="Entity")continue;const s=a.Entity,o=a.LinkedParameterField,c=e.FirstPrimaryKey.NeedsQuotes?"'":"",i=`${o} in (${t.map(y=>`${c}${y[e.FirstPrimaryKey.Name]}${c}`).join(",")})`,u=a.ExtraFilter?`(${i}) AND (${a.ExtraFilter})`:i,d=await super.RunView.RunView({EntityName:s,ExtraFilter:u,ResultType:"simple"},super.CurrentUser);if(d&&d.Success){const y={ParamName:"",Data:[]};y.ParamName=a.Name,y.Data=d.Results,n.push(y)}else l.LogError(`Error getting related data for entity ${s} with filter ${u}`,void 0,d.ErrorMessage)}return n}async UpsertEntityRecordDocumentRecords(e,t){let r=super.Metadata,n=super.RunView,a=!0,s=await r.GetEntityObject("Vector Indexes",t),o=e.VectorIndexID.toString();if(!await s.Load(o)){l.LogError(`Vector Index with ID ${e.VectorIndexID} not found`);return}let i=e.EntityDocument,u=i.EntityID,d=[];const y=await n.RunView({EntityName:"Entity Record Documents",ExtraFilter:`EntityID = '${u}' AND EntityDocumentID = '${i.ID}' AND RecordID in (${e.__mj_recordID})`,ResultType:"entity_object"},t);y.Success?d=y.Results:l.LogError("Error getting existing Entity Record Documents",void 0,y.ErrorMessage);let m=d.find(h=>h.Get("RecordID").toString()===e.__mj_recordID.toString());m||(m=await r.GetEntityObject("Entity Record Documents",t),m.NewRecord()),m.Set("EntityID",u.toString()),m.Set("RecordID",e.__mj_recordID.toString()),m.Set("DocumentText",e.TemplateContent),m.Set("VectorID",e.VectorID.toString()),m.Set("VectorJSON",JSON.stringify(e.Vector)),m.Set("VectorIndexID",e.VectorIndexID.toString()),m.Set("EntityRecordUpdatedAt",new Date),m.Set("EntityDocumentID",e.EntityDocument.ID.toString()),m.ContextCurrentUser=t,await m.Save()||(l.LogError("Error saving Entity Record Document Entity",void 0,m.LatestResult),a=!1),a?l.LogStatus("Upserting Entity Record Documents: Complete"):l.LogError("Upserting Entity Record Documents: Fail")}ValidateTemplateContextParamAlignment(e){const t={};for(const r of e.Params){const n=t[r.Name];if(n&&n.Type!==r.Type)throw new Error(`Parameter ${n.Name} has different types in different templates`);t[r.Name]=r}return!0}}class g{static{f(this,"EntityDocumentTemplateParserBase")}static ClearCache(){g.__cache={}}static CreateCacheKey(e,t,r){return`${e}___${t}___${r}`}static __cache={};static get _cache(){return g.__cache}async Parse(e,t,r,n){if(!n)throw new Error("ContextUser is required to parse the template");const s=new l.Metadata().Entities.find(m=>m.ID===t);if(!s)throw new Error(`Entity with ID ${t} not found.`);let o=new l.CompositeKey;o.LoadFromEntityInfoAndRecord(s,r);const c=/\$\{([^{}]+)\}/g,i=e.matchAll(c),u=Array.from(i).map(async m=>{const D=m[1],h=g.CreateCacheKey(t,o.ToString(),D);return g._cache[h]||(g._cache[h]=await this.evalSingleArgument(D,t,r,n)),{old:m[0],new:g._cache[h]}}),d=await Promise.all(u);let y=e;return d.forEach(m=>{y=y.replace(m.old,m.new)}),y}async evalSingleArgument(e,t,r,n){const a=e.match(/(\w+)\(([^)]*)\)/);if(a){const[,s,o]=a,c=o.split(",").map(i=>(i=i.trim(),i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'")?i.slice(1,-1):i));if(typeof this[s]=="function")return this[s](t,r,n,...c);throw new Error(`Function ${s} is not defined.`)}else return r[e]!==void 0?r[e]:""}}var W=Object.defineProperty,H=Object.getOwnPropertyDescriptor,Q=f((I,e,t,r)=>{for(var n=r>1?void 0:r?H(e,t):e,a=I.length-1,s;a>=0;a--)(s=I[a])&&(n=(r?s(e,t,n):s(n))||n);return r&&n&&W(e,t,n),n},"__decorateClass");exports.EntityDocumentTemplateParser=class extends g{static{f(this,"EntityDocumentTemplateParser")}static CreateInstance(){return R.MJGlobal.Instance.ClassFactory.CreateInstance(exports.EntityDocumentTemplateParser)}async Relationship(e,t,r,n,a,s){const o=new l.Metadata,c=new j;c.CurrentUser=r;const i=o.Entities.find(h=>h.ID===e);if(!i)throw new Error(`Entity with ID ${e} not found.`);const u=i.RelatedEntities.find(h=>h.RelatedEntity===n);if(!u)throw new Error(`Relationship ${n} not found for entity ${i.Name}`);const d=await o.GetEntityObject(i.Name,r);let y=new l.CompositeKey;if(y.LoadFromEntityInfoAndRecord(i,t),!await d.InnerLoad(y))return l.LogError(`Failed to load entity ${i.Name} with ID ${y.ToString()}`),"";const D=await d.GetRelatedEntityDataExt(u,null,a);if(D&&D.Data)if(s&&s.trim().length>0){const h=await c.GetEntityDocumentByName(s,r);if(h){const b=exports.EntityDocumentTemplateParser.CreateInstance(),T=10,$=[];for(let w=0;w<D.Data.length;w+=T){const E=D.Data.slice(w,w+T).map(_=>b.Parse(h.Template,u.RelatedEntityID,_,r)),S=await Promise.all(E);$.push(...S)}return $.map(w=>w+`
|
|
2
2
|
|
|
3
|
-
`).join("")}else return l.LogStatus(`Entity Document with name ${
|
|
3
|
+
`).join("")}else return l.LogStatus(`Entity Document with name ${s} not found.`),""}else return JSON.stringify({Relationship:n,Data:D.Data});else return"{ No Data for: "+n+" }"}},exports.EntityDocumentTemplateParser=Q([R.RegisterClass(exports.EntityDocumentTemplateParser)],exports.EntityDocumentTemplateParser),exports.EntityVectorSyncer=j;
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/models/BatchWorker.ts","../src/models/EntityDocumentCache.ts","../src/models/PagedRecords.ts","../src/models/entityVectorSync.ts","../src/generic/EntityDocumenTemplateParserBase.ts","../src/generic/EntityDocumentTemplateParser.ts"],"sourcesContent":["export const RECORD_DUPLICATES_TYPE_ID = \"JONATHAN - FIX THIS TO USE BaseEngine DERVIED SUB-CLASS\";","import { UserInfo } from '@memberjunction/core';\nimport { Transform } from 'node:stream';\nimport { Worker } from 'node:worker_threads';\n\nexport type TransformCallback = Parameters<Transform['_flush']>[0];\nexport type WorkerData<TContext = Record<string, unknown>, TRecord = Record<string, unknown>> = {\n batch?: Array<TRecord>;\n context?: TContext;\n};\n\nexport type BatchWorkerOptions<TContext = Record<string, unknown>> = {\n /**\n * The number of records to process in a batch\n */\n batchSize?: number;\n /**\n * The path to the worker file used to launch a worker thread\n */\n workerFile?: string;\n /**\n * An abitrary context to pass to the worker thread\n */\n workerContext?: TContext;\n /**\n * The maximum number of worker threads to run concurrently\n */\n concurrencyLimit?: number;\n /**\n * The user context to pass to the worker thread\n */\n contextUser?: UserInfo;\n /**\n * The time to delay between api calls\n **/\n delayTimeMS?: number;\n};\n\n/**\n * This class processes records in batches using a worker thread. It expects\n * a worker file that exports a function to process the batch of records.\n * The stream operates in object mode and emits processed records.\n */\nexport class BatchWorker<TRecord = Record<string, unknown>, TContext = Record<string, unknown>> extends Transform {\n _batchSize = 10;\n _workerFile = './worker.js';\n _workerContext: TContext | Record<string, never> = {};\n _concurrencyLimit = 4;\n _running = 0;\n\n _buffer: Array<TRecord> = [];\n\n _queue: Array<() => Promise<void>> = [];\n\n _contextUser: UserInfo | undefined = undefined;\n\n /**\n * @param {BatchWorkerOptions} options - Options for the BatchWorker\n */\n constructor(options: BatchWorkerOptions<TContext> = {}) {\n super({ objectMode: true });\n this._batchSize = options.batchSize ?? this._batchSize;\n this._workerFile = options.workerFile ?? this._workerFile;\n this._workerContext = options.workerContext ?? this._workerContext;\n this._concurrencyLimit = options.concurrencyLimit ?? this._concurrencyLimit;\n this._contextUser = options.contextUser ?? this._contextUser;\n }\n\n /**\n * Starts the next task in the queue\n */\n _next() {\n if (this._queue.length > 0 && this._running < this._concurrencyLimit) {\n const task = this._queue.shift();\n task && task().then(() => this._next());\n }\n }\n\n /**\n * Enqueues a task to be processed\n * @param task - The task to enqueue\n */\n _enqueue(task: () => Promise<void>) {\n this._queue.push(task);\n this._next();\n }\n\n async _transform(chunk: TRecord, encoding: BufferEncoding, callback: TransformCallback) {\n this._buffer.push(chunk);\n if (this._buffer.length >= this._batchSize) {\n const batch = this._buffer.splice(0, this._batchSize);\n this._enqueue(() =>\n this._processBatchInWorker(batch)\n .then(() => callback())\n .catch(callback)\n );\n } else {\n callback();\n }\n }\n\n async _flush(callback: TransformCallback) {\n if (this._buffer.length > 0) {\n this._enqueue(() => this._processBatchInWorker(this._buffer));\n }\n\n Promise.all(this._queue)\n .then(() => callback())\n .catch(callback);\n }\n\n _processBatchInWorker(batch: Array<TRecord>): Promise<void> {\n return new Promise((resolve, reject) => {\n this._running++;\n const worker = new Worker(this._workerFile, { workerData: { batch, context: this._workerContext } });\n worker.on('message', ({ batch }: WorkerData<TContext, TRecord>) => {\n // Push batch rows to the stream for reading\n batch.forEach((row) => this.push(row));\n\n // Decrement _running on successful processing\n this._running--;\n resolve();\n });\n worker.on('error', (error) => {\n // Decrement _running and reject on error\n this._running--;\n reject(error);\n });\n });\n }\n}\n","import { UserInfo, RunView, LogStatus } from \"@memberjunction/core\";\nimport { EntityDocumentEntity } from \"@memberjunction/core-entities\";\n\n/**\n * Simple caching class to load all Entity Documents at once into memory\n */\nexport class EntityDocumentCache {\n private static _instance: EntityDocumentCache;\n private _loaded: boolean = false;\n private _cache: { [key: string]: EntityDocumentEntity } = {};\n private _contextUser: UserInfo | null = null;\n\n private constructor() {\n // load up the cache\n this._cache = {};\n } \n\n public static get Instance(): EntityDocumentCache {\n if(!EntityDocumentCache._instance){\n EntityDocumentCache._instance = new EntityDocumentCache();\n }\n return EntityDocumentCache._instance;\n }\n\n public get IsLoaded(): boolean {\n return this._loaded;\n }\n\n protected Cache(): { [key: string]: EntityDocumentEntity } {\n return this._cache;\n }\n\n public GetDocument(EntityDocumentID: string): EntityDocumentEntity | null {\n let document: EntityDocumentEntity = this._cache[EntityDocumentID];\n if (!document) {\n LogStatus(`EntityDocumentCache.GetDocument: Cache miss for EntityDocumentID: ${EntityDocumentID}`);\n }\n\n return document || null;\n }\n\n public GetDocumentByName(EntityDocumentName: string): EntityDocumentEntity | null {\n const toLower = EntityDocumentName.trim().toLowerCase();\n let document: EntityDocumentEntity = Object.values(this._cache).find((ed: EntityDocumentEntity) => {\n ed.Name.trim().toLowerCase() === toLower;\n });\n\n if (!document) {\n LogStatus(`EntityDocumentCache.GetDocumentByName: Cache miss for EntityDocumentName: ${EntityDocumentName}`);\n }\n\n return document || null;\n }\n\n public SetCurrentUser(user: UserInfo) {\n this._contextUser = user;\n }\n\n public async Refresh(ContextUser?: UserInfo) {\n LogStatus('Refreshing Entity Document Cache');\n this._cache = {};\n\n // now load up the cache with all the entity documents\n const rv = new RunView();\n const result = await rv.RunView({\n EntityName: \"Entity Documents\",\n ResultType: \"entity_object\"\n }, ContextUser || this._contextUser);\n\n if (result && result.Success) {\n for (const entityDocument of result.Results) {\n this._cache[entityDocument.ID] = entityDocument;\n }\n this._loaded = true;\n }\n }\n}","import { Readable } from 'node:stream';\n\n/**\n * A stream to collect pages of records and emit them as individual records\n */\nexport class PagedRecords extends Readable {\n constructor() {\n super({ objectMode: true });\n }\n\n _read() {\n // no-op\n }\n\n /**\n * Adds a page of results to the stream\n * @param {Array<Record<string,unknown>>} page - The page of results to add to the stream\n */\n addPage(page) {\n page.forEach((row) => this.push(row));\n }\n\n /**\n * Called when there are no more pages to add to the stream\n */\n endStream() {\n this.push(null);\n }\n}\n","import { Embeddings, EmbedTextsResult, GetAIAPIKey } from '@memberjunction/ai';\nimport { VectorDBBase, VectorRecord } from '@memberjunction/ai-vectordb';\nimport { VectorBase } from '@memberjunction/ai-vectors';\nimport { BaseEntity, EntityField, EntityInfo, LogError, LogStatus, Metadata, RunView, RunViewResult, UserInfo } from '@memberjunction/core';\nimport { AIModelEntity, EntityDocumentEntity, EntityDocumentTypeEntity, EntityRecordDocumentEntity, TemplateContentEntity, \n TemplateContentTypeEntity, TemplateEntity, TemplateParamEntity, VectorDatabaseEntity, VectorIndexEntity } from '@memberjunction/core-entities';\nimport { MJGlobal } from '@memberjunction/global';\nimport { pipeline } from 'node:stream/promises';\nimport { RECORD_DUPLICATES_TYPE_ID } from '../constants';\nimport { EmbeddingData, VectorSyncRequest } from '../generic/vectorSync.types';\nimport { BatchWorker } from './BatchWorker';\nimport { EntityDocumentCache } from './EntityDocumentCache';\nimport { PagedRecords } from './PagedRecords';\nimport { resolve } from 'node:path';\nimport { PassThrough, Transform } from 'node:stream';\nimport { AIEngine } from '@memberjunction/aiengine';\nimport { TemplateEngineServer } from '@memberjunction/templates';\nimport { TemplateEntityExtended } from '@memberjunction/templates-base-types';\nimport { EntityRecordDocumentWorker } from './EntityRecordDocumentWorker';\n\nexport type AnnotateWorkerContext = {\n executionId: number;\n entity: BaseEntity;\n entityDocument: Record<string, unknown>;\n template: TemplateEntityExtended;\n templateContent: TemplateContentEntity;\n embeddingDriverClass: string;\n embeddingAPIKey: string;\n delayTimeMS: number;\n};\n\nexport type ArchiveWorkerContext = {\n executionId: number;\n entity: BaseEntity;\n entityDocument: EntityDocumentEntity;\n vectorDBClassKey: string;\n vectorDBAPIKey: string;\n templateContent: TemplateContentEntity;\n embeddings: EmbedTextsResult;\n delayTimeMS: number;\n};\n\nexport type TemplateParamData = {\n ParamName: string;\n Data: BaseEntity[];\n};\n\nexport class EntityVectorSyncer extends VectorBase {\n _startTime: Date;\n _endTime: Date;\n\n constructor() {\n super();\n }\n\n public async Config(contextUser?: UserInfo): Promise<void> {\n super.CurrentUser = contextUser;\n await EntityDocumentCache.Instance.Refresh(contextUser);\n await AIEngine.Instance.Config(false, contextUser);\n await TemplateEngineServer.Instance.Config(false, contextUser);\n }\n\n public async VectorizeEntity(request: VectorSyncRequest, contextUser?: UserInfo): Promise<any> {\n if (!contextUser) {\n throw new Error('ContextUser is required to vectorize the entity');\n }\n\n //start row\n const delayTimeMS: number = 250;\n const startTime: number = new Date().getTime();\n super.CurrentUser = contextUser;\n await TemplateEngineServer.Instance.Config(false, contextUser);\n //const parser = EntityDocumentTemplateParser.CreateInstance();\n const entityDocument: EntityDocumentEntity = await this.GetEntityDocument(request.entityDocumentID);\n const vectorIndexEntity: VectorIndexEntity = await this.GetOrCreateVectorIndex(entityDocument);\n const obj = await this.GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(request.entityDocumentID);\n\n const md = new Metadata();\n const entity = md.Entities.find((e) => e.ID === request.entityID);\n if (!entity) throw new Error(`Entity with ID ${request.entityID} not found.`);\n\n\n const template: TemplateEntityExtended | undefined = TemplateEngineServer.Instance.Templates.find((t: TemplateEntityExtended) => t.ID === entityDocument.TemplateID);\n if(!template){\n throw new Error(`Template not found with ID ${entityDocument.TemplateID}`);\n }\n\n if(template.Content.length === 0){\n throw new Error(`Template ${template.ID} does not have an associated Template Content record`);\n }\n\n if(template.Content.length > 1){\n throw new Error('Templates used by Entity Documents should only have one associated Template Content record.');\n }\n\n const validTemplate: boolean = this.ValidateTemplateContextParamAlignment(template);\n\n // this gets all the records, but we want to paginate\n // const allrecords: BaseEntity[] = await super.getRecordsByEntityID(request.entityID);\n\n //small number in the hopes we dont hit embedding token limits\n const pageSize: number = 15;\n const dataStream = new PagedRecords();\n \n let templateObj: {} = {\n ...template.GetAll(),\n Params: template.Params.map((p) => p.GetAll())\n }; \n\n const workerContext = { \n executionId: Date.now(), \n entity, \n entityDocument: entityDocument.GetAll(),\n template: templateObj,\n templateContent: template.Content[0].GetAll(),\n vectorDBClassKey: obj.vectorDBClassKey,\n vectorDBAPIKey: obj.vectorDBAPIKey,\n embeddingDriverClass: obj.embeddingDriverClass,\n embeddingAPIKey: obj.embeddingAPIKey,\n delayTimeMS\n };\n\n //annotator worker handles vectorizing the records \n const annotator = new BatchWorker({\n workerFile: resolve(__dirname, 'workers/VectorizeTemplates.js'),\n batchSize: 3,\n concurrencyLimit: 2,\n contextUser: super.CurrentUser,\n workerContext,\n });\n\n //archiver worker handles upserting the vectors into the vector database\n const archiver = new BatchWorker({ \n workerFile: resolve(__dirname, 'workers/UpsertVectors.js'), \n batchSize: 4,\n contextUser: super.CurrentUser, \n workerContext\n });\n\n const upserter = new Transform({objectMode: true, transform: (chunk, encoding, callback) => {\n this.UpsertEntityRecordDocumentRecords(chunk as EmbeddingData, super.CurrentUser).then(() => callback(null)).catch(callback);\n }});\n\n const getData = async (): Promise<void> => {\n let pageNumber = 0;\n let hasMore = true;\n\n while (hasMore) {\n const recordsPage: BaseEntity[] = await super.pageRecordsByEntityID<BaseEntity>(request.entityID, pageNumber, pageSize);\n const relatedData: TemplateParamData[] = await this.GetRelatedTemplateDataForBatch(entity, recordsPage, template);\n const items: {}[] = [];\n \n for(const record of recordsPage){\n const templateData: { [key: string]: unknown } = await this.GetTemplateData(entity, record, template, relatedData);\n //we need a reference to this record's ID for the upsert worker\n templateData.__mj_recordID = record.FirstPrimaryKey.Value;\n templateData.__mj_compositeKey = record.PrimaryKey.ToConcatenatedString();\n //we also need a reference to the vector index's ID\n templateData.VectorIndexID = vectorIndexEntity.ID;\n templateData.TemplateContent = template.Content[0].TemplateText;\n items.push(templateData);\n }\n\n dataStream.addPage(items);\n if(recordsPage.length < pageSize) {\n hasMore = false;\n break;\n }\n\n pageNumber++;\n }\n\n dataStream.endStream();\n };\n\n // page data asynchrounously and add to the data stream\n getData();\n\n console.log('Starting pipeline');\n await pipeline(dataStream, annotator, archiver, upserter, new PassThrough({ objectMode: true }));\n\n // const chunks: BaseEntity[][] = this.chunkArray(allrecords, batchSize);\n // LogStatus(`Processing ${allrecords.length} records in ${chunks.length} chunks of ${batchSize} records each`);\n // LogStatus(`Processing page ${pageNumber} records of ${pageSize} records each`);\n\n // Now add the records to the vectorize queue\n // The vectorize queue consumer calls the embedding service to get the embeddings\n // Then adds vectors + record metadata to the storage queue\n // The storage queue consumer adds the vectors to the vector database\n\n // let count = 0;\n // for (const batch of chunks) {\n // let templates: string[] = [];\n // for (const record of batch) {\n // let template: string = await parser.Parse(entityDocument.Template, request.entityID, record, contextUser);\n // templates.push(template);\n // }\n // LogStatus(`parsing batch ${count}: done`);\n\n // const embeddings: EmbedTextsResult = await obj.embedding.EmbedTexts({ texts: templates, model: null });\n // LogStatus(`embedding batch ${count}: done`);\n\n // const vectorRecords: VectorRecord[] = embeddings.vectors.map((vector: number[], index: number) => {\n // const record: BaseEntity = batch[index];\n // const recordID = record.PrimaryKey.Values('|');\n // return {\n // //The id breaks down to e.g. \"Accounts_7_117\"\n // id: `${entityDocument.Entity}_${entityDocument.ID}_${recordID}`,\n // values: vector,\n // metadata: {\n // EntityID: entityDocument.EntityID,\n // EntityName: entityDocument.Entity,\n // EntityDocumentID: entityDocument.ID,\n // PrimaryKey: record.PrimaryKey.ToString(),\n // Template: templates[index],\n // Data: this.ConvertEntityFieldsToString(record),\n // },\n // };\n // });\n\n // const response: BaseResponse = await obj.vectorDB.createRecords(vectorRecords);\n // if (response.success && vectorIndexEntity) {\n // LogStatus('Successfully created vector records, creating associated Entity Record Documents...');\n // for (const [index, vectorRecord] of vectorRecords.entries()) {\n // try {\n // let erdEntity: EntityRecordDocumentEntity = await super.Metadata.GetEntityObject('Entity Record Documents');\n // erdEntity.NewRecord();\n // erdEntity.EntityID = entityDocument.EntityID;\n // erdEntity.RecordID = batch[index].PrimaryKey.ToString();\n // erdEntity.DocumentText = templates[index];\n // erdEntity.VectorID = vectorRecord.id;\n // erdEntity.VectorJSON = JSON.stringify(vectorRecord.values);\n // erdEntity.VectorIndexID = vectorIndexEntity.ID;\n // erdEntity.EntityRecordUpdatedAt = new Date();\n // erdEntity.EntityDocumentID = entityDocument.ID;\n // let erdEntitySaveResult: boolean = await super.SaveEntity(erdEntity);\n // if (!erdEntitySaveResult) {\n // LogError('Error saving Entity Record Document Entity');\n // }\n // } catch (err) {\n // LogError('Error saving Entity Record Document Entity');\n // LogError(err);\n // }\n // }\n // } else {\n // LogError('Unable to successfully save records to vector database', undefined, response.message);\n // }\n\n // //add a delay to avoid rate limiting\n // let delayRes = await this.delay(1000);\n // count += 1;\n // LogStatus(`Chunk ${count} of out ${chunks.length} processed`);\n // }\n\n const endTime: number = new Date().getTime();\n LogStatus(`Finished vectorizing ${entityDocument.Entity} entity in ${endTime - startTime} ms`);\n return null;\n }\n\n /**\n * This method will create a default Entity Document for the given entityID, vectorDatabase, and AIModel\n * @param entityID\n * @param vectorDatabase\n * @param AIModel\n * @returns\n */\n public async CreateDefaultEntityDocument(\n EntityID: string,\n VectorDatabase: VectorDatabaseEntity,\n AIModel: AIModelEntity\n ): Promise<EntityDocumentEntity> {\n const md = new Metadata();\n const entity = md.Entities.find((e) => e.ID === EntityID);\n if (!entity) throw new Error(`Entity with ID ${EntityID} not found.`);\n\n const EDTemplate: string = entity.Fields.map((ef) => {\n return `${ef.Name}: \\$\\{${ef.Name}\\}`;\n }).join(' ');\n\n const entityDocument: EntityDocumentEntity = await md.GetEntityObject<EntityDocumentEntity>('Entity Documents');\n entityDocument.NewRecord();\n entityDocument.Name = `Default duplicate record Entity Document for the ${entity.Name} entity using vector database ${VectorDatabase.Name} and AI Model ${AIModel.Name}`;\n entityDocument.EntityID = EntityID;\n entityDocument.TypeID = RECORD_DUPLICATES_TYPE_ID;\n entityDocument.Status = 'Active';\n entityDocument.TemplateID = EDTemplate;\n entityDocument.VectorDatabaseID = VectorDatabase.ID;\n entityDocument.AIModelID = AIModel.ID;\n let saveResult = await this.SaveEntity(entityDocument);\n if (saveResult) {\n return entityDocument;\n } else {\n throw new Error(`Failed to save Entity Document for ${EntityID}`);\n }\n }\n\n protected async GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(\n entityDocumentID: string,\n createDocumentIfNotFound: boolean = false\n ): Promise<{ embedding: Embeddings; vectorDB: VectorDBBase, vectorDBClassKey: string, vectorDBAPIKey: string, embeddingDriverClass: string, embeddingAPIKey: string }> {\n let entityDocument: EntityDocumentEntity | null =\n (await this.GetEntityDocument(entityDocumentID)) || (await this.GetFirstActiveEntityDocumentForEntity(entityDocumentID));\n if (!entityDocument) {\n if (createDocumentIfNotFound) {\n if (!entityDocument) {\n LogStatus(`No active Entity Document found for entity ${entityDocumentID}, creating one`);\n const defaultVectorDB: VectorDatabaseEntity = this.getVectorDatabase();\n const defaultAIModel: AIModelEntity = this.getAIModel();\n entityDocument = await this.CreateDefaultEntityDocument(entityDocumentID, defaultVectorDB, defaultAIModel);\n }\n } else {\n throw new Error(`No Entity Document found for ID=${entityDocumentID}`);\n }\n }\n\n const vectorDBEntity: VectorDatabaseEntity = this.getVectorDatabase(entityDocument.VectorDatabaseID);\n const aiModelEntity: AIModelEntity = this.getAIModel(entityDocument.AIModelID);\n\n const embeddingAPIKey: string = GetAIAPIKey(aiModelEntity.DriverClass);\n const vectorDBAPIKey: string = GetAIAPIKey(vectorDBEntity.ClassKey);\n\n if (!embeddingAPIKey) {\n throw Error(`No API Key found for AI Model ${aiModelEntity.DriverClass}`);\n }\n\n if (!vectorDBAPIKey) {\n throw Error(`No API Key found for Vector Database ${vectorDBEntity.ClassKey}`);\n }\n\n //LogStatus(`Embedding API Key: ${embeddingAPIKey} VectorDB API Key: ${vectorDBAPIKey}`);\n const embedding = MJGlobal.Instance.ClassFactory.CreateInstance<Embeddings>(Embeddings, aiModelEntity.DriverClass, embeddingAPIKey);\n const vectorDB = MJGlobal.Instance.ClassFactory.CreateInstance<VectorDBBase>(VectorDBBase, vectorDBEntity.ClassKey, vectorDBAPIKey);\n\n if (!embedding) {\n throw Error(`Failed to create Embeddings instance for AI Model ${aiModelEntity.DriverClass}`);\n }\n\n if (!vectorDB) {\n throw Error(`Failed to create Vector Database instance for ${vectorDBEntity.ClassKey}`);\n }\n\n LogStatus(`Using vector database ${vectorDBEntity.Name} and AI Model ${aiModelEntity.Name}`);\n\n const obj = { \n embedding, \n vectorDB, \n vectorDBClassKey: vectorDBEntity.ClassKey, \n vectorDBAPIKey: vectorDBAPIKey,\n embeddingDriverClass: aiModelEntity.DriverClass,\n embeddingAPIKey: embeddingAPIKey\n };\n\n return obj;\n }\n\n public async GetEntityDocument(EntityDocumentID: string): Promise<EntityDocumentEntity | null> {\n const cache = EntityDocumentCache.Instance;\n if (!cache.IsLoaded) {\n await cache.Refresh(super.CurrentUser);\n }\n return cache.GetDocument(EntityDocumentID);\n }\n\n public async GetEntityDocumentByName(EntityDocumentName: string, ContextUser?: UserInfo): Promise<EntityDocumentEntity | null> {\n const cache = EntityDocumentCache.Instance;\n if (!cache.IsLoaded) {\n await cache.Refresh(ContextUser);\n }\n return cache.GetDocumentByName(EntityDocumentName);\n }\n\n public async GetFirstActiveEntityDocumentForEntity(entityID: string): Promise<EntityDocumentEntity | null> {\n const entityDocumentTypeID: EntityDocumentTypeEntity | undefined = AIEngine.EntityDocumentTypes.find((documentType: EntityDocumentTypeEntity) => documentType.Name === 'Record Duplicate');\n\n if (!entityDocumentTypeID) {\n throw new Error('Entity Document Type not found');\n }\n\n const entityDocument: EntityDocumentEntity = await this.runViewForSingleValue<EntityDocumentEntity>(\n 'Entity Documents',\n `EntityID = '${entityID}' AND TypeID = '${entityDocumentTypeID.ID}' AND Status = 'Active'`\n );\n if (!entityDocument) {\n LogError(`No active Entity Document with entityID=${entityID} found`);\n return null;\n }\n\n return entityDocument;\n }\n\n /**\n * Returns all active Entity Documents of the 'Record Duplicate' type.\n * Note that this only returns the first active Entity Document. Meaning if there are multiple Entity Documents for the same entity, \n * only the oldest one will be returned.\n * @param entityIDs If provided, only Entity Documents for the specified entities will be returned.\n */\n public async GetActiveEntityDocuments(entityNames?: string[]): Promise<EntityDocumentEntity[]> {\n await AIEngine.Instance.Config(false, super.CurrentUser);\n\n const entityDocumentTypeID: EntityDocumentTypeEntity | undefined = AIEngine.EntityDocumentTypes.find((documentType: EntityDocumentTypeEntity) => documentType.Name === 'Record Duplicate');\n if (!entityDocumentTypeID) {\n throw new Error('Entity Document Type not found');\n }\n\n let filter = `TypeID = '${entityDocumentTypeID}' AND Status = 'Active' `;\n if (entityNames) {\n filter += ` AND Entity IN (${entityNames.map((entityName: string) => `'${entityName}'`).join(',')})`;\n }\n\n const runViewResult: RunViewResult<EntityDocumentEntity> = await super.RunView.RunView<EntityDocumentEntity>({\n EntityName: 'Entity Documents',\n ExtraFilter: filter,\n ResultType: 'entity_object',\n }, super.CurrentUser);\n\n if(!runViewResult.Success){\n throw new Error(runViewResult.ErrorMessage);\n }\n\n let entityDocuments: EntityDocumentEntity[] = [];\n let seenEntities: string[] = [];\n\n //we only want one entity document per entity\n for(const entityDocument of runViewResult.Results){\n if(seenEntities.includes(entityDocument.EntityID)){\n continue;\n }\n \n entityDocuments.push(entityDocument);\n seenEntities.push(entityDocument.EntityID);\n }\n\n return entityDocuments;\n }\n\n private async GetOrCreateVectorIndex(entityDocument: EntityDocumentEntity): Promise<VectorIndexEntity> {\n let vectorIndexEntity: VectorIndexEntity = await super.runViewForSingleValue(\n 'Vector Indexes',\n `VectorDatabaseID = '${entityDocument.VectorDatabaseID}' AND EmbeddingModelID = '${entityDocument.AIModelID}'`\n );\n if (vectorIndexEntity) {\n return vectorIndexEntity;\n }\n\n LogStatus(`No Vector Index found for entityDocument ${entityDocument.ID}, creating one`);\n try {\n vectorIndexEntity = await super.Metadata.GetEntityObject<VectorIndexEntity>('Vector Indexes');\n vectorIndexEntity.NewRecord();\n vectorIndexEntity.VectorDatabaseID = entityDocument.VectorDatabaseID;\n vectorIndexEntity.EmbeddingModelID = entityDocument.AIModelID;\n vectorIndexEntity.Name = `Vector Index for entityDocument ${entityDocument.EntityID}`;\n vectorIndexEntity.Set('EntityRecordUpdatedAt', new Date());\n vectorIndexEntity.Set('EntityDocumentID', entityDocument.ID);\n //not a very descriptive description, but the view has the name of the vectorDB and embedding model used\n vectorIndexEntity.Description = `Vector Index that uses the Vector database ${entityDocument.VectorDatabaseID} and ${entityDocument.AIModelID} as the embedding model`;\n const saveResult = await super.SaveEntity(vectorIndexEntity);\n if (saveResult) {\n LogStatus(`Successfully created new Vector Index Entity`);\n return vectorIndexEntity;\n } else {\n LogError('Error saving Vector Index Entity');\n return null;\n }\n } catch (err) {\n console.error(JSON.stringify(err));\n LogError(err);\n return null;\n }\n }\n\n protected async CreateTemplateForEntityDocument(entityDocument: EntityDocumentEntity): Promise<TemplateEntity> {\n const templateEntity: TemplateEntityExtended = await super.Metadata.GetEntityObject<TemplateEntityExtended>('Templates');\n templateEntity.NewRecord();\n templateEntity.Name = `Template for EntityDocument ${entityDocument.EntityID}`;\n templateEntity.Description = `The template used by EntityDocument ${entityDocument.ID}`\n templateEntity.UserID = super.CurrentUser.ID;\n templateEntity.IsActive = true;\n templateEntity.CategoryID = null;\n\n const templateEntitySaveResult = await super.SaveEntity(templateEntity);\n if(!templateEntitySaveResult){\n LogError('Error saving Template Entity', undefined, templateEntity.LatestResult);\n throw new Error(templateEntity.LatestResult.Message);\n }\n LogStatus(`Successfully created new Template Entity ${templateEntity.ID}`);\n\n //next, create the template contents record\n await TemplateEngineServer.Instance.Config(false, super.CurrentUser);\n const textContentType: TemplateContentTypeEntity = TemplateEngineServer.Instance.TemplateContentTypes.find((type: TemplateContentTypeEntity) => type.Name === 'Text');\n if(!textContentType){\n throw new Error('Text template content type not found');\n }\n\n const entityFields: EntityField[] = await this.GetEntityFieldsForSimilaritySearch(entityDocument.EntityID);\n\n const templateContentsEntity: TemplateContentEntity = await super.Metadata.GetEntityObject<TemplateContentEntity>('Template Contents');\n templateContentsEntity.NewRecord();\n templateContentsEntity.TemplateID = templateEntity.ID;\n templateContentsEntity.TypeID = textContentType.ID;\n templateContentsEntity.Priority = 1;\n templateContentsEntity.IsActive = true;\n templateContentsEntity.TemplateText = this.BuildTemplateContent(entityFields);\n\n const templateContentsEntitySaveResult = await super.SaveEntity(templateContentsEntity);\n if(!templateContentsEntitySaveResult){\n LogError('Error saving Template Entity', undefined, templateContentsEntity.LatestResult);\n throw new Error(templateContentsEntity.LatestResult.Message);\n }\n LogStatus(`Successfully created new Template Content Entity ${templateContentsEntity.ID}`);\n\n //next, create the template params record\n const templateParamsEntity: TemplateParamEntity = await super.Metadata.GetEntityObject<TemplateParamEntity>('Template Params');\n templateParamsEntity.NewRecord();\n templateParamsEntity.TemplateID = templateEntity.ID;\n templateParamsEntity.Name = 'Entity';\n templateParamsEntity.Description = 'The entity object to be used in the template';\n templateParamsEntity.Type = 'Record';\n templateParamsEntity.DefaultValue = null;\n templateParamsEntity.IsRequired = true;\n templateParamsEntity.LinkedParameterName = null;\n templateParamsEntity.LinkedParameterField = null;\n templateParamsEntity.ExtraFilter = null;\n templateParamsEntity.EntityID = entityDocument.EntityID;\n templateParamsEntity.RecordID = null;\n\n const templateParamsEntitySaveResult = await super.SaveEntity(templateParamsEntity);\n if(!templateParamsEntitySaveResult){\n LogError('Error saving Template Entity', undefined, templateParamsEntity.LatestResult);\n throw new Error(templateParamsEntity.LatestResult.Message);\n }\n LogStatus(`Successfully created new Template Param Entity ${templateParamsEntity.ID}`);\n \n templateEntity.Content.push(templateContentsEntity);\n templateEntity.Params.push(templateParamsEntity);\n TemplateEngineServer.Instance.AddTemplate(templateEntity);\n\n return templateEntity;\n }\n\n protected BuildTemplateContent(entityFields: EntityField[]): string {\n return entityFields.map((field: EntityField) => {\n return `{{Entity.${field.Name}}}`;\n }).join(' ');\n }\n\n protected async GetEntityFieldsForSimilaritySearch(entityID: string): Promise<EntityField[]> {\n //We only want fields that can potentially be the same across records\n //which means things such as IDs, timestamps, etc. are not useful\n //as they're likely to be unique or not that helpful in determining similarity\n const runViewResult: RunViewResult<EntityField> = await super.RunView.RunView<EntityField>({\n EntityName: 'Entity Fields',\n ExtraFilter: `EntityID = '${entityID}' AND IsPrimaryKey = 0 AND IsUnique = 0 AND AutoIncrement = 0 and Type NOT IN ('datetimeoffset', 'datetime')`,\n ResultType: 'entity_object',\n }, super.CurrentUser);\n\n if (!runViewResult.Success) {\n throw new Error(runViewResult.ErrorMessage);\n }\n\n return runViewResult.Results;\n }\n\n private chunkArray(array: any[], chunkSize: number): BaseEntity[][] {\n let arrayCopy = [...array];\n let result: BaseEntity[][] = [];\n while (arrayCopy.length) {\n result.push(arrayCopy.splice(0, chunkSize));\n }\n return result;\n }\n\n private convertPrimaryKeysToList(primaryKeys: EntityField[]): any {\n return primaryKeys.map((pk) => {\n return `${pk.Name}=${pk.Value}`;\n });\n }\n\n private ConvertEntityFieldsToString(entity: BaseEntity): string {\n let obj = {};\n for (const field of entity.Fields) {\n obj[field.Name] = field.Value;\n }\n\n return JSON.stringify(obj);\n }\n\n private delay = (delayInms: number) => {\n return new Promise((resolve) => setTimeout(resolve, delayInms));\n };\n\n protected async GetTemplateData(entity: EntityInfo, record: BaseEntity, template: TemplateEntityExtended, relatedData: TemplateParamData[]): Promise<{ [key: string]: any }> {\n const templateData: { [key: string]: any } = {};\n for(const param of template.Params){\n if(templateData[param.Name]){\n continue;\n }\n\n switch(param.Type){\n case 'Record':\n // this one is simple, we create a property by the provided name, and set the value to the record we are currently processing\n templateData[param.Name] = record.GetAll();\n break;\n case 'Entity':\n // here we need to grab the related data from another entity and filter it down for the record we are current processing so it only shows the related data\n // the metadata in the param tells us what we need to know\n const paramData: TemplateParamData | undefined = relatedData.find((rd: TemplateParamData) => rd.ParamName === param.Name);\n if(!paramData){\n LogError(`No related data found for param ${param.Name} in template ${template.ID}`);\n break;\n }\n\n // now filter down the data in d to just this record and set the value of the context data to the filtered data\n const relatedDataForRecord = paramData.Data.filter((rdfr: BaseEntity) => rdfr.Get(param.LinkedParameterField) === record.Get(entity.FirstPrimaryKey.Name));\n templateData[param.Name] = relatedDataForRecord.map((rdfr: BaseEntity) => rdfr.GetAll());\n break;\n case \"Array\":\n case \"Scalar\":\n case \"Object\":\n // do nothing here, as we don't directly support these param types\n LogError(`Unsupported parameter type ${param.Type} for parameter ${param.Name} in template ${template.ID}`);\n break;\n }\n }\n return templateData;\n }\n\n protected async GetRelatedTemplateData(entity: EntityInfo, record: BaseEntity, templateParam: TemplateParamEntity): Promise<TemplateParamData | null> {\n const relatedEntity = templateParam.Entity;\n const relatedField = templateParam.LinkedParameterField;\n\n // construct a filter for the related field so that we constrain the results to just the set of records linked to our recipients\n const quotes = entity.FirstPrimaryKey.NeedsQuotes ? \"'\" : \"\";\n const filter = `${relatedField} = ${quotes}${record[entity.FirstPrimaryKey.Name]}${quotes}`;\n const finalFilter = templateParam.ExtraFilter ? `(${filter}) AND (${templateParam.ExtraFilter})` : filter;\n\n const result = await super.RunView.RunView({\n EntityName: relatedEntity,\n ExtraFilter: finalFilter,\n ResultType: 'entity_object'\n }, super.CurrentUser);\n\n if (result && result.Success) {\n const relatedData: TemplateParamData = { ParamName: '', Data: [] };\n relatedData.ParamName = templateParam.Name,\n relatedData.Data = result.Results;\n return relatedData;\n }\n \n LogError(`Error getting related data for entity ${relatedEntity} with filter ${finalFilter}`, undefined, result.ErrorMessage);\n return null;\n }\n\n protected async GetRelatedTemplateDataForBatch(entity: EntityInfo, records: BaseEntity[], template: TemplateEntityExtended): Promise<TemplateParamData[]> {\n const relatedData: TemplateParamData[] = [];\n\n for(const templateParam of template.Params){\n if(templateParam.Type !== 'Entity'){\n continue;\n }\n\n const relatedEntity = templateParam.Entity;\n const relatedField = templateParam.LinkedParameterField;\n\n // construct a filter for the related field so that we constrain the results to just the set of records linked to our recipients\n const quotes = entity.FirstPrimaryKey.NeedsQuotes ? \"'\" : \"\";\n const filter = `${relatedField} in (${records.map((record: BaseEntity) => `${quotes}${record[entity.FirstPrimaryKey.Name]}${quotes}`).join(',')})`;\n const finalFilter = templateParam.ExtraFilter ? `(${filter}) AND (${templateParam.ExtraFilter})` : filter;\n\n const result = await super.RunView.RunView({\n EntityName: relatedEntity,\n ExtraFilter: finalFilter,\n ResultType: 'entity_object'\n }, super.CurrentUser);\n\n if (result && result.Success) {\n const data: TemplateParamData = { ParamName: '', Data: [] };\n data.ParamName = templateParam.Name,\n data.Data = result.Results;\n relatedData.push(data);\n }\n else {\n LogError(`Error getting related data for entity ${relatedEntity} with filter ${finalFilter}`, undefined, result.ErrorMessage);\n }\n }\n\n return relatedData;\n }\n\n // Rather than having this logic inside the EntityRecordDocumentWorker class, it's placed here instead\n //so that the logic behind vectorizing entities isnt spread out across so many files\n protected async UpsertEntityRecordDocumentRecords(embeddingData: EmbeddingData, contextUser: UserInfo): Promise<void> {\n let md: Metadata = super.Metadata;\n let rv: RunView = super.RunView;\n\n let vectorIndex: VectorIndexEntity = await md.GetEntityObject('Vector Indexes', contextUser);\n let loadResult = await vectorIndex.Load(embeddingData.VectorIndexID.toString());\n if(!loadResult){\n LogError(`Vector Index with ID ${embeddingData.VectorIndexID} not found`);\n return;\n }\n\n let entityDocument: Record<string, unknown> = embeddingData.EntityDocument;\n let entityID: unknown = entityDocument.EntityID;\n\n let existingRecords: EntityRecordDocumentEntity[] = [];\n const runViewResult: RunViewResult<EntityRecordDocumentEntity> = await rv.RunView<EntityRecordDocumentEntity>({\n EntityName: 'Entity Record Documents',\n ExtraFilter: `EntityID = '${entityID}' AND EntityDocumentID = '${entityDocument.ID}' AND RecordID in (${embeddingData.__mj_recordID})`,\n ResultType: 'entity_object'\n }, contextUser);\n \n if(runViewResult.Success){\n existingRecords = runViewResult.Results;\n }\n else{\n LogError(`Error getting existing Entity Record Documents`, undefined, runViewResult.ErrorMessage);\n }\n\n let erdEntity: EntityRecordDocumentEntity | undefined = existingRecords.find((er: EntityRecordDocumentEntity) => er.RecordID.toString() === embeddingData.__mj_recordID.toString());\n if(!erdEntity){\n erdEntity = await md.GetEntityObject('Entity Record Documents', contextUser);\n erdEntity.NewRecord();\n }\n\n erdEntity.EntityID = entityID.toString();\n erdEntity.RecordID = embeddingData.__mj_recordID.toString();\n erdEntity.DocumentText = embeddingData.TemplateContent;\n erdEntity.VectorID = embeddingData.VectorID.toString();\n erdEntity.VectorJSON = JSON.stringify(embeddingData.Vector);\n erdEntity.VectorIndexID = embeddingData.VectorIndexID.toString();\n erdEntity.EntityRecordUpdatedAt = new Date();\n erdEntity.EntityDocumentID = embeddingData.EntityDocument.ID.toString();\n erdEntity.ContextCurrentUser = contextUser;\n let erdEntitySaveResult: boolean = await erdEntity.Save();\n if(!erdEntitySaveResult){\n LogError('Error saving Entity Record Document Entity', undefined, erdEntity.LatestResult);\n }\n\n LogStatus(\"Upserting Entity Record Documents: Complete\");\n }\n\n /**\n * This method is resposnible for determining if the template(s) given have aligned parameters, meaning they don't have overlapping parameter names that have \n * different meanings. It is okay for scenarios where there are > 1 template in use for a message to have different parameter names, but if they have the SAME parameter names\n * they must not have different settings.\n */\n protected ValidateTemplateContextParamAlignment(template: TemplateEntityExtended): boolean {\n // the params are defined in each template they will be in the Params property of the template\n const seenParams: {[key: string]: TemplateParamEntity } = {};\n for (const templateParam of template.Params) {\n const param: TemplateParamEntity | undefined = seenParams[templateParam.Name];\n // we have a duplicate parameter name, now we need to check if the definitions are the same\n if(param && param.Type !== templateParam.Type){\n throw new Error(`Parameter ${param.Name} has different types in different templates`);\n }\n else {\n seenParams[templateParam.Name] = templateParam;\n }\n }\n\n // if we get here, we are good, otherwise we will have thrown an exception\n return true;\n }\n}\n","import { CompositeKey, Metadata, UserInfo } from '@memberjunction/core';\n\n/**\n * This is an abstract base class, use the EntityDocumentTemplateParser class or a sub-class thereof.\n */\nexport abstract class EntityDocumentTemplateParserBase {\n public static ClearCache() {\n EntityDocumentTemplateParserBase.__cache = {};\n }\n public static CreateCacheKey(EntityID: string, EntityRecordPrimaryKey: string, Content: string): string {\n return `${EntityID}___${EntityRecordPrimaryKey}___${Content}`;\n }\n\n protected static __cache: { [key: string]: string } = {};\n protected static get _cache(): { [key: string]: string } {\n return EntityDocumentTemplateParserBase.__cache;\n }\n\n /**\n * This method will parse an entity document template and replace values within ${} placeholders with actual values from the entity record. In the case of function calls\n * within the placeholders, the functions object must be provided to parse the function calls.\n * @param Template - the document template to parse\n * @param EntityID - the ID of the entity\n * @param EntityRecord - the values for the entity record\n * @param ContextUser - the current user\n * @returns the evaluated value of the template incorporating fields and function call(s), if any.\n */\n public async Parse(Template: string, EntityID: string, EntityRecord: any, ContextUser: UserInfo): Promise<string> {\n if (!ContextUser) {\n throw new Error('ContextUser is required to parse the template');\n }\n\n const md = new Metadata();\n const entityInfo = md.Entities.find((e) => e.ID === EntityID);\n if (!entityInfo) {\n throw new Error(`Entity with ID ${EntityID} not found.`);\n }\n\n let compositeKey: CompositeKey = new CompositeKey();\n compositeKey.LoadFromEntityInfoAndRecord(entityInfo, EntityRecord);\n\n const regex = /\\$\\{([^{}]+)\\}/g;\n const matches = Template.matchAll(regex);\n\n // Convert matches to an array to handle them asynchronously\n const replacements = Array.from(matches).map(async (match) => {\n const content = match[1]; // The captured group from regex\n const cacheKey = EntityDocumentTemplateParserBase.CreateCacheKey(EntityID, compositeKey.ToString(), content);\n\n // check the cache and if we don't have an entry in the cache, add it\n if (!EntityDocumentTemplateParserBase._cache[cacheKey]) {\n // Cache miss, evaluate and store the result\n EntityDocumentTemplateParserBase._cache[cacheKey] = await this.evalSingleArgument(content, EntityID, EntityRecord, ContextUser);\n }\n\n return {\n old: match[0], // The entire placeholder including ${}\n new: EntityDocumentTemplateParserBase._cache[cacheKey], // The replacement value\n };\n });\n\n // Resolve all promises\n const resolvedReplacements = await Promise.all(replacements);\n\n // Replace each placeholder in the template with its resolved value\n let resolvedTemplate = Template;\n resolvedReplacements.forEach((replacement) => {\n resolvedTemplate = resolvedTemplate.replace(replacement.old, replacement.new);\n });\n\n return resolvedTemplate;\n }\n\n protected async evalSingleArgument(argument: string, entityID: string, entityRecord: any, ContextUser: UserInfo): Promise<string> {\n const funcMatch = argument.match(/(\\w+)\\(([^)]*)\\)/);\n if (funcMatch) {\n const [, funcName, paramsString] = funcMatch;\n const params = paramsString.split(',').map((param) => {\n param = param.trim();\n //if the string is wrapped in single or double quotes, remove them\n if (param.startsWith('\"') && param.endsWith('\"')) {\n return param.slice(1, -1);\n } else if (param.startsWith(\"'\") && param.endsWith(\"'\")) {\n return param.slice(1, -1);\n } else {\n return param;\n }\n });\n\n // Check if the method exists on this instance\n if (typeof this[funcName] === 'function') {\n // Call the instance method dynamically using its name and spread the params\n return this[funcName](entityID, entityRecord, ContextUser, ...params);\n } else {\n throw new Error(`Function ${funcName} is not defined.`);\n }\n } else {\n // not a function match, attempt to return the value from the entity record\n return entityRecord[argument] !== undefined ? entityRecord[argument] : '';\n }\n }\n}\n","import { CompositeKey, LogError, LogStatus, Metadata, UserInfo } from \"@memberjunction/core\";\nimport { MJGlobal, RegisterClass } from \"@memberjunction/global\";\nimport { EntityVectorSyncer } from \"../models/entityVectorSync\";\nimport { EntityDocumentTemplateParserBase } from \"./EntityDocumenTemplateParserBase\";\n\n/**\n * This is the first-level sub-class of EntityDocumentTemplateParserBase. This class is used to parse a string template with variables and functions. \n * If you wish to override functionality you can subclass it and then use the @RegisterClass decorator to register the sub-class of EntityDocumentTemplateParser with a priority of 1 or above to \n * then be used instead of the default implementation.\n */\n@RegisterClass(EntityDocumentTemplateParser)\nexport class EntityDocumentTemplateParser extends EntityDocumentTemplateParserBase {\n\n /** Convenience method to get an instance of the class and uses the ClassFactory so we can create sub-classes if they are registered with higher priorities than the base class */\n public static CreateInstance(): EntityDocumentTemplateParser {\n return MJGlobal.Instance.ClassFactory.CreateInstance<EntityDocumentTemplateParser>(EntityDocumentTemplateParser);\n }\n\n /**\n * This function \n * @param entityID \n * @param entityRecord \n * @param relationshipName \n * @param maxRows \n * @param entityDocumentName \n * @returns \n */\n protected async Relationship(entityID: string, entityRecord: any, ContextUser: UserInfo, relationshipName: string, maxRows: number, entityDocumentName: string): Promise<string> {\n // super inefficient handling to start, we'll optimize this later to call the related stuff in batch\n const md = new Metadata();\n const vectorSyncer: EntityVectorSyncer = new EntityVectorSyncer();\n vectorSyncer.CurrentUser = ContextUser;\n\n const entityInfo = md.Entities.find(e => e.ID === entityID); \n if (!entityInfo){\n throw new Error(`Entity with ID ${entityID} not found.`);\n }\n\n const re = entityInfo.RelatedEntities.find(re => re.RelatedEntity === relationshipName);\n if (!re){\n throw new Error(`Relationship ${relationshipName} not found for entity ${entityInfo.Name}`);\n }\n\n const obj = await md.GetEntityObject(entityInfo.Name, ContextUser);\n let compositeKey: CompositeKey = new CompositeKey();\n compositeKey.LoadFromEntityInfoAndRecord(entityInfo, entityRecord);\n let loadResult: boolean = await obj.InnerLoad(compositeKey);\n if (!loadResult){\n LogError(`Failed to load entity ${entityInfo.Name} with ID ${compositeKey.ToString()}`);\n return \"\";\n }\n\n const reData = await obj.GetRelatedEntityDataExt(re, null, maxRows)\n\n if (reData && reData.Data) {\n // now, get the entity document info if provided\n if (entityDocumentName && entityDocumentName.trim().length > 0) {\n // we have a document name, attempt to locate it\n const doc = await vectorSyncer.GetEntityDocumentByName(entityDocumentName, ContextUser);\n if (doc) {\n // we have the document, now we need to parse it and build a result that is the concatenation of all the parsed documents\n // start off by creating an instance of the parser using CreateInstance() so we're using the highest priority registered subclass\n const parser = EntityDocumentTemplateParser.CreateInstance();\n\n // now we need to batch the requests to the parser to have the right concurrency\n const batchSize = 10; // Set the batch size to the desired number of concurrent requests\n const results = [];\n \n for (let i = 0; i < reData.Data.length; i += batchSize) {\n const batchPromises = reData.Data.slice(i, i + batchSize).map(data => {\n return parser.Parse((doc as any).Template, re.RelatedEntityID, data, ContextUser);\n });\n const batchResults = await Promise.all(batchPromises);\n results.push(...batchResults);\n }\n \n return results.map(r => r + \"\\n\\n\").join('');\n }\n else {\n LogStatus(`Entity Document with name ${entityDocumentName} not found.`);\n return \"\";\n }\n }\n else {\n // no entity document name provided, just return the data in a simple format\n return JSON.stringify({ Relationship: relationshipName, Data: reData.Data});\n }\n }\n else {\n return \"{ No Data for: \" + relationshipName + \" }\"\n }\n }\n}"],"names":["Transform","Worker","LogStatus","RunView","Readable","VectorBase","AIEngine","TemplateEngineServer","Metadata","resolve","pipeline","PassThrough","GetAIAPIKey","MJGlobal","Embeddings","VectorDBBase","LogError","CompositeKey","EntityDocumentTemplateParser","RegisterClass"],"mappings":";;;;;;;;;;;;;;AAAO,MAAM,yBAAyB,GAAG,yDAAyD;;ACE3F,MAAM,WAAW,SAASA,qBAAS,CAAC;AAC3C,EAAE,UAAU,GAAG,EAAE,CAAC;AAClB,EAAE,WAAW,GAAG,aAAa,CAAC;AAC9B,EAAE,cAAc,GAAG,EAAE,CAAC;AACtB,EAAE,iBAAiB,GAAG,CAAC,CAAC;AACxB,EAAE,QAAQ,GAAG,CAAC,CAAC;AACf,EAAE,OAAO,GAAG,EAAE,CAAC;AACf,EAAE,MAAM,GAAG,EAAE,CAAC;AACd,EAAE,YAAY,GAAG,KAAK,CAAC,CAAC;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,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,SAAS,MAAM;AACf,UAAUhB,cAAS,CAAC,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;AAClF,UAAU,OAAO,EAAE,CAAC;AACpB,SAAS;AACT,OAAO,MAAM;AACb,QAAQ,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACrF,OAAO;AACP,KAAK,MAAM;AACX,MAAM,OAAO,iBAAiB,GAAG,gBAAgB,GAAG,IAAI,CAAC;AACzD,KAAK;AACL,GAAG;AACH,EAAE;AACFgB,oCAA4B,GAAG,eAAe,CAAC;AAC/C,EAAEC,oBAAa,CAACD,oCAA4B,CAAC;AAC7C,CAAC,EAAEA,oCAA4B,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/models/BatchWorker.ts","../src/models/EntityDocumentCache.ts","../src/models/PagedRecords.ts","../src/models/entityVectorSync.ts","../src/generic/EntityDocumenTemplateParserBase.ts","../src/generic/EntityDocumentTemplateParser.ts"],"sourcesContent":["export const RECORD_DUPLICATES_TYPE_ID = \"JONATHAN - FIX THIS TO USE BaseEngine DERVIED SUB-CLASS\";","import { UserInfo } from '@memberjunction/core';\nimport { Transform } from 'node:stream';\nimport { Worker } from 'node:worker_threads';\n\nexport type TransformCallback = Parameters<Transform['_flush']>[0];\nexport type WorkerData<TContext = Record<string, unknown>, TRecord = Record<string, unknown>> = {\n batch?: Array<TRecord>;\n context?: TContext;\n};\n\nexport type BatchWorkerOptions<TContext = Record<string, unknown>> = {\n /**\n * The number of records to process in a batch\n */\n batchSize?: number;\n /**\n * The path to the worker file used to launch a worker thread\n */\n workerFile?: string;\n /**\n * An abitrary context to pass to the worker thread\n */\n workerContext?: TContext;\n /**\n * The maximum number of worker threads to run concurrently\n */\n concurrencyLimit?: number;\n /**\n * The user context to pass to the worker thread\n */\n contextUser?: UserInfo;\n /**\n * The time to delay between api calls\n **/\n delayTimeMS?: number;\n};\n\n/**\n * This class processes records in batches using a worker thread. It expects\n * a worker file that exports a function to process the batch of records.\n * The stream operates in object mode and emits processed records.\n */\nexport class BatchWorker<TRecord = Record<string, unknown>, TContext = Record<string, unknown>> extends Transform {\n _batchSize = 10;\n _workerFile = './worker.js';\n _workerContext: TContext | Record<string, never> = {};\n _concurrencyLimit = 4;\n _running = 0;\n\n _buffer: Array<TRecord> = [];\n\n _queue: Array<() => Promise<void>> = [];\n\n _contextUser: UserInfo | undefined = undefined;\n\n /**\n * @param {BatchWorkerOptions} options - Options for the BatchWorker\n */\n constructor(options: BatchWorkerOptions<TContext> = {}) {\n super({ objectMode: true });\n this._batchSize = options.batchSize ?? this._batchSize;\n this._workerFile = options.workerFile ?? this._workerFile;\n this._workerContext = options.workerContext ?? this._workerContext;\n this._concurrencyLimit = options.concurrencyLimit ?? this._concurrencyLimit;\n this._contextUser = options.contextUser ?? this._contextUser;\n }\n\n /**\n * Starts the next task in the queue\n */\n _next() {\n if (this._queue.length > 0 && this._running < this._concurrencyLimit) {\n const task = this._queue.shift();\n task && task().then(() => this._next());\n }\n }\n\n /**\n * Enqueues a task to be processed\n * @param task - The task to enqueue\n */\n _enqueue(task: () => Promise<void>) {\n this._queue.push(task);\n this._next();\n }\n\n async _transform(chunk: TRecord, encoding: BufferEncoding, callback: TransformCallback) {\n this._buffer.push(chunk);\n if (this._buffer.length >= this._batchSize) {\n const batch = this._buffer.splice(0, this._batchSize);\n this._enqueue(() =>\n this._processBatchInWorker(batch)\n .then(() => callback())\n .catch(callback)\n );\n } else {\n callback();\n }\n }\n\n async _flush(callback: TransformCallback) {\n if (this._buffer.length > 0) {\n this._enqueue(() => this._processBatchInWorker(this._buffer));\n }\n\n Promise.all(this._queue)\n .then(() => callback())\n .catch(callback);\n }\n\n _processBatchInWorker(batch: Array<TRecord>): Promise<void> {\n return new Promise((resolve, reject) => {\n this._running++;\n const worker = new Worker(this._workerFile, { workerData: { batch, context: this._workerContext } });\n worker.on('message', ({ batch }: WorkerData<TContext, TRecord>) => {\n // Push batch rows to the stream for reading\n batch.forEach((row) => this.push(row));\n\n // Decrement _running on successful processing\n this._running--;\n resolve();\n });\n worker.on('error', (error) => {\n // Decrement _running and reject on error\n this._running--;\n reject(error);\n });\n });\n }\n}\n","import { UserInfo, RunView, LogStatus, RunViewResult } from \"@memberjunction/core\";\nimport { EntityDocumentEntity, EntityDocumentTypeEntity } from \"@memberjunction/core-entities\";\n\n/**\n * Simple caching class to load all Entity Documents and related data at once into memory\n */\nexport class EntityDocumentCache {\n private static _instance: EntityDocumentCache;\n private _loaded: boolean = false;\n private _cache: { [key: string]: EntityDocumentEntity } = {};\n private _typeCache: { [key: string]: EntityDocumentTypeEntity } = {};\n private _contextUser: UserInfo | null = null;\n\n private constructor() {\n // load up the cache\n this._cache = {};\n this._typeCache = {};\n } \n\n public static get Instance(): EntityDocumentCache {\n if(!EntityDocumentCache._instance){\n EntityDocumentCache._instance = new EntityDocumentCache();\n }\n return EntityDocumentCache._instance;\n }\n\n public get IsLoaded(): boolean {\n return this._loaded;\n }\n\n protected Cache(): { [key: string]: EntityDocumentEntity } {\n return this._cache;\n }\n\n protected TypeCache(): { [key: string]: EntityDocumentTypeEntity } {\n return this._typeCache;\n }\n\n public GetDocument(EntityDocumentID: string): EntityDocumentEntity | null {\n let document: EntityDocumentEntity = this._cache[EntityDocumentID];\n if (!document) {\n LogStatus(`EntityDocumentCache.GetDocument: Cache miss for EntityDocumentID: ${EntityDocumentID}`);\n }\n\n return document || null;\n }\n\n public GetFirstActiveDocumentForEntityByID(EntityID: string): EntityDocumentEntity | null {\n let documentType: EntityDocumentTypeEntity | null = this.GetDocumentTypeByName('Record Duplicate');\n if(!documentType){\n return null;\n }\n\n return Object.values(this._cache).find((ed: EntityDocumentEntity) => {\n ed.EntityID === EntityID && ed.Status === 'Active' && ed.TypeID === documentType.ID;\n });\n\n }\n\n public GetFirstActiveDocumentForEntityByName(EntityName: string): EntityDocumentEntity | null {\n let documentType: EntityDocumentTypeEntity | null = this.GetDocumentTypeByName('Record Duplicate');\n if(!documentType){\n return null;\n }\n\n return Object.values(this._cache).find((ed: EntityDocumentEntity) => {\n ed.Entity === EntityName && ed.Status === 'Active' && ed.TypeID === documentType.ID;\n });\n\n }\n\n public GetDocumentByName(EntityDocumentName: string): EntityDocumentEntity | null {\n const toLower = EntityDocumentName.trim().toLowerCase();\n let document: EntityDocumentEntity = Object.values(this._cache).find((ed: EntityDocumentEntity) => {\n ed.Name.trim().toLowerCase() === toLower;\n });\n\n if (!document) {\n LogStatus(`EntityDocumentCache.GetDocumentByName: Cache miss for EntityDocumentName: ${EntityDocumentName}`);\n }\n\n return document || null;\n }\n\n public GetDocumentType(EntityDocumentTypeID: string): EntityDocumentTypeEntity | null {\n let documentType: EntityDocumentTypeEntity = this._typeCache[EntityDocumentTypeID];\n if (!documentType) {\n LogStatus(`EntityDocumentCache.GetDocument: Cache miss for EntityDocumentID: ${EntityDocumentTypeID}`);\n return null;\n }\n\n return documentType;\n }\n\n public GetDocumentTypeByName(EntityDocumentTypeName: string): EntityDocumentTypeEntity | null {\n const toLower = EntityDocumentTypeName.trim().toLowerCase();\n let documentType: EntityDocumentTypeEntity = Object.values(this._typeCache).find((edt: EntityDocumentTypeEntity) => edt.Name.trim().toLowerCase() === toLower);\n\n if (!documentType) {\n LogStatus(`EntityDocumentCache.GetDocumentByName: Cache miss for EntityDocumentName: ${EntityDocumentTypeName}`);\n return null;\n }\n\n return documentType;;\n }\n\n public SetCurrentUser(user: UserInfo) {\n this._contextUser = user;\n }\n\n public async Refresh(forceRefresh: boolean, ContextUser?: UserInfo) {\n\n if(!forceRefresh && this._loaded){\n return;\n }\n\n LogStatus('Refreshing Entity Document Cache');\n this._cache = {};\n this._typeCache = {};\n\n // now load up the cache with all the entity documents\n const rv = new RunView();\n\n const results: RunViewResult[] = await rv.RunViews([\n {\n EntityName: \"Entity Documents\",\n ResultType: \"entity_object\"\n },\n {\n EntityName: \"Entity Document Types\",\n ResultType: \"entity_object\"\n }\n ], ContextUser || this._contextUser);\n\n if (results[0] && results[0].Success) {\n for (const entityDocument of results[0].Results) {\n this._cache[entityDocument.ID] = entityDocument;\n }\n }\n\n if (results[1] && results[1].Success) {\n for (const entityDocumentType of results[1].Results) {\n this._typeCache[entityDocumentType.ID] = entityDocumentType;\n }\n }\n\n this._loaded = true;\n }\n}","import { Readable } from 'node:stream';\n\n/**\n * A stream to collect pages of records and emit them as individual records\n */\nexport class PagedRecords extends Readable {\n constructor() {\n super({ objectMode: true });\n }\n\n _read() {\n // no-op\n }\n\n /**\n * Adds a page of results to the stream\n * @param {Array<Record<string,unknown>>} page - The page of results to add to the stream\n */\n addPage(page) {\n page.forEach((row) => this.push(row));\n }\n\n /**\n * Called when there are no more pages to add to the stream\n */\n endStream() {\n this.push(null);\n }\n}\n","import { Embeddings, GetAIAPIKey } from '@memberjunction/ai';\nimport { VectorDBBase } from '@memberjunction/ai-vectordb';\nimport { PageRecordsParams, VectorBase } from '@memberjunction/ai-vectors';\nimport { BaseEntity, EntityField, EntityInfo, LogError, LogStatus, Metadata, RunView, RunViewResult, UserInfo } from '@memberjunction/core';\nimport { AIModelEntity, EntityDocumentEntity, EntityDocumentTypeEntity, EntityRecordDocumentEntity, TemplateContentEntity, \n TemplateContentTypeEntity, TemplateEntity, TemplateParamEntity, VectorDatabaseEntity, VectorIndexEntity } from '@memberjunction/core-entities';\nimport { MJGlobal } from '@memberjunction/global';\nimport { pipeline } from 'node:stream/promises';\nimport { RECORD_DUPLICATES_TYPE_ID } from '../constants';\nimport { EmbeddingData, TemplateParamData, VectorEmeddingData, VectorizeEntityParams, VectorizeEntityResponse } from '../generic/vectorSync.types';\nimport { BatchWorker } from './BatchWorker';\nimport { EntityDocumentCache } from './EntityDocumentCache';\nimport { PagedRecords } from './PagedRecords';\nimport { resolve } from 'node:path';\nimport { PassThrough, Transform } from 'node:stream';\nimport { AIEngine } from '@memberjunction/aiengine';\nimport { TemplateEngineServer } from '@memberjunction/templates';\nimport { TemplateEntityExtended } from '@memberjunction/templates-base-types';\n\n/**\n * Class that specializes in vectorizing entities using embedding models and upserting them into Vector Databases \n */\nexport class EntityVectorSyncer extends VectorBase {\n _startTime: Date;\n _endTime: Date;\n\n constructor() {\n super();\n }\n\n /**\n * Refreshes the EntityDocumentCache and configures the AIEngine and TemplateEngineServer\n * @param forceRefresh If true, the cache and enginges will be refreshed even if it is already loaded\n * @param contextUser The context user to use to refresh the cache and configure the engines\n */\n public async Config(forceRefresh: boolean, contextUser?: UserInfo): Promise<void> {\n super.CurrentUser = contextUser;\n await EntityDocumentCache.Instance.Refresh(forceRefresh, contextUser);\n await AIEngine.Instance.Config(forceRefresh, contextUser);\n await TemplateEngineServer.Instance.Config(forceRefresh, contextUser);\n }\n\n public async VectorizeEntity(params: VectorizeEntityParams, contextUser?: UserInfo): Promise<VectorizeEntityResponse> {\n if (!contextUser) {\n throw new Error('ContextUser is required to vectorize the entity');\n }\n\n //start row\n const delayTimeMS: number = 250;\n const startTime: number = new Date().getTime();\n super.CurrentUser = contextUser;\n await TemplateEngineServer.Instance.Config(false, contextUser);\n \n const entityDocument: EntityDocumentEntity = await this.GetEntityDocument(params.entityDocumentID);\n const vectorIndexEntity: VectorIndexEntity = await this.GetOrCreateVectorIndex(entityDocument);\n const obj: VectorEmeddingData = await this.GetVectorDatabaseAndEmbeddingClassByEntityDocumentID(params.entityDocumentID);\n\n const md = new Metadata();\n const entity: EntityInfo | undefined = md.Entities.find((e) => e.ID === params.entityID);\n if (!entity) throw new Error(`Entity with ID ${params.entityID} not found.`);\n\n\n const template: TemplateEntityExtended | undefined = TemplateEngineServer.Instance.Templates.find((t: TemplateEntityExtended) => t.ID === entityDocument.TemplateID);\n if(!template){\n throw new Error(`Template not found with ID ${entityDocument.TemplateID}`);\n }\n\n if(template.Content.length === 0){\n throw new Error(`Template ${template.ID} does not have an associated Template Content record`);\n }\n\n if(template.Content.length > 1){\n throw new Error('Templates used by Entity Documents should only have one associated Template Content record.');\n }\n\n //If this function doesnt throw an error, then the template is valid\n const validTemplate: boolean = this.ValidateTemplateContextParamAlignment(template);\n\n const pageSize: number = params.batchCount || 20;\n const dataStream = new PagedRecords();\n \n let templateObj: {} = {\n ...template.GetAll(),\n Params: template.Params.map((p) => p.GetAll())\n }; \n\n const workerContext = { \n executionId: Date.now(), \n entity, \n entityDocument: entityDocument.GetAll(),\n template: templateObj,\n templateContent: template.Content[0].GetAll(),\n vectorDBClassKey: obj.vectorDBClassKey,\n vectorDBAPIKey: obj.vectorDBAPIKey,\n embeddingDriverClass: obj.embeddingDriverClass,\n embeddingAPIKey: obj.embeddingAPIKey,\n delayTimeMS\n };\n\n //annotator worker handles vectorizing the records \n const annotator = new BatchWorker({\n workerFile: resolve(__dirname, 'workers/VectorizeTemplates.js'),\n batchSize: 3,\n concurrencyLimit: 2,\n contextUser: super.CurrentUser,\n workerContext,\n });\n\n //archiver worker handles upserting the vectors into the vector database\n const archiver = new BatchWorker({ \n workerFile: resolve(__dirname, 'workers/UpsertVectors.js'), \n batchSize: 4,\n contextUser: super.CurrentUser, \n workerContext\n });\n\n const upserter = new Transform({objectMode: true, transform: (chunk, encoding, callback) => {\n this.UpsertEntityRecordDocumentRecords(chunk as EmbeddingData, super.CurrentUser).then(() => callback(null)).catch(callback);\n }});\n\n const getData = async (): Promise<void> => {\n let pageNumber = 0;\n let hasMore = true;\n\n while (hasMore) {\n let pageRecordRequest: PageRecordsParams = {\n EntityID: params.entityID,\n PageNumber: pageNumber,\n PageSize: pageSize,\n ResultType: 'simple'\n };\n\n const recordsPage: unknown[] = await super.PageRecordsByEntityID<unknown>(pageRecordRequest);\n const relatedData: TemplateParamData[] = await this.GetRelatedTemplateDataForBatch(entity, recordsPage, template);\n const items: {}[] = [];\n \n for(const record of recordsPage){\n const templateData: { [key: string]: unknown } = await this.GetTemplateData(entity, record, template, relatedData);\n //we need a reference to this record's ID for the upsert worker\n templateData.__mj_recordID = record[entity.FirstPrimaryKey.Name];\n templateData.__mj_compositeKey = entity.PrimaryKeys.map((key) => `${key.Name}|${record[key.Name]}`).join(\"||\");\n //we also need a reference to the vector index's ID\n templateData.VectorIndexID = vectorIndexEntity.ID;\n templateData.TemplateContent = template.Content[0].TemplateText;\n items.push(templateData);\n }\n\n dataStream.addPage(items);\n if(recordsPage.length < pageSize) {\n hasMore = false;\n break;\n }\n\n pageNumber++;\n }\n\n dataStream.endStream();\n };\n\n // page data asynchrounously and add to the data stream\n getData();\n\n console.log('Starting pipeline');\n await pipeline(dataStream, annotator, archiver, upserter, new PassThrough({ objectMode: true }));\n\n // const chunks: BaseEntity[][] = this.chunkArray(allrecords, batchSize);\n // LogStatus(`Processing ${allrecords.length} records in ${chunks.length} chunks of ${batchSize} records each`);\n // LogStatus(`Processing page ${pageNumber} records of ${pageSize} records each`);\n\n // Now add the records to the vectorize queue\n // The vectorize queue consumer calls the embedding service to get the embeddings\n // Then adds vectors + record metadata to the storage queue\n // The storage queue consumer adds the vectors to the vector database\n\n // let count = 0;\n // for (const batch of chunks) {\n // let templates: string[] = [];\n // for (const record of batch) {\n // let template: string = await parser.Parse(entityDocument.Template, request.entityID, record, contextUser);\n // templates.push(template);\n // }\n // LogStatus(`parsing batch ${count}: done`);\n\n // const embeddings: EmbedTextsResult = await obj.embedding.EmbedTexts({ texts: templates, model: null });\n // LogStatus(`embedding batch ${count}: done`);\n\n // const vectorRecords: VectorRecord[] = embeddings.vectors.map((vector: number[], index: number) => {\n // const record: BaseEntity = batch[index];\n // const recordID = record.PrimaryKey.Values('|');\n // return {\n // //The id breaks down to e.g. \"Accounts_7_117\"\n // id: `${entityDocument.Entity}_${entityDocument.ID}_${recordID}`,\n // values: vector,\n // metadata: {\n // EntityID: entityDocument.EntityID,\n // EntityName: entityDocument.Entity,\n // EntityDocumentID: entityDocument.ID,\n // PrimaryKey: record.PrimaryKey.ToString(),\n // Template: templates[index],\n // Data: this.ConvertEntityFieldsToString(record),\n // },\n // };\n // });\n\n // const response: BaseResponse = await obj.vectorDB.createRecords(vectorRecords);\n // if (response.success && vectorIndexEntity) {\n // LogStatus('Successfully created vector records, creating associated Entity Record Documents...');\n // for (const [index, vectorRecord] of vectorRecords.entries()) {\n // try {\n // let erdEntity: EntityRecordDocumentEntity = await super.Metadata.GetEntityObject('Entity Record Documents');\n // erdEntity.NewRecord();\n // erdEntity.EntityID = entityDocument.EntityID;\n // erdEntity.RecordID = batch[index].PrimaryKey.ToString();\n // erdEntity.DocumentText = templates[index];\n // erdEntity.VectorID = vectorRecord.id;\n // erdEntity.VectorJSON = JSON.stringify(vectorRecord.values);\n // erdEntity.VectorIndexID = vectorIndexEntity.ID;\n // erdEntity.EntityRecordUpdatedAt = new Date();\n // erdEntity.EntityDocumentID = entityDocument.ID;\n // let erdEntitySaveResult: boolean = await super.SaveEntity(erdEntity);\n // if (!erdEntitySaveResult) {\n // LogError('Error saving Entity Record Document Entity');\n // }\n // } catch (err) {\n // LogError('Error saving Entity Record Document Entity');\n // LogError(err);\n // }\n // }\n // } else {\n // LogError('Unable to successfully save records to vector database', undefined, response.message);\n // }\n\n // //add a delay to avoid rate limiting\n // let delayRes = await this.delay(1000);\n // count += 1;\n // LogStatus(`Chunk ${count} of out ${chunks.length} processed`);\n // }\n\n const endTime: number = new Date().getTime();\n LogStatus(`Finished vectorizing ${entityDocument.Entity} entity in ${endTime - startTime} ms`);\n return null;\n }\n\n /**\n * This method will create a default Entity Document for the given entityID, vectorDatabase, and AIModel\n * @param entityID\n * @param vectorDatabase\n * @param AIModel\n * @returns\n */\n public async CreateDefaultEntityDocument(\n EntityID: string,\n VectorDatabase: VectorDatabaseEntity,\n AIModel: AIModelEntity\n ): Promise<EntityDocumentEntity> {\n const md = new Metadata();\n const entity = md.Entities.find((e) => e.ID === EntityID);\n if (!entity) throw new Error(`Entity with ID ${EntityID} not found.`);\n\n const EDTemplate: string = entity.Fields.map((ef) => {\n return `${ef.Name}: \\$\\{${ef.Name}\\}`;\n }).join(' ');\n\n const entityDocument: EntityDocumentEntity = await md.GetEntityObject<EntityDocumentEntity>('Entity Documents');\n entityDocument.NewRecord();\n entityDocument.Name = `Default duplicate record Entity Document for the ${entity.Name} entity using vector database ${VectorDatabase.Name} and AI Model ${AIModel.Name}`;\n entityDocument.EntityID = EntityID;\n entityDocument.TypeID = RECORD_DUPLICATES_TYPE_ID;\n entityDocument.Status = 'Active';\n entityDocument.TemplateID = EDTemplate;\n entityDocument.VectorDatabaseID = VectorDatabase.ID;\n entityDocument.AIModelID = AIModel.ID;\n let saveResult = await this.SaveEntity(entityDocument);\n if (saveResult) {\n return entityDocument;\n } else {\n throw new Error(`Failed to save Entity Document for ${EntityID}`);\n }\n }\n\n protected async GetVectorDatabaseAndEmbeddingClassByEntityDocumentID( entityDocumentID: string, createDocumentIfNotFound?: boolean ): Promise<VectorEmeddingData> {\n let entityDocument: EntityDocumentEntity | null = EntityDocumentCache.Instance.GetDocument(entityDocumentID);\n if (!entityDocument) {\n if (createDocumentIfNotFound) {\n LogStatus(`No active Entity Document found for entity ${entityDocumentID}, creating one`);\n const defaultVectorDB: VectorDatabaseEntity = this.GetVectorDatabase();\n const defaultAIModel: AIModelEntity = this.GetAIModel();\n entityDocument = await this.CreateDefaultEntityDocument(entityDocumentID, defaultVectorDB, defaultAIModel);\n } \n else {\n throw new Error(`No Entity Document found for ID=${entityDocumentID}`);\n }\n }\n\n const vectorDBEntity: VectorDatabaseEntity = this.GetVectorDatabase(entityDocument.VectorDatabaseID);\n const aiModelEntity: AIModelEntity = this.GetAIModel(entityDocument.AIModelID);\n\n const embeddingAPIKey: string = GetAIAPIKey(aiModelEntity.DriverClass);\n const vectorDBAPIKey: string = GetAIAPIKey(vectorDBEntity.ClassKey);\n\n if (!embeddingAPIKey) {\n throw Error(`No API Key found for AI Model ${aiModelEntity.DriverClass}`);\n }\n\n if (!vectorDBAPIKey) {\n throw Error(`No API Key found for Vector Database ${vectorDBEntity.ClassKey}`);\n }\n\n //LogStatus(`Embedding API Key: ${embeddingAPIKey} VectorDB API Key: ${vectorDBAPIKey}`);\n const embedding = MJGlobal.Instance.ClassFactory.CreateInstance<Embeddings>(Embeddings, aiModelEntity.DriverClass, embeddingAPIKey);\n const vectorDB = MJGlobal.Instance.ClassFactory.CreateInstance<VectorDBBase>(VectorDBBase, vectorDBEntity.ClassKey, vectorDBAPIKey);\n\n if (!embedding) {\n throw Error(`Failed to create Embeddings instance for AI Model ${aiModelEntity.DriverClass}`);\n }\n\n if (!vectorDB) {\n throw Error(`Failed to create Vector Database instance for ${vectorDBEntity.ClassKey}`);\n }\n\n LogStatus(`Using vector database ${vectorDBEntity.Name} and AI Model ${aiModelEntity.Name}`);\n\n const obj: VectorEmeddingData = { \n embedding, \n vectorDB, \n vectorDBClassKey: vectorDBEntity.ClassKey, \n vectorDBAPIKey: vectorDBAPIKey,\n embeddingDriverClass: aiModelEntity.DriverClass,\n embeddingAPIKey: embeddingAPIKey\n };\n\n return obj;\n }\n\n public async GetEntityDocument(EntityDocumentID: string): Promise<EntityDocumentEntity | null> {\n const cache = EntityDocumentCache.Instance;\n if (!cache.IsLoaded) {\n await cache.Refresh(false, super.CurrentUser);\n }\n return cache.GetDocument(EntityDocumentID);\n }\n\n public async GetEntityDocumentByName(EntityDocumentName: string, ContextUser?: UserInfo): Promise<EntityDocumentEntity | null> {\n const cache = EntityDocumentCache.Instance;\n if (!cache.IsLoaded) {\n await cache.Refresh(false, ContextUser);\n }\n return cache.GetDocumentByName(EntityDocumentName);\n }\n\n /**\n * Returns all active Entity Documents of the 'Record Duplicate' type.\n * Note that this only returns the first active Entity Document. Meaning if there are multiple Entity Documents for the same entity, \n * only the oldest one will be returned.\n * @param entityIDs If provided, only Entity Documents for the specified entities will be returned.\n */\n public async GetActiveEntityDocuments(entityNames?: string[]): Promise<EntityDocumentEntity[]> {\n await EntityDocumentCache.Instance.Refresh(false, super.CurrentUser);\n const entityDocumentType: EntityDocumentTypeEntity | undefined = EntityDocumentCache.Instance.GetDocumentTypeByName('Record Duplicate');\n if (!entityDocumentType) {\n throw new Error('Entity Document Type not found');\n }\n\n let filter = `TypeID = '${entityDocumentType.ID}' AND Status = 'Active' `;\n if (entityNames && entityNames.length > 0) {\n filter += ` AND Entity IN (${entityNames.map((entityName: string) => `'${entityName}'`).join(',')})`;\n }\n\n const runViewResult: RunViewResult<EntityDocumentEntity> = await super.RunView.RunView<EntityDocumentEntity>({\n EntityName: 'Entity Documents',\n ExtraFilter: filter,\n ResultType: 'entity_object',\n }, super.CurrentUser);\n\n if(!runViewResult.Success){\n throw new Error(runViewResult.ErrorMessage);\n }\n\n let entityDocuments: EntityDocumentEntity[] = [];\n let seenEntities: string[] = [];\n\n //we only want one entity document per entity\n for(const entityDocument of runViewResult.Results){\n if(seenEntities.includes(entityDocument.EntityID)){\n continue;\n }\n \n entityDocuments.push(entityDocument);\n seenEntities.push(entityDocument.EntityID);\n }\n\n return entityDocuments;\n }\n\n private async GetOrCreateVectorIndex(entityDocument: EntityDocumentEntity): Promise<VectorIndexEntity> {\n let vectorIndexEntity: VectorIndexEntity = await super.RunViewForSingleValue(\n 'Vector Indexes',\n `VectorDatabaseID = '${entityDocument.VectorDatabaseID}' AND EmbeddingModelID = '${entityDocument.AIModelID}'`\n );\n\n if (vectorIndexEntity) {\n return vectorIndexEntity;\n }\n\n LogStatus(`No Vector Index found for entityDocument ${entityDocument.ID}, creating one`);\n try {\n vectorIndexEntity = await super.Metadata.GetEntityObject<VectorIndexEntity>('Vector Indexes');\n vectorIndexEntity.NewRecord();\n vectorIndexEntity.VectorDatabaseID = entityDocument.VectorDatabaseID;\n vectorIndexEntity.EmbeddingModelID = entityDocument.AIModelID;\n vectorIndexEntity.Name = `Vector Index for entityDocument ${entityDocument.EntityID}`;\n vectorIndexEntity.Set('EntityRecordUpdatedAt', new Date());\n vectorIndexEntity.Set('EntityDocumentID', entityDocument.ID);\n //not a very descriptive description, but the view has the name of the vectorDB and embedding model used\n vectorIndexEntity.Description = `Vector Index that uses the Vector database ${entityDocument.VectorDatabaseID} and ${entityDocument.AIModelID} as the embedding model`;\n const saveResult = await super.SaveEntity(vectorIndexEntity);\n if (saveResult) {\n LogStatus(`Successfully created new Vector Index Entity`);\n return vectorIndexEntity;\n } else {\n LogError('Error saving Vector Index Entity');\n return null;\n }\n } catch (err) {\n console.error(JSON.stringify(err));\n LogError(err);\n return null;\n }\n }\n\n protected async CreateTemplateForEntityDocument(entityDocument: EntityDocumentEntity): Promise<TemplateEntity> {\n const templateEntity: TemplateEntityExtended = await super.Metadata.GetEntityObject<TemplateEntityExtended>('Templates');\n templateEntity.NewRecord();\n templateEntity.Name = `Template for EntityDocument ${entityDocument.EntityID}`;\n templateEntity.Description = `The template used by EntityDocument ${entityDocument.ID}`\n templateEntity.UserID = super.CurrentUser.ID;\n templateEntity.IsActive = true;\n templateEntity.CategoryID = null;\n\n const templateEntitySaveResult = await super.SaveEntity(templateEntity);\n if(!templateEntitySaveResult){\n LogError('Error saving Template Entity', undefined, templateEntity.LatestResult);\n throw new Error(templateEntity.LatestResult.Message);\n }\n LogStatus(`Successfully created new Template Entity ${templateEntity.ID}`);\n\n //next, create the template contents record\n await TemplateEngineServer.Instance.Config(false, super.CurrentUser);\n const textContentType: TemplateContentTypeEntity = TemplateEngineServer.Instance.TemplateContentTypes.find((type: TemplateContentTypeEntity) => type.Name === 'Text');\n if(!textContentType){\n throw new Error('Text template content type not found');\n }\n\n const entityFields: EntityField[] = await this.GetEntityFieldsForSimilaritySearch(entityDocument.EntityID);\n\n const templateContentsEntity: TemplateContentEntity = await super.Metadata.GetEntityObject<TemplateContentEntity>('Template Contents');\n templateContentsEntity.NewRecord();\n templateContentsEntity.TemplateID = templateEntity.ID;\n templateContentsEntity.TypeID = textContentType.ID;\n templateContentsEntity.Priority = 1;\n templateContentsEntity.IsActive = true;\n templateContentsEntity.TemplateText = this.BuildTemplateContent(entityFields);\n\n const templateContentsEntitySaveResult = await super.SaveEntity(templateContentsEntity);\n if(!templateContentsEntitySaveResult){\n LogError('Error saving Template Entity', undefined, templateContentsEntity.LatestResult);\n throw new Error(templateContentsEntity.LatestResult.Message);\n }\n LogStatus(`Successfully created new Template Content Entity ${templateContentsEntity.ID}`);\n\n //next, create the template params record\n const templateParamsEntity: TemplateParamEntity = await super.Metadata.GetEntityObject<TemplateParamEntity>('Template Params');\n templateParamsEntity.NewRecord();\n templateParamsEntity.TemplateID = templateEntity.ID;\n templateParamsEntity.Name = 'Entity';\n templateParamsEntity.Description = 'The entity object to be used in the template';\n templateParamsEntity.Type = 'Record';\n templateParamsEntity.DefaultValue = null;\n templateParamsEntity.IsRequired = true;\n templateParamsEntity.LinkedParameterName = null;\n templateParamsEntity.LinkedParameterField = null;\n templateParamsEntity.ExtraFilter = null;\n templateParamsEntity.EntityID = entityDocument.EntityID;\n templateParamsEntity.RecordID = null;\n\n const templateParamsEntitySaveResult = await super.SaveEntity(templateParamsEntity);\n if(!templateParamsEntitySaveResult){\n LogError('Error saving Template Entity', undefined, templateParamsEntity.LatestResult);\n throw new Error(templateParamsEntity.LatestResult.Message);\n }\n LogStatus(`Successfully created new Template Param Entity ${templateParamsEntity.ID}`);\n \n templateEntity.Content.push(templateContentsEntity);\n templateEntity.Params.push(templateParamsEntity);\n TemplateEngineServer.Instance.AddTemplate(templateEntity);\n\n return templateEntity;\n }\n\n protected BuildTemplateContent(entityFields: EntityField[]): string {\n return entityFields.map((field: EntityField) => {\n return `{{Entity.${field.Name}}}`;\n }).join(' ');\n }\n\n protected async GetEntityFieldsForSimilaritySearch(entityID: string): Promise<EntityField[]> {\n //We only want fields that can potentially be the same across records\n //which means things such as IDs, timestamps, etc. are not useful\n //as they're likely to be unique or not that helpful in determining similarity\n const runViewResult: RunViewResult<EntityField> = await super.RunView.RunView<EntityField>({\n EntityName: 'Entity Fields',\n ExtraFilter: `EntityID = '${entityID}' AND IsPrimaryKey = 0 AND IsUnique = 0 AND AutoIncrement = 0 and Type NOT IN ('datetimeoffset', 'datetime')`,\n ResultType: 'entity_object',\n }, super.CurrentUser);\n\n if (!runViewResult.Success) {\n throw new Error(runViewResult.ErrorMessage);\n }\n\n return runViewResult.Results;\n }\n\n protected async GetTemplateData(entity: EntityInfo, record: unknown, template: TemplateEntityExtended, relatedData: TemplateParamData[]): Promise<{ [key: string]: any }> {\n const templateData: { [key: string]: unknown } = {};\n for(const param of template.Params){\n if(templateData[param.Name]){\n continue;\n }\n\n switch(param.Type){\n case 'Record':\n // this one is simple, we create a property by the provided name, and set the value to the record we are currently processing\n templateData[param.Name] = record;\n break;\n case 'Entity':\n // here we need to grab the related data from another entity and filter it down for the record we are current processing so it only shows the related data\n // the metadata in the param tells us what we need to know\n const paramData: TemplateParamData | undefined = relatedData.find((rd: TemplateParamData) => rd.ParamName === param.Name);\n if(!paramData){\n LogError(`No related data found for param ${param.Name} in template ${template.ID}`);\n break;\n }\n\n // now filter down the data in d to just this record and set the value of the context data to the filtered data\n templateData[param.Name] = paramData.Data.filter((rdfr: BaseEntity) => rdfr[param.LinkedParameterField] === record[entity.FirstPrimaryKey.Name]);\n break;\n case \"Array\":\n case \"Scalar\":\n case \"Object\":\n // do nothing here, as we don't directly support these param types\n LogError(`Unsupported parameter type ${param.Type} for parameter ${param.Name} in template ${template.ID}`);\n break;\n }\n }\n return templateData;\n }\n\n protected async GetRelatedTemplateDataForBatch(entity: EntityInfo, records: unknown[], template: TemplateEntityExtended): Promise<TemplateParamData[]> {\n const relatedData: TemplateParamData[] = [];\n\n records.forEach((record: unknown) => {\n console.log(JSON.stringify(record, null, 4));\n console.log(record[entity.FirstPrimaryKey.Name]);\n });\n\n for(const templateParam of template.Params){\n if(templateParam.Type !== 'Entity'){\n continue;\n }\n\n const relatedEntity = templateParam.Entity;\n const relatedField = templateParam.LinkedParameterField;\n\n // construct a filter for the related field so that we constrain the results to just the set of records linked to our recipients\n const quotes = entity.FirstPrimaryKey.NeedsQuotes ? \"'\" : \"\";\n const filter = `${relatedField} in (${records.map((record: unknown) => `${quotes}${record[entity.FirstPrimaryKey.Name]}${quotes}`).join(',')})`;\n const finalFilter = templateParam.ExtraFilter ? `(${filter}) AND (${templateParam.ExtraFilter})` : filter;\n\n const result = await super.RunView.RunView<unknown>({\n EntityName: relatedEntity,\n ExtraFilter: finalFilter,\n ResultType: 'simple'\n }, super.CurrentUser);\n\n if (result && result.Success) {\n const data: TemplateParamData = { ParamName: '', Data: [] };\n data.ParamName = templateParam.Name,\n data.Data = result.Results;\n relatedData.push(data);\n }\n else {\n LogError(`Error getting related data for entity ${relatedEntity} with filter ${finalFilter}`, undefined, result.ErrorMessage);\n }\n }\n\n return relatedData;\n }\n\n // Rather than having this logic inside the EntityRecordDocumentWorker class, it's placed here instead\n //so that the logic behind vectorizing entities isnt spread out across so many files\n protected async UpsertEntityRecordDocumentRecords(embeddingData: EmbeddingData, contextUser: UserInfo): Promise<void> {\n let md: Metadata = super.Metadata;\n let rv: RunView = super.RunView;\n let success: boolean = true;\n\n let vectorIndex: VectorIndexEntity = await md.GetEntityObject<VectorIndexEntity>('Vector Indexes', contextUser);\n let vectorIndexID: string = embeddingData.VectorIndexID.toString();\n let loadResult = await vectorIndex.Load(vectorIndexID);\n if(!loadResult){\n LogError(`Vector Index with ID ${embeddingData.VectorIndexID} not found`);\n return;\n }\n\n let entityDocument: Record<string, unknown> = embeddingData.EntityDocument;\n let entityID: unknown = entityDocument.EntityID;\n\n let existingRecords: BaseEntity[] = [];\n const runViewResult: RunViewResult<BaseEntity> = await rv.RunView<BaseEntity>({\n EntityName: 'Entity Record Documents',\n ExtraFilter: `EntityID = '${entityID}' AND EntityDocumentID = '${entityDocument.ID}' AND RecordID in (${embeddingData.__mj_recordID})`,\n ResultType: 'entity_object'\n }, contextUser);\n \n if(runViewResult.Success){\n existingRecords = runViewResult.Results;\n }\n else {\n LogError(`Error getting existing Entity Record Documents`, undefined, runViewResult.ErrorMessage);\n }\n\n let erdEntity: BaseEntity | undefined = existingRecords.find((er: BaseEntity) => er.Get(\"RecordID\").toString() === embeddingData.__mj_recordID.toString());\n if(!erdEntity){\n erdEntity = await md.GetEntityObject<BaseEntity>('Entity Record Documents', contextUser);\n erdEntity.NewRecord();\n }\n\n erdEntity.Set(\"EntityID\", entityID.toString());\n erdEntity.Set(\"RecordID\", embeddingData.__mj_recordID.toString());\n erdEntity.Set(\"DocumentText\", embeddingData.TemplateContent);\n erdEntity.Set(\"VectorID\", embeddingData.VectorID.toString());\n erdEntity.Set(\"VectorJSON\", JSON.stringify(embeddingData.Vector));\n erdEntity.Set(\"VectorIndexID\", embeddingData.VectorIndexID.toString());\n erdEntity.Set(\"EntityRecordUpdatedAt\", new Date());\n erdEntity.Set(\"EntityDocumentID\", embeddingData.EntityDocument.ID.toString());\n erdEntity.ContextCurrentUser = contextUser;\n \n let erdEntitySaveResult: boolean = await erdEntity.Save();\n if(!erdEntitySaveResult){\n LogError('Error saving Entity Record Document Entity', undefined, erdEntity.LatestResult);\n success = false;\n }\n\n if(success){\n LogStatus(\"Upserting Entity Record Documents: Complete\");\n }\n else{\n LogError(\"Upserting Entity Record Documents: Fail\");\n }\n }\n\n /**\n * This method is resposnible for determining if the template(s) given have aligned parameters, meaning they don't have overlapping parameter names that have \n * different meanings. It is okay for scenarios where there are > 1 template in use for a message to have different parameter names, but if they have the SAME parameter names\n * they must not have different settings.\n */\n protected ValidateTemplateContextParamAlignment(template: TemplateEntityExtended): boolean {\n // the params are defined in each template they will be in the Params property of the template\n const seenParams: {[key: string]: TemplateParamEntity } = {};\n for (const templateParam of template.Params) {\n const param: TemplateParamEntity | undefined = seenParams[templateParam.Name];\n // we have a duplicate parameter name, now we need to check if the definitions are the same\n if(param && param.Type !== templateParam.Type){\n throw new Error(`Parameter ${param.Name} has different types in different templates`);\n }\n else {\n seenParams[templateParam.Name] = templateParam;\n }\n }\n\n // if we get here, we are good, otherwise we will have thrown an exception\n return true;\n }\n}\n","import { CompositeKey, Metadata, UserInfo } from '@memberjunction/core';\n\n/**\n * This is an abstract base class, use the EntityDocumentTemplateParser class or a sub-class thereof.\n */\nexport abstract class EntityDocumentTemplateParserBase {\n public static ClearCache() {\n EntityDocumentTemplateParserBase.__cache = {};\n }\n public static CreateCacheKey(EntityID: string, EntityRecordPrimaryKey: string, Content: string): string {\n return `${EntityID}___${EntityRecordPrimaryKey}___${Content}`;\n }\n\n protected static __cache: { [key: string]: string } = {};\n protected static get _cache(): { [key: string]: string } {\n return EntityDocumentTemplateParserBase.__cache;\n }\n\n /**\n * This method will parse an entity document template and replace values within ${} placeholders with actual values from the entity record. In the case of function calls\n * within the placeholders, the functions object must be provided to parse the function calls.\n * @param Template - the document template to parse\n * @param EntityID - the ID of the entity\n * @param EntityRecord - the values for the entity record\n * @param ContextUser - the current user\n * @returns the evaluated value of the template incorporating fields and function call(s), if any.\n */\n public async Parse(Template: string, EntityID: string, EntityRecord: any, ContextUser: UserInfo): Promise<string> {\n if (!ContextUser) {\n throw new Error('ContextUser is required to parse the template');\n }\n\n const md = new Metadata();\n const entityInfo = md.Entities.find((e) => e.ID === EntityID);\n if (!entityInfo) {\n throw new Error(`Entity with ID ${EntityID} not found.`);\n }\n\n let compositeKey: CompositeKey = new CompositeKey();\n compositeKey.LoadFromEntityInfoAndRecord(entityInfo, EntityRecord);\n\n const regex = /\\$\\{([^{}]+)\\}/g;\n const matches = Template.matchAll(regex);\n\n // Convert matches to an array to handle them asynchronously\n const replacements = Array.from(matches).map(async (match) => {\n const content = match[1]; // The captured group from regex\n const cacheKey = EntityDocumentTemplateParserBase.CreateCacheKey(EntityID, compositeKey.ToString(), content);\n\n // check the cache and if we don't have an entry in the cache, add it\n if (!EntityDocumentTemplateParserBase._cache[cacheKey]) {\n // Cache miss, evaluate and store the result\n EntityDocumentTemplateParserBase._cache[cacheKey] = await this.evalSingleArgument(content, EntityID, EntityRecord, ContextUser);\n }\n\n return {\n old: match[0], // The entire placeholder including ${}\n new: EntityDocumentTemplateParserBase._cache[cacheKey], // The replacement value\n };\n });\n\n // Resolve all promises\n const resolvedReplacements = await Promise.all(replacements);\n\n // Replace each placeholder in the template with its resolved value\n let resolvedTemplate = Template;\n resolvedReplacements.forEach((replacement) => {\n resolvedTemplate = resolvedTemplate.replace(replacement.old, replacement.new);\n });\n\n return resolvedTemplate;\n }\n\n protected async evalSingleArgument(argument: string, entityID: string, entityRecord: any, ContextUser: UserInfo): Promise<string> {\n const funcMatch = argument.match(/(\\w+)\\(([^)]*)\\)/);\n if (funcMatch) {\n const [, funcName, paramsString] = funcMatch;\n const params = paramsString.split(',').map((param) => {\n param = param.trim();\n //if the string is wrapped in single or double quotes, remove them\n if (param.startsWith('\"') && param.endsWith('\"')) {\n return param.slice(1, -1);\n } else if (param.startsWith(\"'\") && param.endsWith(\"'\")) {\n return param.slice(1, -1);\n } else {\n return param;\n }\n });\n\n // Check if the method exists on this instance\n if (typeof this[funcName] === 'function') {\n // Call the instance method dynamically using its name and spread the params\n return this[funcName](entityID, entityRecord, ContextUser, ...params);\n } else {\n throw new Error(`Function ${funcName} is not defined.`);\n }\n } else {\n // not a function match, attempt to return the value from the entity record\n return entityRecord[argument] !== undefined ? entityRecord[argument] : '';\n }\n }\n}\n","import { CompositeKey, LogError, LogStatus, Metadata, UserInfo } from \"@memberjunction/core\";\nimport { MJGlobal, RegisterClass } from \"@memberjunction/global\";\nimport { EntityVectorSyncer } from \"../models/entityVectorSync\";\nimport { EntityDocumentTemplateParserBase } from \"./EntityDocumenTemplateParserBase\";\n\n/**\n * This is the first-level sub-class of EntityDocumentTemplateParserBase. This class is used to parse a string template with variables and functions. \n * If you wish to override functionality you can subclass it and then use the @RegisterClass decorator to register the sub-class of EntityDocumentTemplateParser with a priority of 1 or above to \n * then be used instead of the default implementation.\n */\n@RegisterClass(EntityDocumentTemplateParser)\nexport class EntityDocumentTemplateParser extends EntityDocumentTemplateParserBase {\n\n /** Convenience method to get an instance of the class and uses the ClassFactory so we can create sub-classes if they are registered with higher priorities than the base class */\n public static CreateInstance(): EntityDocumentTemplateParser {\n return MJGlobal.Instance.ClassFactory.CreateInstance<EntityDocumentTemplateParser>(EntityDocumentTemplateParser);\n }\n\n /**\n * This function \n * @param entityID \n * @param entityRecord \n * @param relationshipName \n * @param maxRows \n * @param entityDocumentName \n * @returns \n */\n protected async Relationship(entityID: string, entityRecord: any, ContextUser: UserInfo, relationshipName: string, maxRows: number, entityDocumentName: string): Promise<string> {\n // super inefficient handling to start, we'll optimize this later to call the related stuff in batch\n const md = new Metadata();\n const vectorSyncer: EntityVectorSyncer = new EntityVectorSyncer();\n vectorSyncer.CurrentUser = ContextUser;\n\n const entityInfo = md.Entities.find(e => e.ID === entityID); \n if (!entityInfo){\n throw new Error(`Entity with ID ${entityID} not found.`);\n }\n\n const re = entityInfo.RelatedEntities.find(re => re.RelatedEntity === relationshipName);\n if (!re){\n throw new Error(`Relationship ${relationshipName} not found for entity ${entityInfo.Name}`);\n }\n\n const obj = await md.GetEntityObject(entityInfo.Name, ContextUser);\n let compositeKey: CompositeKey = new CompositeKey();\n compositeKey.LoadFromEntityInfoAndRecord(entityInfo, entityRecord);\n let loadResult: boolean = await obj.InnerLoad(compositeKey);\n if (!loadResult){\n LogError(`Failed to load entity ${entityInfo.Name} with ID ${compositeKey.ToString()}`);\n return \"\";\n }\n\n const reData = await obj.GetRelatedEntityDataExt(re, null, maxRows)\n\n if (reData && reData.Data) {\n // now, get the entity document info if provided\n if (entityDocumentName && entityDocumentName.trim().length > 0) {\n // we have a document name, attempt to locate it\n const doc = await vectorSyncer.GetEntityDocumentByName(entityDocumentName, ContextUser);\n if (doc) {\n // we have the document, now we need to parse it and build a result that is the concatenation of all the parsed documents\n // start off by creating an instance of the parser using CreateInstance() so we're using the highest priority registered subclass\n const parser = EntityDocumentTemplateParser.CreateInstance();\n\n // now we need to batch the requests to the parser to have the right concurrency\n const batchSize = 10; // Set the batch size to the desired number of concurrent requests\n const results = [];\n \n for (let i = 0; i < reData.Data.length; i += batchSize) {\n const batchPromises = reData.Data.slice(i, i + batchSize).map(data => {\n return parser.Parse((doc as any).Template, re.RelatedEntityID, data, ContextUser);\n });\n const batchResults = await Promise.all(batchPromises);\n results.push(...batchResults);\n }\n \n return results.map(r => r + \"\\n\\n\").join('');\n }\n else {\n LogStatus(`Entity Document with name ${entityDocumentName} not found.`);\n return \"\";\n }\n }\n else {\n // no entity document name provided, just return the data in a simple format\n return JSON.stringify({ Relationship: relationshipName, Data: reData.Data});\n }\n }\n else {\n return \"{ No Data for: \" + relationshipName + \" }\"\n }\n }\n}"],"names":["Transform","Worker","LogStatus","RunView","Readable","VectorBase","AIEngine","TemplateEngineServer","Metadata","resolve","pipeline","PassThrough","GetAIAPIKey","MJGlobal","Embeddings","VectorDBBase","LogError","CompositeKey","EntityDocumentTemplateParser","RegisterClass"],"mappings":";;;;;;;;;;;;;;AAAO,MAAM,yBAAyB,GAAG,yDAAyD;;ACE3F,MAAM,WAAW,SAASA,qBAAS,CAAC;AAC3C,EAAE,UAAU,GAAG,EAAE,CAAC;AAClB,EAAE,WAAW,GAAG,aAAa,CAAC;AAC9B,EAAE,cAAc,GAAG,EAAE,CAAC;AACtB,EAAE,iBAAiB,GAAG,CAAC,CAAC;AACxB,EAAE,QAAQ,GAAG,CAAC,CAAC;AACf,EAAE,OAAO,GAAG,EAAE,CAAC;AACf,EAAE,MAAM,GAAG,EAAE,CAAC;AACd,EAAE,YAAY,GAAG,KAAK,CAAC,CAAC;AACxB;AACA;AACA;AACA,EAAE,WAAW,CAAC,OAAO,GAAG,EAAE,EAAE;AAC5B,IAAI,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAChC,IAAI,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC;AAC3D,IAAI,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC;AAC9D,IAAI,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,cAAc,CAAC;AACvE,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,cAAS,CAAC,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;AAClF,UAAU,OAAO,EAAE,CAAC;AACpB,SAAS;AACT,OAAO,MAAM;AACb,QAAQ,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACrF,OAAO;AACP,KAAK,MAAM;AACX,MAAM,OAAO,iBAAiB,GAAG,gBAAgB,GAAG,IAAI,CAAC;AACzD,KAAK;AACL,GAAG;AACH,EAAE;AACFgB,oCAA4B,GAAG,eAAe,CAAC;AAC/C,EAAEC,oBAAa,CAACD,oCAA4B,CAAC;AAC7C,CAAC,EAAEA,oCAA4B,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-vector-sync",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "MemberJunction: AI Vector/Entity Sync Package - handles synchronization between MemberJunction entities and vector databases",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
"author": "MemberJunction.com",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@memberjunction/ai": "2.
|
|
19
|
-
"@memberjunction/ai-vectordb": "2.
|
|
20
|
-
"@memberjunction/ai-vectors": "2.
|
|
21
|
-
"@memberjunction/ai-vectors-pinecone": "2.
|
|
22
|
-
"@memberjunction/ai-mistral": "2.
|
|
23
|
-
"@memberjunction/aiengine": "2.
|
|
24
|
-
"@memberjunction/core": "2.
|
|
25
|
-
"@memberjunction/global": "2.
|
|
26
|
-
"@memberjunction/templates": "2.
|
|
27
|
-
"@memberjunction/templates-base-types": "2.
|
|
28
|
-
"@memberjunction/ai-openai": "2.
|
|
18
|
+
"@memberjunction/ai": "2.1.0",
|
|
19
|
+
"@memberjunction/ai-vectordb": "2.1.0",
|
|
20
|
+
"@memberjunction/ai-vectors": "2.1.0",
|
|
21
|
+
"@memberjunction/ai-vectors-pinecone": "2.1.0",
|
|
22
|
+
"@memberjunction/ai-mistral": "2.1.0",
|
|
23
|
+
"@memberjunction/aiengine": "2.1.0",
|
|
24
|
+
"@memberjunction/core": "2.1.0",
|
|
25
|
+
"@memberjunction/global": "2.1.0",
|
|
26
|
+
"@memberjunction/templates": "2.1.0",
|
|
27
|
+
"@memberjunction/templates-base-types": "2.1.0",
|
|
28
|
+
"@memberjunction/ai-openai": "2.1.0",
|
|
29
29
|
"dotenv": "^16.4.1",
|
|
30
30
|
"typeorm": "^0.3.20"
|
|
31
31
|
},
|