@memberjunction/ai-vectors 2.112.0 → 2.113.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/README.md
CHANGED
|
@@ -119,7 +119,7 @@ Create specialized vector operation classes by extending `VectorBase`:
|
|
|
119
119
|
|
|
120
120
|
```typescript
|
|
121
121
|
import { VectorBase, PageRecordsParams } from '@memberjunction/ai-vectors';
|
|
122
|
-
import { BaseEntity } from '@memberjunction/
|
|
122
|
+
import { BaseEntity } from '@memberjunction/core';
|
|
123
123
|
|
|
124
124
|
export class MyVectorProcessor extends VectorBase {
|
|
125
125
|
async processEntityRecords(entityId: string): Promise<void> {
|
|
@@ -175,7 +175,7 @@ The package provides utilities for working with MemberJunction entities:
|
|
|
175
175
|
|
|
176
176
|
```typescript
|
|
177
177
|
import { VectorBase, PageRecordsParams } from '@memberjunction/ai-vectors';
|
|
178
|
-
import { BaseEntity } from '@memberjunction/
|
|
178
|
+
import { BaseEntity } from '@memberjunction/core';
|
|
179
179
|
import { AIModelEntityExtended, VectorDatabaseEntity } from '@memberjunction/core-entities';
|
|
180
180
|
|
|
181
181
|
class EntityVectorizer extends VectorBase {
|
|
@@ -226,7 +226,7 @@ Use composite keys for complex filtering scenarios:
|
|
|
226
226
|
|
|
227
227
|
```typescript
|
|
228
228
|
import { VectorBase } from '@memberjunction/ai-vectors';
|
|
229
|
-
import { CompositeKey } from '@memberjunction/
|
|
229
|
+
import { CompositeKey } from '@memberjunction/core';
|
|
230
230
|
|
|
231
231
|
class AdvancedVectorProcessor extends VectorBase {
|
|
232
232
|
async getSpecificRecords(entityId: string): Promise<void> {
|
|
@@ -260,7 +260,7 @@ This package works in harmony with other MemberJunction packages:
|
|
|
260
260
|
```typescript
|
|
261
261
|
import { VectorBase } from '@memberjunction/ai-vectors';
|
|
262
262
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
263
|
-
import { Metadata, RunView } from '@memberjunction/
|
|
263
|
+
import { Metadata, RunView } from '@memberjunction/core';
|
|
264
264
|
|
|
265
265
|
// Your vector processing will have access to:
|
|
266
266
|
// - Entity metadata
|
|
@@ -353,4 +353,4 @@ When contributing to this package:
|
|
|
353
353
|
|
|
354
354
|
## License
|
|
355
355
|
|
|
356
|
-
ISC
|
|
356
|
+
ISC
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseEntity, Metadata, CompositeKey, RunView, UserInfo } from
|
|
2
|
-
import { AIModelEntityExtended, VectorDatabaseEntity } from
|
|
3
|
-
import { PageRecordsParams } from
|
|
1
|
+
import { BaseEntity, Metadata, CompositeKey, RunView, UserInfo } from "@memberjunction/core";
|
|
2
|
+
import { AIModelEntityExtended, VectorDatabaseEntity } from "@memberjunction/core-entities";
|
|
3
|
+
import { PageRecordsParams } from "../generic/VectorCore.types";
|
|
4
4
|
export declare class VectorBase {
|
|
5
5
|
_runView: RunView;
|
|
6
6
|
_metadata: Metadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VectorBase.d.ts","sourceRoot":"","sources":["../../src/models/VectorBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAuC,MAAM,
|
|
1
|
+
{"version":3,"file":"VectorBase.d.ts","sourceRoot":"","sources":["../../src/models/VectorBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAuC,MAAM,sBAAsB,CAAC;AAClI,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,qBAAa,UAAU;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,QAAQ,CAAC;IACpB,YAAY,EAAE,QAAQ,CAAC;;IAQvB,IAAW,QAAQ,IAAI,QAAQ,CAA2B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IACvD,IAAW,WAAW,IAAI,QAAQ,CAA8B;IAChE,IAAW,WAAW,CAAC,IAAI,EAAE,QAAQ,EAA+B;cAEpD,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;cAqBzF,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAqBjF,SAAS,CAAC,gBAAgB,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,MAAM;IAQhE,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,qBAAqB;IAexD,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,oBAAoB;cAgB9C,qBAAqB,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;cAoBvG,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAInE"}
|
|
@@ -2,28 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VectorBase = void 0;
|
|
4
4
|
const aiengine_1 = require("@memberjunction/aiengine");
|
|
5
|
-
const
|
|
5
|
+
const core_1 = require("@memberjunction/core");
|
|
6
6
|
class VectorBase {
|
|
7
7
|
constructor() {
|
|
8
|
-
this._runView = new
|
|
9
|
-
this._metadata = new
|
|
8
|
+
this._runView = new core_1.RunView();
|
|
9
|
+
this._metadata = new core_1.Metadata();
|
|
10
10
|
this._currentUser = this._metadata.CurrentUser;
|
|
11
11
|
}
|
|
12
|
-
get Metadata() {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return this._runView;
|
|
17
|
-
}
|
|
18
|
-
get CurrentUser() {
|
|
19
|
-
return this._currentUser;
|
|
20
|
-
}
|
|
21
|
-
set CurrentUser(user) {
|
|
22
|
-
this._currentUser = user;
|
|
23
|
-
}
|
|
12
|
+
get Metadata() { return this._metadata; }
|
|
13
|
+
get RunView() { return this._runView; }
|
|
14
|
+
get CurrentUser() { return this._currentUser; }
|
|
15
|
+
set CurrentUser(user) { this._currentUser = user; }
|
|
24
16
|
async GetRecordsByEntityID(entityID, recordIDs) {
|
|
25
|
-
const md = new
|
|
26
|
-
const entity = md.Entities.find(
|
|
17
|
+
const md = new core_1.Metadata();
|
|
18
|
+
const entity = md.Entities.find(e => e.ID === entityID);
|
|
27
19
|
if (!entity) {
|
|
28
20
|
throw new Error(`Entity with ID ${entityID} not found.`);
|
|
29
21
|
}
|
|
@@ -31,7 +23,7 @@ class VectorBase {
|
|
|
31
23
|
EntityName: entity.Name,
|
|
32
24
|
ExtraFilter: recordIDs ? this.BuildExtraFilter(recordIDs) : undefined,
|
|
33
25
|
ResultType: 'entity_object',
|
|
34
|
-
IgnoreMaxRows: true
|
|
26
|
+
IgnoreMaxRows: true
|
|
35
27
|
}, this.CurrentUser);
|
|
36
28
|
if (!rvResult.Success) {
|
|
37
29
|
throw new Error(rvResult.ErrorMessage);
|
|
@@ -48,7 +40,7 @@ class VectorBase {
|
|
|
48
40
|
ResultType: params.ResultType,
|
|
49
41
|
MaxRows: params.PageSize,
|
|
50
42
|
StartRow: Math.max(0, (params.PageNumber - 1) * params.PageSize),
|
|
51
|
-
ExtraFilter: params.Filter
|
|
43
|
+
ExtraFilter: params.Filter
|
|
52
44
|
}, this.CurrentUser);
|
|
53
45
|
if (!rvResult.Success) {
|
|
54
46
|
throw new Error(rvResult.ErrorMessage);
|
|
@@ -59,26 +51,26 @@ class VectorBase {
|
|
|
59
51
|
return CompositeKey.map((keyValue) => {
|
|
60
52
|
return keyValue.KeyValuePairs.map((keys) => {
|
|
61
53
|
return `${keys.FieldName} = '${keys.Value}'`;
|
|
62
|
-
}).join(
|
|
63
|
-
}).join(
|
|
54
|
+
}).join(" AND ");
|
|
55
|
+
}).join("\n OR ");
|
|
64
56
|
}
|
|
65
57
|
GetAIModel(id) {
|
|
66
58
|
let model;
|
|
67
59
|
if (id) {
|
|
68
|
-
model = aiengine_1.AIEngine.Instance.Models.find(
|
|
60
|
+
model = aiengine_1.AIEngine.Instance.Models.find(m => m.AIModelType === "Embeddings" && m.ID === id);
|
|
69
61
|
}
|
|
70
62
|
else {
|
|
71
|
-
model = aiengine_1.AIEngine.Instance.Models.find(
|
|
63
|
+
model = aiengine_1.AIEngine.Instance.Models.find(m => m.AIModelType === "Embeddings");
|
|
72
64
|
}
|
|
73
65
|
if (!model) {
|
|
74
|
-
throw new Error(
|
|
66
|
+
throw new Error("No AI Model Entity found");
|
|
75
67
|
}
|
|
76
68
|
return model;
|
|
77
69
|
}
|
|
78
70
|
GetVectorDatabase(id) {
|
|
79
71
|
if (aiengine_1.AIEngine.Instance.VectorDatabases.length > 0) {
|
|
80
72
|
if (id) {
|
|
81
|
-
let vectorDB = aiengine_1.AIEngine.Instance.VectorDatabases.find(
|
|
73
|
+
let vectorDB = aiengine_1.AIEngine.Instance.VectorDatabases.find(vd => vd.ID === id);
|
|
82
74
|
if (vectorDB) {
|
|
83
75
|
return vectorDB;
|
|
84
76
|
}
|
|
@@ -87,19 +79,19 @@ class VectorBase {
|
|
|
87
79
|
return aiengine_1.AIEngine.Instance.VectorDatabases[0];
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
|
-
throw new Error(
|
|
82
|
+
throw new Error("No Vector Database Entity found");
|
|
91
83
|
}
|
|
92
84
|
async RunViewForSingleValue(entityName, extraFilter) {
|
|
93
85
|
const rvResult = await this._runView.RunView({
|
|
94
86
|
EntityName: entityName,
|
|
95
87
|
ExtraFilter: extraFilter,
|
|
96
|
-
ResultType: 'entity_object'
|
|
88
|
+
ResultType: 'entity_object'
|
|
97
89
|
}, this.CurrentUser);
|
|
98
90
|
if (rvResult.Success) {
|
|
99
91
|
return rvResult.RowCount > 0 ? rvResult.Results[0] : null;
|
|
100
92
|
}
|
|
101
93
|
else {
|
|
102
|
-
(0,
|
|
94
|
+
(0, core_1.LogError)(rvResult.ErrorMessage);
|
|
103
95
|
return null;
|
|
104
96
|
}
|
|
105
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VectorBase.js","sourceRoot":"","sources":["../../src/models/VectorBase.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD
|
|
1
|
+
{"version":3,"file":"VectorBase.js","sourceRoot":"","sources":["../../src/models/VectorBase.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,+CAAkI;AAIlI,MAAa,UAAU;IAKnB;QACI,IAAI,CAAC,QAAQ,GAAG,IAAI,cAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,eAAQ,EAAE,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;IACnD,CAAC;IAED,IAAW,QAAQ,KAAe,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,IAAW,WAAW,KAAe,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChE,IAAW,WAAW,CAAC,IAAc,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;IAE1D,KAAK,CAAC,oBAAoB,CAAC,QAAgB,EAAE,SAA0B;QAC7E,MAAM,EAAE,GAAG,IAAI,eAAQ,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,EAAC,CAAC;YACT,MAAM,IAAI,KAA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": "2.113.0",
|
|
4
4
|
"description": "MemberJunction: AI Vectors Module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
"author": "MemberJunction.com",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@memberjunction/
|
|
19
|
-
"@memberjunction/
|
|
20
|
-
"@memberjunction/
|
|
21
|
-
"@memberjunction/
|
|
22
|
-
"@memberjunction/ai
|
|
18
|
+
"@memberjunction/core": "2.113.0",
|
|
19
|
+
"@memberjunction/global": "2.113.0",
|
|
20
|
+
"@memberjunction/core-entities": "2.113.0",
|
|
21
|
+
"@memberjunction/aiengine": "2.113.0",
|
|
22
|
+
"@memberjunction/ai": "2.113.0",
|
|
23
|
+
"@memberjunction/ai-vectordb": "2.113.0",
|
|
23
24
|
"dotenv": "^16.4.1",
|
|
24
25
|
"openai": "^4.28.4"
|
|
25
26
|
},
|