@rws-framework/ai-tools 3.9.0 → 3.9.2
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/package.json
CHANGED
|
@@ -83,18 +83,21 @@ export class LangChainEmbeddingService {
|
|
|
83
83
|
// This method is kept for compatibility but doesn't initialize anything
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
async embedDocs(docs: Document[], batchCallback?: (fragments:string[], batch: number[][]) => Promise<void>): Promise<number[][]> {
|
|
86
|
+
async embedDocs(docs: Document[], batchCallback?: (fragments:string[], batch: number[][], percentage: number) => Promise<void>): Promise<number[][]> {
|
|
87
87
|
this.ensureInitialized();
|
|
88
88
|
|
|
89
89
|
if (this.config.rateLimiting) {
|
|
90
|
+
let doneFiles = 0;
|
|
90
91
|
return await this.rateLimitingService.executeWithRateLimit(
|
|
91
92
|
docs,
|
|
92
93
|
async (batch: Document[]) => {
|
|
93
94
|
const embeddings = await this.embeddings.embedDocuments(batch.map(d => d.pageContent));
|
|
94
95
|
|
|
95
96
|
if(batchCallback){
|
|
96
|
-
const fragments = batch.map(d => d.pageContent);
|
|
97
|
-
|
|
97
|
+
const fragments = batch.map(d => d.pageContent);
|
|
98
|
+
doneFiles += batch.length;
|
|
99
|
+
const percentage = (doneFiles / docs.length) * 100;
|
|
100
|
+
await batchCallback(fragments, embeddings, percentage);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
return embeddings;
|
|
@@ -106,16 +109,18 @@ export class LangChainEmbeddingService {
|
|
|
106
109
|
return await this.embeddings.embedDocuments(docs.map(d => d.pageContent));
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
async embedTexts(texts: string[], batchCallback?: (fragments:string[], batch: number[][]) => Promise<void>): Promise<number[][]> {
|
|
112
|
+
async embedTexts(texts: string[], batchCallback?: (fragments:string[], batch: number[][], percentage: number) => Promise<void>): Promise<number[][]> {
|
|
110
113
|
this.ensureInitialized();
|
|
111
|
-
|
|
114
|
+
let doneTexts = 0;
|
|
112
115
|
if (this.config.rateLimiting) {
|
|
113
116
|
return await this.rateLimitingService.executeWithRateLimit(
|
|
114
117
|
texts,
|
|
115
118
|
async (batch: string[]) => {
|
|
116
119
|
const embeddings = await this.embeddings.embedDocuments(batch);
|
|
117
120
|
if (batchCallback) {
|
|
118
|
-
|
|
121
|
+
doneTexts += batch.length;
|
|
122
|
+
const percentage = (doneTexts / texts.length) * 100;
|
|
123
|
+
await batchCallback(batch, embeddings, percentage);
|
|
119
124
|
}
|
|
120
125
|
return embeddings;
|
|
121
126
|
},
|
|
@@ -98,7 +98,7 @@ export class LangChainRAGService {
|
|
|
98
98
|
fileId: string | number,
|
|
99
99
|
content: string | Record<string, any>[],
|
|
100
100
|
metadata: Record<string, any> = {},
|
|
101
|
-
batchCallback?: (fragments:string[], batch: number[][]) => Promise<void>,
|
|
101
|
+
batchCallback?: (fragments:string[], batch: number[][], percentage: number) => Promise<void>,
|
|
102
102
|
ragOverride?: IChunkConfig
|
|
103
103
|
): Promise<IRAGResponse<{ chunkCount: number }>> {
|
|
104
104
|
this.log('log', `[INDEXING] Starting indexKnowledge for fileId: ${fileId}`);
|