@rws-framework/ai-tools 3.2.6 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -36,8 +36,7 @@ export class InputOutputManager {
|
|
|
36
36
|
readInput(): CompoundInput[] {
|
|
37
37
|
const enchantedInput: CompoundInput[] = this.enhancedInput.map(enchantment => ({
|
|
38
38
|
role: enchantment.input.role || 'user',
|
|
39
|
-
|
|
40
|
-
text: enchantment.input.text
|
|
39
|
+
content: enchantment.input.content
|
|
41
40
|
}));
|
|
42
41
|
|
|
43
42
|
return [...enchantedInput, ...this.input];
|
|
@@ -87,7 +86,13 @@ export class InputOutputManager {
|
|
|
87
86
|
if (callback) {
|
|
88
87
|
callback(messages, prompt);
|
|
89
88
|
} else {
|
|
90
|
-
this.input = [{
|
|
89
|
+
this.input = [{
|
|
90
|
+
role: 'user',
|
|
91
|
+
content: {
|
|
92
|
+
type: 'text',
|
|
93
|
+
text: prompt
|
|
94
|
+
}
|
|
95
|
+
}, ...this.input];
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
|
|
@@ -141,13 +141,13 @@ export class LangChainRAGService {
|
|
|
141
141
|
*/
|
|
142
142
|
async searchKnowledge(request: IRAGSearchRequest): Promise<IRAGResponse<{ results: ISearchResult[] }>> {
|
|
143
143
|
this.log('log', `[SEARCH] Starting knowledge search for query: "${request.query}"`);
|
|
144
|
-
this.log('debug', `[SEARCH] Search parameters: maxResults=${request.maxResults || 5}, threshold=${request.threshold || 0.3}`);
|
|
144
|
+
this.log('debug', `[SEARCH] Search parameters: maxResults=${request.maxResults || 5}, threshold=${request.threshold || 0.3}, temporaryDocumentSearch=${request.temporaryDocumentSearch}`);
|
|
145
145
|
|
|
146
146
|
try {
|
|
147
147
|
await this.ensureInitialized();
|
|
148
148
|
|
|
149
149
|
const knowledgeIds = request.filter?.knowledgeIds || [];
|
|
150
|
-
console.log('knowledgeIds', knowledgeIds);
|
|
150
|
+
console.log('knowledgeIds', knowledgeIds, 'temporaryDocumentSearch:', request.temporaryDocumentSearch);
|
|
151
151
|
|
|
152
152
|
if (knowledgeIds.length === 0) {
|
|
153
153
|
this.log('warn', '[SEARCH] No knowledge IDs provided for search, returning empty results');
|
|
@@ -157,16 +157,29 @@ export class LangChainRAGService {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
// Load all knowledge vectors in parallel
|
|
160
|
+
// Load all knowledge vectors in parallel (including temporary documents)
|
|
161
161
|
const knowledgeVectorPromises = knowledgeIds.map(async (knowledgeId) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
try {
|
|
163
|
+
const vectorData = await this.loadKnowledgeVectorWithEmbeddings(knowledgeId);
|
|
164
|
+
return {
|
|
165
|
+
knowledgeId,
|
|
166
|
+
chunks: vectorData.chunks
|
|
167
|
+
};
|
|
168
|
+
} catch (loadError) {
|
|
169
|
+
this.log('warn', `[SEARCH] Failed to load knowledge ${knowledgeId}:`, loadError);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
167
172
|
});
|
|
168
173
|
|
|
169
|
-
const knowledgeVectors = await Promise.all(knowledgeVectorPromises);
|
|
174
|
+
const knowledgeVectors = (await Promise.all(knowledgeVectorPromises)).filter(v => v !== null);
|
|
175
|
+
|
|
176
|
+
if (knowledgeVectors.length === 0) {
|
|
177
|
+
this.log('warn', '[SEARCH] No knowledge vectors could be loaded for search');
|
|
178
|
+
return {
|
|
179
|
+
success: true,
|
|
180
|
+
data: { results: [] }
|
|
181
|
+
};
|
|
182
|
+
}
|
|
170
183
|
|
|
171
184
|
// Use optimized vector search service
|
|
172
185
|
const searchResponse = await this.vectorSearchService.searchSimilar({
|
|
@@ -205,25 +218,25 @@ export class LangChainRAGService {
|
|
|
205
218
|
/**
|
|
206
219
|
* Remove knowledge from index
|
|
207
220
|
*/
|
|
208
|
-
async removeKnowledge(
|
|
209
|
-
this.log('log', `[REMOVE] Starting removal of knowledge: ${
|
|
221
|
+
async removeKnowledge(fileId: string | number): Promise<boolean> {
|
|
222
|
+
this.log('log', `[REMOVE] Starting removal of knowledge: ${fileId}`);
|
|
210
223
|
|
|
211
224
|
try {
|
|
212
225
|
await this.ensureInitialized();
|
|
213
226
|
|
|
214
227
|
// Remove the individual knowledge vector file
|
|
215
|
-
const vectorFilePath = this.getKnowledgeVectorPath(
|
|
228
|
+
const vectorFilePath = this.getKnowledgeVectorPath(fileId);
|
|
216
229
|
if (fs.existsSync(vectorFilePath)) {
|
|
217
230
|
fs.unlinkSync(vectorFilePath);
|
|
218
|
-
this.log('log', `[REMOVE] Successfully removed vector file for knowledge ${
|
|
231
|
+
this.log('log', `[REMOVE] Successfully removed vector file for knowledge ${fileId}`);
|
|
219
232
|
return true;
|
|
220
233
|
} else {
|
|
221
|
-
this.log('warn', `[REMOVE] Vector file not found for knowledge ${
|
|
234
|
+
this.log('warn', `[REMOVE] Vector file not found for knowledge ${fileId}`);
|
|
222
235
|
return true; // Consider it successful if file doesn't exist
|
|
223
236
|
}
|
|
224
237
|
|
|
225
238
|
} catch (error: any) {
|
|
226
|
-
this.log('error', `[REMOVE] Failed to remove knowledge ${
|
|
239
|
+
this.log('error', `[REMOVE] Failed to remove knowledge ${fileId}:`, error);
|
|
227
240
|
return false;
|
|
228
241
|
}
|
|
229
242
|
}
|
package/src/types/rag.types.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface IRAGSearchRequest {
|
|
|
24
24
|
query: string;
|
|
25
25
|
maxResults?: number;
|
|
26
26
|
threshold?: number;
|
|
27
|
+
temporaryDocumentSearch?: boolean; // Flag for searching temporary documents (web search)
|
|
27
28
|
filter?: {
|
|
28
29
|
knowledgeIds?: (string | number)[];
|
|
29
30
|
documentIds?: (string | number)[];
|