@rws-framework/ai-tools 3.2.0 → 3.2.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/ai-tools",
3
3
  "private": false,
4
- "version": "3.2.0",
4
+ "version": "3.2.2",
5
5
  "description": "",
6
6
  "main": "src/index.ts",
7
7
  "scripts": {},
@@ -16,7 +16,8 @@
16
16
  "@rws-framework/console": "*",
17
17
  "uuid": "^9.0.0",
18
18
  "xml2js": "^0.6.2",
19
- "zod": "^3.25.76"
19
+ "zod": "^3.25.76",
20
+ "tiktoken": "^1.0.22"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/xml2js": "^0.4.14"
@@ -161,7 +161,7 @@ export class LangChainRAGService {
161
161
  const knowledgeVectorPromises = knowledgeIds.map(async (knowledgeId) => {
162
162
  const vectorData = await this.loadKnowledgeVectorWithEmbeddings(knowledgeId);
163
163
  return {
164
- knowledgeId,
164
+ knowledgeId,
165
165
  chunks: vectorData.chunks
166
166
  };
167
167
  });
@@ -178,13 +178,14 @@ export class LangChainRAGService {
178
178
 
179
179
  // Convert results to expected format
180
180
  const results: ISearchResult[] = searchResponse.results.map(result => ({
181
+ knowledgeId: result.metadata.knowledgeId,
181
182
  content: result.content,
182
183
  score: result.score,
183
184
  metadata: result.metadata,
184
- chunkId: result.chunkId
185
+ chunkId: result.chunkId,
185
186
  }));
186
187
 
187
- this.log('log', `[SEARCH] Found ${results.length} relevant chunks for query: "${request.query}"`);
188
+ this.log('log', `[SEARCH] Found ${results.length} relevant chunks for query: "${request.query}"\n ${JSON.stringify({ results})}`);
188
189
 
189
190
  return {
190
191
  success: true,
@@ -334,7 +335,7 @@ export class LangChainRAGService {
334
335
  /**
335
336
  * Load vector data for a specific knowledge item with embeddings
336
337
  */
337
- private async loadKnowledgeVectorWithEmbeddings(knowledgeId: string | number): Promise<{ chunks: Array<{ content: string; embedding: number[]; metadata: any }> }> {
338
+ private async loadKnowledgeVectorWithEmbeddings(knowledgeId: string | number): Promise<{ knowledgeId?: string | number, chunks: Array<{ content: string; embedding: number[]; metadata: any }> }> {
338
339
  const vectorFilePath = this.getKnowledgeVectorPath(knowledgeId);
339
340
 
340
341
  if (!fs.existsSync(vectorFilePath)) {
@@ -347,7 +348,8 @@ export class LangChainRAGService {
347
348
  const vectorData = JSON.parse(fs.readFileSync(vectorFilePath, 'utf8'));
348
349
 
349
350
  return {
350
- chunks: vectorData.chunks || []
351
+ chunks: vectorData.chunks || [],
352
+ knowledgeId
351
353
  };
352
354
  } catch (error) {
353
355
  this.log('error', `[LOAD] Failed to load vector data for knowledge ${knowledgeId}:`, error);
@@ -292,7 +292,8 @@ export class OptimizedVectorSearchService {
292
292
  content: result.content,
293
293
  score: result.score,
294
294
  metadata: result.metadata,
295
- chunkId: result.chunkId
295
+ chunkId: result.chunkId,
296
+ knowledgeId: result.knowledgeId
296
297
  }));
297
298
 
298
299
  return {
@@ -5,6 +5,7 @@ export interface ISearchResult {
5
5
  content: string;
6
6
  score: number;
7
7
  metadata: any;
8
+ knowledgeId: string | number;
8
9
  chunkId: string;
9
10
  }
10
11
 
@@ -12,8 +13,7 @@ export interface IVectorSearchRequest {
12
13
  query: string;
13
14
  maxResults?: number;
14
15
  similarityThreshold?: number;
15
- filter?: {
16
- knowledgeIds?: string[];
16
+ filter?: {
17
17
  documentIds?: string[];
18
18
  [key: string]: any;
19
19
  };