@futdevpro/nts-dynamo 1.14.6 → 1.14.8
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/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.js +0 -1
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.js.map +1 -1
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.d.ts +19 -0
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.d.ts.map +1 -1
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.js +19 -0
- package/build/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-chunk-data.service.d.ts +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-chunk-data.service.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-chunk-data.service.js +30 -26
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-chunk-data.service.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-page.data-service.d.ts +1 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-page.data-service.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-page.data-service.js +63 -23
- package/build/_modules/ai/_modules/open-ai/_services/oai-doc-page.data-service.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-document.data-service.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-document.data-service.js +66 -45
- package/build/_modules/ai/_modules/open-ai/_services/oai-document.data-service.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.js +19 -17
- package/build/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.js.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js +1 -1
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js.map +1 -1
- package/package.json +1 -1
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +1 -1
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +20 -1
- package/src/_modules/ai/_modules/open-ai/_services/oai-doc-chunk-data.service.ts +35 -28
- package/src/_modules/ai/_modules/open-ai/_services/oai-doc-page.data-service.ts +77 -23
- package/src/_modules/ai/_modules/open-ai/_services/oai-document.data-service.ts +81 -45
- package/src/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.ts +8 -4
- package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +1 -1
|
@@ -20,7 +20,7 @@ export class DyNTS_OAI_DocChunkDataService<
|
|
|
20
20
|
T_Document extends DyNTS_DAI_Document<T_Chunk, T_Page, T_ExternalDocumentId> = DyNTS_DAI_Document<T_Chunk, T_Page, T_ExternalDocumentId>,
|
|
21
21
|
> extends DyNTS_OAI_VectorDataService<T_Chunk> {
|
|
22
22
|
|
|
23
|
-
override debugLog: boolean =
|
|
23
|
+
/* override debugLog: boolean = false; */
|
|
24
24
|
|
|
25
25
|
constructor(
|
|
26
26
|
issuer: string,
|
|
@@ -68,10 +68,21 @@ export class DyNTS_OAI_DocChunkDataService<
|
|
|
68
68
|
const oldChunk = oldChunks[i];
|
|
69
69
|
if (oldChunk) {
|
|
70
70
|
newChunk._id = oldChunk._id;
|
|
71
|
-
|
|
72
|
-
const chunkCompareResult: DyNTS_DAI_DocChunkCompareResult<T_Chunk> = await this.compareChunk(
|
|
73
|
-
|
|
71
|
+
// Compare first to determine if we need to save
|
|
72
|
+
const chunkCompareResult: DyNTS_DAI_DocChunkCompareResult<T_Chunk> = await this.compareChunk(newChunk, oldChunk);
|
|
73
|
+
|
|
74
|
+
if (chunkCompareResult.result === DyNTS_DAI_CompareResult_Type.equal) {
|
|
75
|
+
// No changes detected, reuse existing chunk without saving
|
|
76
|
+
chunkCompareResult.newChunk = oldChunk;
|
|
77
|
+
chunkCompareResults.push(chunkCompareResult);
|
|
78
|
+
} else {
|
|
79
|
+
// Changes detected, save the updated chunk
|
|
80
|
+
const savedChunk: T_Chunk = await this.saveData(newChunk, true);
|
|
81
|
+
chunkCompareResult.newChunk = savedChunk;
|
|
82
|
+
chunkCompareResults.push(chunkCompareResult);
|
|
83
|
+
}
|
|
74
84
|
} else {
|
|
85
|
+
// New chunk, save it
|
|
75
86
|
const savedChunk: T_Chunk = await this.saveData(newChunk, true);
|
|
76
87
|
chunkCompareResults.push({
|
|
77
88
|
result: DyNTS_DAI_CompareResult_Type.new,
|
|
@@ -146,31 +157,20 @@ export class DyNTS_OAI_DocChunkDataService<
|
|
|
146
157
|
DyFM_Log.info(`🔍 Comparing ${this.dataParams.dataName} chunk: ${newChunk.chunkIndex}`);
|
|
147
158
|
}
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
/* if (!oldChunk) {
|
|
163
|
-
// itt kéne vektor search-el utána keresni,
|
|
164
|
-
// hogy a page link-je megtalálható-e (avagy csak átnevezésre került-e)
|
|
165
|
-
// hogy az adott tartalom, nem-e csak átnevezésre, szétbontásra vagy összevonásra került-e
|
|
166
|
-
return {
|
|
167
|
-
result: DyNTS_DAI_CompareResult_Type.new,
|
|
168
|
-
newChunk: newChunk,
|
|
169
|
-
oldChunk: null,
|
|
170
|
-
};
|
|
171
|
-
} */
|
|
160
|
+
// Compare all relevant fields for comprehensive change detection
|
|
161
|
+
const contentEqual = oldChunk.chunkContent === newChunk.chunkContent;
|
|
162
|
+
const pathEqual = oldChunk.path === newChunk.path;
|
|
163
|
+
const documentNameEqual = oldChunk.documentName === newChunk.documentName;
|
|
164
|
+
const pageNameEqual = oldChunk.pageName === newChunk.pageName;
|
|
165
|
+
const pageLinkEqual = oldChunk.pageLink === newChunk.pageLink;
|
|
166
|
+
|
|
167
|
+
// Compare allFlaggedParents arrays
|
|
168
|
+
const allFlaggedParentsEqual = this.compareStringArrays(
|
|
169
|
+
oldChunk.allFlaggedParents || [],
|
|
170
|
+
newChunk.allFlaggedParents || []
|
|
171
|
+
);
|
|
172
172
|
|
|
173
|
-
if (
|
|
173
|
+
if (contentEqual && pathEqual && documentNameEqual && pageNameEqual && pageLinkEqual && allFlaggedParentsEqual) {
|
|
174
174
|
return {
|
|
175
175
|
result: DyNTS_DAI_CompareResult_Type.equal,
|
|
176
176
|
newChunk: newChunk,
|
|
@@ -190,6 +190,13 @@ export class DyNTS_OAI_DocChunkDataService<
|
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
+
|
|
194
|
+
private compareStringArrays(arr1: string[], arr2: string[]): boolean {
|
|
195
|
+
if (arr1.length !== arr2.length) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return arr1.every((item, index) => item === arr2[index]);
|
|
199
|
+
}
|
|
193
200
|
|
|
194
201
|
async chunkPage(page: T_Page): Promise<T_Chunk[]> {
|
|
195
202
|
try {
|
|
@@ -106,12 +106,6 @@ export class DyNTS_OAI_DocPageDataService<
|
|
|
106
106
|
|
|
107
107
|
async processPage(page: T_Page): Promise<DyNTS_DAI_DocPageCompareResult<T_Chunk, T_Page>> {
|
|
108
108
|
try {
|
|
109
|
-
// ugyan a logikus az lenne, ha először compare-elnénk, és csak az után mentenénk,
|
|
110
|
-
// de akkor nem lenne id, amit a sub-element-ekhez kellenek, ezért...
|
|
111
|
-
// - először kikérjük a régi adatot,
|
|
112
|
-
// - aztán mentünk, hogy legyen id,
|
|
113
|
-
// - és utána compare-eljük
|
|
114
|
-
|
|
115
109
|
let existingPage: T_Page;
|
|
116
110
|
if (page._id) {
|
|
117
111
|
existingPage = await this.findData({
|
|
@@ -131,30 +125,47 @@ export class DyNTS_OAI_DocPageDataService<
|
|
|
131
125
|
} as DyFM_DBFilterSimple<T_Page>);
|
|
132
126
|
}
|
|
133
127
|
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
let pageCompareResult: DyNTS_DAI_DocPageCompareResult<T_Chunk, T_Page>;
|
|
129
|
+
|
|
136
130
|
if (existingPage) {
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
// Compare first to determine if we need to save
|
|
132
|
+
pageCompareResult = await this.comparePage(page, existingPage);
|
|
133
|
+
|
|
134
|
+
if (pageCompareResult.result === DyNTS_DAI_CompareResult_Type.equal) {
|
|
135
|
+
// No changes detected, reuse existing page without saving
|
|
136
|
+
pageCompareResult.newPage = existingPage;
|
|
137
|
+
pageCompareResult.oldPage = existingPage;
|
|
138
|
+
} else {
|
|
139
|
+
// Changes detected, save the updated page
|
|
140
|
+
let pageDataToSave: T_Page;
|
|
141
|
+
pageDataToSave = existingPage;
|
|
142
|
+
Object.assign(pageDataToSave, page);
|
|
143
|
+
delete pageDataToSave.chunks;
|
|
144
|
+
|
|
145
|
+
const savedPage: T_Page = await this.saveData(pageDataToSave, true);
|
|
146
|
+
|
|
147
|
+
page.chunks.forEach((chunk: T_Chunk) => {
|
|
148
|
+
chunk.documentId = savedPage.documentId;
|
|
149
|
+
chunk.pageId = savedPage._id;
|
|
150
|
+
});
|
|
151
|
+
page._id = savedPage._id;
|
|
152
|
+
pageCompareResult.newPage = page;
|
|
153
|
+
}
|
|
139
154
|
} else {
|
|
140
|
-
|
|
155
|
+
// New page, save it first to get ID
|
|
156
|
+
const pageDataToSave: T_Page = {
|
|
141
157
|
...page,
|
|
142
158
|
};
|
|
143
|
-
|
|
144
|
-
delete pageDataToSave.chunks;
|
|
159
|
+
delete pageDataToSave.chunks;
|
|
145
160
|
|
|
146
|
-
|
|
161
|
+
const savedPage: T_Page = await this.saveData(pageDataToSave, true);
|
|
147
162
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
163
|
+
page.chunks.forEach((chunk: T_Chunk) => {
|
|
164
|
+
chunk.documentId = savedPage.documentId;
|
|
165
|
+
chunk.pageId = savedPage._id;
|
|
166
|
+
});
|
|
167
|
+
page._id = savedPage._id;
|
|
153
168
|
|
|
154
|
-
let pageCompareResult: DyNTS_DAI_DocPageCompareResult<T_Chunk, T_Page>;
|
|
155
|
-
if (existingPage) {
|
|
156
|
-
pageCompareResult = await this.comparePage(page, existingPage);
|
|
157
|
-
} else {
|
|
158
169
|
pageCompareResult = {
|
|
159
170
|
result: DyNTS_DAI_CompareResult_Type.new,
|
|
160
171
|
newPage: page,
|
|
@@ -263,6 +274,7 @@ export class DyNTS_OAI_DocPageDataService<
|
|
|
263
274
|
const messages: string[] = [];
|
|
264
275
|
const chunkCompareResults: DyNTS_DAI_DocChunkCompareResult<T_Chunk>[] = [];
|
|
265
276
|
|
|
277
|
+
// Compare all relevant fields for comprehensive change detection
|
|
266
278
|
if (newPage.name !== oldPage.name) {
|
|
267
279
|
pageCompareResult = DyNTS_DAI_CompareResult_Type.modified;
|
|
268
280
|
messages.push(`Page name modified`);
|
|
@@ -271,7 +283,42 @@ export class DyNTS_OAI_DocPageDataService<
|
|
|
271
283
|
if (newPage.content !== oldPage.content) {
|
|
272
284
|
pageCompareResult = DyNTS_DAI_CompareResult_Type.modified;
|
|
273
285
|
messages.push(`Page content modified`);
|
|
286
|
+
}
|
|
274
287
|
|
|
288
|
+
// Compare allFlaggedParents arrays
|
|
289
|
+
const allFlaggedParentsEqual = this.compareStringArrays(
|
|
290
|
+
newPage.allFlaggedParents || [],
|
|
291
|
+
oldPage.allFlaggedParents || []
|
|
292
|
+
);
|
|
293
|
+
if (!allFlaggedParentsEqual) {
|
|
294
|
+
pageCompareResult = DyNTS_DAI_CompareResult_Type.modified;
|
|
295
|
+
messages.push(`Page allFlaggedParents modified`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Compare allFlaggedParentsMerged
|
|
299
|
+
if (newPage.allFlaggedParentsMerged !== oldPage.allFlaggedParentsMerged) {
|
|
300
|
+
pageCompareResult = DyNTS_DAI_CompareResult_Type.modified;
|
|
301
|
+
messages.push(`Page allFlaggedParentsMerged modified`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Compare filePath
|
|
305
|
+
if (newPage.filePath !== oldPage.filePath) {
|
|
306
|
+
pageCompareResult = DyNTS_DAI_CompareResult_Type.modified;
|
|
307
|
+
messages.push(`Page filePath modified`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Compare parentedPath arrays
|
|
311
|
+
const parentedPathEqual = this.compareStringArrays(
|
|
312
|
+
newPage.parentedPath || [],
|
|
313
|
+
oldPage.parentedPath || []
|
|
314
|
+
);
|
|
315
|
+
if (!parentedPathEqual) {
|
|
316
|
+
pageCompareResult = DyNTS_DAI_CompareResult_Type.modified;
|
|
317
|
+
messages.push(`Page parentedPath modified`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Only process chunks if page content actually changed
|
|
321
|
+
if (pageCompareResult === DyNTS_DAI_CompareResult_Type.modified) {
|
|
275
322
|
const docChunk_DS: DyNTS_OAI_DocChunkDataService<T_Chunk, T_Page, T_ExternalDocumentId, T_Document> =
|
|
276
323
|
this.getDocChunkDataService();
|
|
277
324
|
|
|
@@ -300,6 +347,13 @@ export class DyNTS_OAI_DocPageDataService<
|
|
|
300
347
|
}
|
|
301
348
|
}
|
|
302
349
|
|
|
350
|
+
private compareStringArrays(arr1: string[], arr2: string[]): boolean {
|
|
351
|
+
if (arr1.length !== arr2.length) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
return arr1.every((item, index) => item === arr2[index]);
|
|
355
|
+
}
|
|
356
|
+
|
|
303
357
|
/* async comparePage_deep(page: T_Page, oldPage: T_Page): Promise<DyNTS_DAI_DocPageCompareResult<T_Chunk, T_Page>> {
|
|
304
358
|
try {
|
|
305
359
|
if (this.debugLog) {
|
|
@@ -53,6 +53,10 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
53
53
|
DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document>[]
|
|
54
54
|
> {
|
|
55
55
|
try {
|
|
56
|
+
if (!documents || documents.length === 0) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
const compareResults: DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document>[] = [];
|
|
57
61
|
|
|
58
62
|
await DyFM_Array.asyncForEachAllAtOnce(
|
|
@@ -96,7 +100,7 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
96
100
|
messages.unshift(`${pagesToDelete.length} pages deleted`);
|
|
97
101
|
|
|
98
102
|
await this.deleteData(deletedDocument._id, this.absoluteDeletesOnProcess);
|
|
99
|
-
messages.unshift(`Document "${deletedDocument
|
|
103
|
+
messages.unshift(`Document "${deletedDocument?.name}" deleted`);
|
|
100
104
|
|
|
101
105
|
compareResults.push({
|
|
102
106
|
result: DyNTS_DAI_CompareResult_Type.deleted,
|
|
@@ -124,13 +128,6 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
124
128
|
DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document>
|
|
125
129
|
> {
|
|
126
130
|
try {
|
|
127
|
-
// ugyan a logikus az lenne, ha először compare-elnénk, és csak az után mentenénk,
|
|
128
|
-
// de akkor nem lenne id, amit a sub-element-ekhez kellenek, ezért...
|
|
129
|
-
// - először kikérjük a régi adatot,
|
|
130
|
-
// - aztán mentünk, hogy legyen id,
|
|
131
|
-
// - és utána compare-eljük
|
|
132
|
-
|
|
133
|
-
|
|
134
131
|
let existingDocument: T_Document;
|
|
135
132
|
|
|
136
133
|
if (document._id) {
|
|
@@ -150,30 +147,47 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
150
147
|
});
|
|
151
148
|
}
|
|
152
149
|
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
let documentCompareResult: DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document>;
|
|
151
|
+
|
|
155
152
|
if (existingDocument) {
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
// Compare first to determine if we need to save
|
|
154
|
+
documentCompareResult = await this.compareDocument_deep(document, existingDocument);
|
|
155
|
+
|
|
156
|
+
if (documentCompareResult.result === DyNTS_DAI_CompareResult_Type.equal) {
|
|
157
|
+
// No changes detected, reuse existing document without saving
|
|
158
|
+
documentCompareResult.newDocument = existingDocument;
|
|
159
|
+
documentCompareResult.oldDocument = existingDocument;
|
|
160
|
+
} else {
|
|
161
|
+
// Changes detected, save the updated document
|
|
162
|
+
let docDataToSave: T_Document;
|
|
163
|
+
docDataToSave = existingDocument;
|
|
164
|
+
Object.assign(docDataToSave, document);
|
|
165
|
+
delete docDataToSave.pages;
|
|
166
|
+
|
|
167
|
+
const savedDocument: T_Document = await this.saveData(docDataToSave, true);
|
|
168
|
+
|
|
169
|
+
// set the id to the pages and the document
|
|
170
|
+
document.pages.forEach((page: T_Page) => {
|
|
171
|
+
page.documentId = savedDocument._id;
|
|
172
|
+
});
|
|
173
|
+
document._id = savedDocument._id;
|
|
174
|
+
documentCompareResult.newDocument = document;
|
|
175
|
+
}
|
|
158
176
|
} else {
|
|
159
|
-
|
|
177
|
+
// New document, save it first to get ID
|
|
178
|
+
const docDataToSave: T_Document = {
|
|
160
179
|
...document,
|
|
161
180
|
};
|
|
162
|
-
|
|
163
|
-
delete docDataToSave.pages;
|
|
181
|
+
delete docDataToSave.pages;
|
|
164
182
|
|
|
165
|
-
|
|
183
|
+
const savedDocument: T_Document = await this.saveData(docDataToSave, true);
|
|
166
184
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
185
|
+
// set the id to the pages and the document
|
|
186
|
+
document.pages.forEach((page: T_Page) => {
|
|
187
|
+
page.documentId = savedDocument._id;
|
|
188
|
+
});
|
|
189
|
+
document._id = savedDocument._id;
|
|
172
190
|
|
|
173
|
-
let documentCompareResult: DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document>;
|
|
174
|
-
if (existingDocument) {
|
|
175
|
-
documentCompareResult = await this.compareDocument_deep(document, existingDocument);
|
|
176
|
-
} else {
|
|
177
191
|
const docPage_DS: DyNTS_OAI_DocPageDataService<T_Chunk, T_Page, T_ExternalDocumentId, T_Document> =
|
|
178
192
|
this.getDocPageDataService();
|
|
179
193
|
|
|
@@ -187,8 +201,8 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
187
201
|
oldDocument: null,
|
|
188
202
|
pageCompareResults: pagesCompareResults,
|
|
189
203
|
reports: [
|
|
190
|
-
`New document: ${document
|
|
191
|
-
`${document
|
|
204
|
+
`New document: "${document?.name}"`,
|
|
205
|
+
`${document?.pages?.length ?? 0} new pages in "${document?.name}"`,
|
|
192
206
|
],
|
|
193
207
|
};
|
|
194
208
|
}
|
|
@@ -206,7 +220,7 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
206
220
|
> {
|
|
207
221
|
try {
|
|
208
222
|
if (this.debugLog) {
|
|
209
|
-
DyFM_Log.info(`🔍 Comparing ${this.dataParams.dataName} document: ${newDocument
|
|
223
|
+
DyFM_Log.info(`🔍 Comparing "${this.dataParams.dataName}" document: "${newDocument?.name}"`);
|
|
210
224
|
}
|
|
211
225
|
|
|
212
226
|
if (!oldDocument) {
|
|
@@ -253,13 +267,13 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
253
267
|
).length;
|
|
254
268
|
|
|
255
269
|
if (modifiedPagesCount > 0) {
|
|
256
|
-
messages.push(`${modifiedPagesCount} pages
|
|
270
|
+
messages.push(`${modifiedPagesCount} modified pages`);
|
|
257
271
|
}
|
|
258
272
|
if (newPagesCount > 0) {
|
|
259
|
-
messages.push(`${newPagesCount} pages
|
|
273
|
+
messages.push(`${newPagesCount} new pages`);
|
|
260
274
|
}
|
|
261
275
|
if (deletedPagesCount > 0) {
|
|
262
|
-
messages.push(`${deletedPagesCount} pages
|
|
276
|
+
messages.push(`${deletedPagesCount} deleted pages`);
|
|
263
277
|
}
|
|
264
278
|
} else {
|
|
265
279
|
pagesResult = DyNTS_DAI_CompareResult_Type.new;
|
|
@@ -312,18 +326,34 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
312
326
|
});
|
|
313
327
|
}
|
|
314
328
|
|
|
315
|
-
let result: DyNTS_DAI_CompareResult_Type;
|
|
329
|
+
let result: DyNTS_DAI_CompareResult_Type = DyNTS_DAI_CompareResult_Type.equal;
|
|
316
330
|
const messages: string[] = [];
|
|
317
331
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
messages.push(`New document: ${newDocument.name}`);
|
|
321
|
-
} else if (newDocument.name !== oldDocument?.name) {
|
|
332
|
+
// Compare document name
|
|
333
|
+
if (newDocument.name !== oldDocument.name) {
|
|
322
334
|
result = DyNTS_DAI_CompareResult_Type.modified;
|
|
323
|
-
messages.push(`Document name changed from "${oldDocument
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
335
|
+
messages.push(`Document name changed from "${oldDocument.name}" to "${newDocument.name}"`);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Compare externalDocumentId
|
|
339
|
+
if (newDocument.externalDocumentId !== oldDocument.externalDocumentId) {
|
|
340
|
+
result = DyNTS_DAI_CompareResult_Type.modified;
|
|
341
|
+
messages.push(`Document externalDocumentId changed`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Compare externalMetadata if present
|
|
345
|
+
if (newDocument.externalMetadata || oldDocument.externalMetadata) {
|
|
346
|
+
const newMetadataStr = newDocument.externalMetadata ? JSON.stringify(newDocument.externalMetadata) : '';
|
|
347
|
+
const oldMetadataStr = oldDocument.externalMetadata ? JSON.stringify(oldDocument.externalMetadata) : '';
|
|
348
|
+
|
|
349
|
+
if (newMetadataStr !== oldMetadataStr) {
|
|
350
|
+
result = DyNTS_DAI_CompareResult_Type.modified;
|
|
351
|
+
messages.push(`Document externalMetadata changed`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (result === DyNTS_DAI_CompareResult_Type.equal) {
|
|
356
|
+
messages.push(`Document name or not changed: "${newDocument.name}"`);
|
|
327
357
|
}
|
|
328
358
|
|
|
329
359
|
const result_flat: DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document> = {
|
|
@@ -348,29 +378,35 @@ export class DyNTS_OAI_DocumentDataService<
|
|
|
348
378
|
documentCompareResult: DyNTS_DAI_DocumentCompareResult<T_Chunk, T_Page, T_ExternalDocumentId, T_ExternalMetadata, T_Document>,
|
|
349
379
|
): Promise<void> {
|
|
350
380
|
try {
|
|
351
|
-
DyFM_Log.log(
|
|
381
|
+
DyFM_Log.log(
|
|
382
|
+
`\n✅ Document processed: "${
|
|
383
|
+
documentCompareResult?.newDocument?.name ?? documentCompareResult?.oldDocument?.name ?? 'unknown'
|
|
384
|
+
}"`
|
|
385
|
+
);
|
|
352
386
|
|
|
353
387
|
switch (documentCompareResult.result) {
|
|
354
388
|
case DyNTS_DAI_CompareResult_Type.new:
|
|
355
|
-
DyFM_Log.info(`
|
|
389
|
+
DyFM_Log.info(` ✨ New document`);
|
|
356
390
|
break;
|
|
357
391
|
|
|
358
392
|
case DyNTS_DAI_CompareResult_Type.equal:
|
|
359
|
-
DyFM_Log.
|
|
393
|
+
DyFM_Log.success(` 🟰 Equal document`);
|
|
360
394
|
break;
|
|
361
395
|
|
|
362
396
|
case DyNTS_DAI_CompareResult_Type.modified:
|
|
363
|
-
DyFM_Log.info(`
|
|
397
|
+
DyFM_Log.info(` 🔄 Modified document`);
|
|
364
398
|
break;
|
|
365
399
|
|
|
366
400
|
case DyNTS_DAI_CompareResult_Type.deleted:
|
|
367
|
-
DyFM_Log.warn(`
|
|
401
|
+
DyFM_Log.warn(` ❌ Deleted document`);
|
|
368
402
|
break;
|
|
369
403
|
}
|
|
370
404
|
|
|
371
405
|
for (const report of documentCompareResult.reports) {
|
|
372
406
|
DyFM_Log.log(` - ${report}`);
|
|
373
407
|
}
|
|
408
|
+
|
|
409
|
+
DyFM_Log.log('');
|
|
374
410
|
} catch (error) {
|
|
375
411
|
throw new DyFM_Error({
|
|
376
412
|
...this.getDefaultErrorSettings('reportDocumentProcessing', error),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
1
2
|
|
|
2
3
|
import {
|
|
3
4
|
DyFM_Array,
|
|
@@ -62,7 +63,7 @@ export class DyNTS_OAI_VectorDataService<T extends DyFM_Metadata> extends DyNTS_
|
|
|
62
63
|
readonly vectorizedProperties: DyFM_DataProperty_Params<any, T>[];
|
|
63
64
|
/* readonly vectorizeProperties: { from: string, to: string }[]; */
|
|
64
65
|
|
|
65
|
-
debugLog: boolean =
|
|
66
|
+
debugLog: boolean = false;
|
|
66
67
|
swallowVectorizedProperties: boolean = true;
|
|
67
68
|
|
|
68
69
|
embedding_CS: DyNTS_OAI_Embedding_ControlService;
|
|
@@ -244,7 +245,10 @@ export class DyNTS_OAI_VectorDataService<T extends DyFM_Metadata> extends DyNTS_
|
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
if (this.debugLog) {
|
|
247
|
-
|
|
248
|
+
DyFM_Log.log(
|
|
249
|
+
`vectorizing "${vectorizedProperty.key}" in new "${this.dataParams.dataName}"` +
|
|
250
|
+
(newData as any)?.name ? `: "${(newData as any)?.name}"` : ''
|
|
251
|
+
);
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
newData[vectorizedProperty.key] = await this.vectorize(
|
|
@@ -412,13 +416,13 @@ export class DyNTS_OAI_VectorDataService<T extends DyFM_Metadata> extends DyNTS_
|
|
|
412
416
|
}
|
|
413
417
|
|
|
414
418
|
if (this.debugLog) {
|
|
415
|
-
|
|
419
|
+
DyFM_Log.log(`vectorSearch...`);
|
|
416
420
|
}
|
|
417
421
|
|
|
418
422
|
const result = await this.dataDBService.aggregate([ vectorSearchFilter ]);
|
|
419
423
|
|
|
420
424
|
if (this.debugLog) {
|
|
421
|
-
|
|
425
|
+
DyFM_Log.log(`vectorSearch: ${result.length} results`);
|
|
422
426
|
}
|
|
423
427
|
|
|
424
428
|
return result;
|
|
@@ -69,7 +69,7 @@ export abstract class DyNTS_DiBo_IO_ControlService extends DyNTS_SingletonServic
|
|
|
69
69
|
async handleNewMessage(message: Message, issuer: string): Promise<void> {
|
|
70
70
|
try {
|
|
71
71
|
if (DyNTS_DiBo_global_settings.debugLevel >= 1) {
|
|
72
|
-
DyFM_Log.H_log(`incoming message
|
|
72
|
+
DyFM_Log.H_log(`incoming message (${message.author.displayName}):\n${message.content}`)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const isForYou = await this.getMessageIsForBotToHandle(message, issuer);
|