@toolpack-sdk/knowledge 1.4.0 → 2.0.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 +110 -1
- package/dist/index.cjs +31 -10
- package/dist/index.d.cts +135 -1
- package/dist/index.d.ts +135 -1
- package/dist/index.js +31 -10
- package/package.json +6 -1
package/dist/index.d.cts
CHANGED
|
@@ -120,6 +120,14 @@ declare class Knowledge {
|
|
|
120
120
|
private getAllChunks;
|
|
121
121
|
sync(): Promise<void>;
|
|
122
122
|
private embedChunks;
|
|
123
|
+
/**
|
|
124
|
+
* Add a single content item to the knowledge base without triggering a full re-sync.
|
|
125
|
+
* This is useful for runtime additions like conversation history or agent state.
|
|
126
|
+
* @param content The text content to add
|
|
127
|
+
* @param metadata Optional metadata to attach to the chunk
|
|
128
|
+
* @returns The ID of the added chunk
|
|
129
|
+
*/
|
|
130
|
+
add(content: string, metadata?: Record<string, unknown>): Promise<string>;
|
|
123
131
|
stop(): Promise<void>;
|
|
124
132
|
toTool(): KnowledgeTool;
|
|
125
133
|
}
|
|
@@ -276,6 +284,78 @@ declare class ApiDataSource implements KnowledgeSource {
|
|
|
276
284
|
private generateChunkId;
|
|
277
285
|
}
|
|
278
286
|
|
|
287
|
+
interface JSONSourceOptions {
|
|
288
|
+
namespace?: string;
|
|
289
|
+
metadata?: Record<string, unknown>;
|
|
290
|
+
filter?: (item: unknown) => boolean;
|
|
291
|
+
chunkSize?: number;
|
|
292
|
+
/** Required. Transform each JSON item into a human-readable string for AI embedding. */
|
|
293
|
+
toContent: (item: unknown) => string;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Knowledge source for JSON files.
|
|
297
|
+
* Supports jq-like filtering and chunking of large arrays.
|
|
298
|
+
*/
|
|
299
|
+
declare class JSONSource implements KnowledgeSource {
|
|
300
|
+
private filePath;
|
|
301
|
+
private options;
|
|
302
|
+
constructor(filePath: string, options: JSONSourceOptions);
|
|
303
|
+
load(): AsyncIterable<Chunk>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
interface SQLiteSourceOptions {
|
|
307
|
+
namespace?: string;
|
|
308
|
+
metadata?: Record<string, unknown>;
|
|
309
|
+
query?: string;
|
|
310
|
+
chunkSize?: number;
|
|
311
|
+
/** Required. Transform each database row into a human-readable string for AI embedding. */
|
|
312
|
+
toContent: (row: Record<string, unknown>) => string;
|
|
313
|
+
preLoadCSV?: {
|
|
314
|
+
tableName: string;
|
|
315
|
+
csvPath: string;
|
|
316
|
+
delimiter?: string;
|
|
317
|
+
headers?: boolean;
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Knowledge source for SQLite databases.
|
|
322
|
+
* Supports SQL queries and optional CSV/TSV pre-loading.
|
|
323
|
+
* Note: This requires the 'better-sqlite3' package to be installed.
|
|
324
|
+
*/
|
|
325
|
+
declare class SQLiteSource implements KnowledgeSource {
|
|
326
|
+
private dbPath;
|
|
327
|
+
private options;
|
|
328
|
+
constructor(dbPath: string, options: SQLiteSourceOptions);
|
|
329
|
+
load(): AsyncIterable<Chunk>;
|
|
330
|
+
private loadCSV;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
interface PostgresSourceOptions {
|
|
334
|
+
namespace?: string;
|
|
335
|
+
metadata?: Record<string, unknown>;
|
|
336
|
+
query: string;
|
|
337
|
+
chunkSize?: number;
|
|
338
|
+
/** Required. Transform each database row into a human-readable string for AI embedding. */
|
|
339
|
+
toContent: (row: Record<string, unknown>) => string;
|
|
340
|
+
connectionString?: string;
|
|
341
|
+
host?: string;
|
|
342
|
+
port?: number;
|
|
343
|
+
database?: string;
|
|
344
|
+
user?: string;
|
|
345
|
+
password?: string;
|
|
346
|
+
ssl?: boolean;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Knowledge source for PostgreSQL databases.
|
|
350
|
+
* Supports SQL queries with optional chunking.
|
|
351
|
+
* Note: This requires the 'pg' package to be installed.
|
|
352
|
+
*/
|
|
353
|
+
declare class PostgresSource implements KnowledgeSource {
|
|
354
|
+
private options;
|
|
355
|
+
constructor(options: PostgresSourceOptions);
|
|
356
|
+
load(): AsyncIterable<Chunk>;
|
|
357
|
+
}
|
|
358
|
+
|
|
279
359
|
interface OllamaEmbedderOptions {
|
|
280
360
|
model: string;
|
|
281
361
|
baseUrl?: string;
|
|
@@ -311,7 +391,61 @@ declare class OpenAIEmbedder implements Embedder {
|
|
|
311
391
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
312
392
|
}
|
|
313
393
|
|
|
394
|
+
interface OpenRouterEmbedderOptions {
|
|
395
|
+
model: string;
|
|
396
|
+
apiKey: string;
|
|
397
|
+
/** Override output dimensions for models not in the built-in map */
|
|
398
|
+
dimensions?: number;
|
|
399
|
+
retries?: number;
|
|
400
|
+
retryDelay?: number;
|
|
401
|
+
timeout?: number;
|
|
402
|
+
}
|
|
403
|
+
declare class OpenRouterEmbedder implements Embedder {
|
|
404
|
+
private options;
|
|
405
|
+
readonly dimensions: number;
|
|
406
|
+
private client;
|
|
407
|
+
constructor(options: OpenRouterEmbedderOptions);
|
|
408
|
+
private getModelDimensions;
|
|
409
|
+
embed(text: string): Promise<number[]>;
|
|
410
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface VertexAIEmbedderOptions {
|
|
414
|
+
/** GCP project ID. Falls back to VERTEX_AI_PROJECT / GOOGLE_CLOUD_PROJECT env vars. */
|
|
415
|
+
projectId?: string;
|
|
416
|
+
/** GCP region. Defaults to 'us-central1'. */
|
|
417
|
+
location?: string;
|
|
418
|
+
/**
|
|
419
|
+
* Embedding model. Defaults to 'gemini-embedding-2' (3072 dims).
|
|
420
|
+
* Other options: 'gemini-embedding-001' (3072), 'text-embedding-005' (768).
|
|
421
|
+
*/
|
|
422
|
+
model?: string;
|
|
423
|
+
/**
|
|
424
|
+
* Output dimensionality override.
|
|
425
|
+
* Must match what the knowledge store was initialised with — changing this requires wiping the store.
|
|
426
|
+
*/
|
|
427
|
+
outputDimensionality?: number;
|
|
428
|
+
/** Max retries on transient errors. Default: 3. */
|
|
429
|
+
retries?: number;
|
|
430
|
+
/** Delay between retries in ms. Default: 1000. */
|
|
431
|
+
retryDelay?: number;
|
|
432
|
+
}
|
|
433
|
+
declare class VertexAIEmbedder implements Embedder {
|
|
434
|
+
readonly dimensions: number;
|
|
435
|
+
private readonly projectId;
|
|
436
|
+
private readonly location;
|
|
437
|
+
private readonly model;
|
|
438
|
+
private readonly outputDimensionality;
|
|
439
|
+
private readonly retries;
|
|
440
|
+
private readonly retryDelay;
|
|
441
|
+
constructor(options?: VertexAIEmbedderOptions);
|
|
442
|
+
embed(text: string): Promise<number[]>;
|
|
443
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
444
|
+
private _request;
|
|
445
|
+
private _getAccessToken;
|
|
446
|
+
}
|
|
447
|
+
|
|
314
448
|
declare function keywordSearch(text: string, query: string): number;
|
|
315
449
|
declare function combineScores(semanticScore: number, keywordScore: number, semanticWeight?: number): number;
|
|
316
450
|
|
|
317
|
-
export { ApiDataSource, type ApiDataSourceOptions, type Chunk, ChunkTooLargeError, type ChunkUpdate, DimensionMismatchError, type Embedder, EmbeddingError, type EmbeddingProgressEvent, type EmbeddingProgressHandler, type ErrorHandler, IngestionError, Knowledge, KnowledgeError, type KnowledgeOptions, type KnowledgeProvider, KnowledgeProviderError, type KnowledgeSource, type KnowledgeTool, type KnowledgeToolParams, type KnowledgeToolResult, MarkdownSource, type MarkdownSourceOptions, MemoryProvider, type MemoryProviderOptions, type MetadataFilter, OllamaEmbedder, type OllamaEmbedderOptions, OpenAIEmbedder, type OpenAIEmbedderOptions, PersistentKnowledgeProvider, type PersistentKnowledgeProviderOptions, type QueryOptions, type QueryResult, type SyncEvent, type SyncEventHandler, WebUrlSource, type WebUrlSourceOptions, combineScores, keywordSearch };
|
|
451
|
+
export { ApiDataSource, type ApiDataSourceOptions, type Chunk, ChunkTooLargeError, type ChunkUpdate, DimensionMismatchError, type Embedder, EmbeddingError, type EmbeddingProgressEvent, type EmbeddingProgressHandler, type ErrorHandler, IngestionError, JSONSource, type JSONSourceOptions, Knowledge, KnowledgeError, type KnowledgeOptions, type KnowledgeProvider, KnowledgeProviderError, type KnowledgeSource, type KnowledgeTool, type KnowledgeToolParams, type KnowledgeToolResult, MarkdownSource, type MarkdownSourceOptions, MemoryProvider, type MemoryProviderOptions, type MetadataFilter, OllamaEmbedder, type OllamaEmbedderOptions, OpenAIEmbedder, type OpenAIEmbedderOptions, OpenRouterEmbedder, type OpenRouterEmbedderOptions, PersistentKnowledgeProvider, type PersistentKnowledgeProviderOptions, PostgresSource, type PostgresSourceOptions, type QueryOptions, type QueryResult, SQLiteSource, type SQLiteSourceOptions, type SyncEvent, type SyncEventHandler, VertexAIEmbedder, type VertexAIEmbedderOptions, WebUrlSource, type WebUrlSourceOptions, combineScores, keywordSearch };
|
package/dist/index.d.ts
CHANGED
|
@@ -120,6 +120,14 @@ declare class Knowledge {
|
|
|
120
120
|
private getAllChunks;
|
|
121
121
|
sync(): Promise<void>;
|
|
122
122
|
private embedChunks;
|
|
123
|
+
/**
|
|
124
|
+
* Add a single content item to the knowledge base without triggering a full re-sync.
|
|
125
|
+
* This is useful for runtime additions like conversation history or agent state.
|
|
126
|
+
* @param content The text content to add
|
|
127
|
+
* @param metadata Optional metadata to attach to the chunk
|
|
128
|
+
* @returns The ID of the added chunk
|
|
129
|
+
*/
|
|
130
|
+
add(content: string, metadata?: Record<string, unknown>): Promise<string>;
|
|
123
131
|
stop(): Promise<void>;
|
|
124
132
|
toTool(): KnowledgeTool;
|
|
125
133
|
}
|
|
@@ -276,6 +284,78 @@ declare class ApiDataSource implements KnowledgeSource {
|
|
|
276
284
|
private generateChunkId;
|
|
277
285
|
}
|
|
278
286
|
|
|
287
|
+
interface JSONSourceOptions {
|
|
288
|
+
namespace?: string;
|
|
289
|
+
metadata?: Record<string, unknown>;
|
|
290
|
+
filter?: (item: unknown) => boolean;
|
|
291
|
+
chunkSize?: number;
|
|
292
|
+
/** Required. Transform each JSON item into a human-readable string for AI embedding. */
|
|
293
|
+
toContent: (item: unknown) => string;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Knowledge source for JSON files.
|
|
297
|
+
* Supports jq-like filtering and chunking of large arrays.
|
|
298
|
+
*/
|
|
299
|
+
declare class JSONSource implements KnowledgeSource {
|
|
300
|
+
private filePath;
|
|
301
|
+
private options;
|
|
302
|
+
constructor(filePath: string, options: JSONSourceOptions);
|
|
303
|
+
load(): AsyncIterable<Chunk>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
interface SQLiteSourceOptions {
|
|
307
|
+
namespace?: string;
|
|
308
|
+
metadata?: Record<string, unknown>;
|
|
309
|
+
query?: string;
|
|
310
|
+
chunkSize?: number;
|
|
311
|
+
/** Required. Transform each database row into a human-readable string for AI embedding. */
|
|
312
|
+
toContent: (row: Record<string, unknown>) => string;
|
|
313
|
+
preLoadCSV?: {
|
|
314
|
+
tableName: string;
|
|
315
|
+
csvPath: string;
|
|
316
|
+
delimiter?: string;
|
|
317
|
+
headers?: boolean;
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Knowledge source for SQLite databases.
|
|
322
|
+
* Supports SQL queries and optional CSV/TSV pre-loading.
|
|
323
|
+
* Note: This requires the 'better-sqlite3' package to be installed.
|
|
324
|
+
*/
|
|
325
|
+
declare class SQLiteSource implements KnowledgeSource {
|
|
326
|
+
private dbPath;
|
|
327
|
+
private options;
|
|
328
|
+
constructor(dbPath: string, options: SQLiteSourceOptions);
|
|
329
|
+
load(): AsyncIterable<Chunk>;
|
|
330
|
+
private loadCSV;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
interface PostgresSourceOptions {
|
|
334
|
+
namespace?: string;
|
|
335
|
+
metadata?: Record<string, unknown>;
|
|
336
|
+
query: string;
|
|
337
|
+
chunkSize?: number;
|
|
338
|
+
/** Required. Transform each database row into a human-readable string for AI embedding. */
|
|
339
|
+
toContent: (row: Record<string, unknown>) => string;
|
|
340
|
+
connectionString?: string;
|
|
341
|
+
host?: string;
|
|
342
|
+
port?: number;
|
|
343
|
+
database?: string;
|
|
344
|
+
user?: string;
|
|
345
|
+
password?: string;
|
|
346
|
+
ssl?: boolean;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Knowledge source for PostgreSQL databases.
|
|
350
|
+
* Supports SQL queries with optional chunking.
|
|
351
|
+
* Note: This requires the 'pg' package to be installed.
|
|
352
|
+
*/
|
|
353
|
+
declare class PostgresSource implements KnowledgeSource {
|
|
354
|
+
private options;
|
|
355
|
+
constructor(options: PostgresSourceOptions);
|
|
356
|
+
load(): AsyncIterable<Chunk>;
|
|
357
|
+
}
|
|
358
|
+
|
|
279
359
|
interface OllamaEmbedderOptions {
|
|
280
360
|
model: string;
|
|
281
361
|
baseUrl?: string;
|
|
@@ -311,7 +391,61 @@ declare class OpenAIEmbedder implements Embedder {
|
|
|
311
391
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
312
392
|
}
|
|
313
393
|
|
|
394
|
+
interface OpenRouterEmbedderOptions {
|
|
395
|
+
model: string;
|
|
396
|
+
apiKey: string;
|
|
397
|
+
/** Override output dimensions for models not in the built-in map */
|
|
398
|
+
dimensions?: number;
|
|
399
|
+
retries?: number;
|
|
400
|
+
retryDelay?: number;
|
|
401
|
+
timeout?: number;
|
|
402
|
+
}
|
|
403
|
+
declare class OpenRouterEmbedder implements Embedder {
|
|
404
|
+
private options;
|
|
405
|
+
readonly dimensions: number;
|
|
406
|
+
private client;
|
|
407
|
+
constructor(options: OpenRouterEmbedderOptions);
|
|
408
|
+
private getModelDimensions;
|
|
409
|
+
embed(text: string): Promise<number[]>;
|
|
410
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface VertexAIEmbedderOptions {
|
|
414
|
+
/** GCP project ID. Falls back to VERTEX_AI_PROJECT / GOOGLE_CLOUD_PROJECT env vars. */
|
|
415
|
+
projectId?: string;
|
|
416
|
+
/** GCP region. Defaults to 'us-central1'. */
|
|
417
|
+
location?: string;
|
|
418
|
+
/**
|
|
419
|
+
* Embedding model. Defaults to 'gemini-embedding-2' (3072 dims).
|
|
420
|
+
* Other options: 'gemini-embedding-001' (3072), 'text-embedding-005' (768).
|
|
421
|
+
*/
|
|
422
|
+
model?: string;
|
|
423
|
+
/**
|
|
424
|
+
* Output dimensionality override.
|
|
425
|
+
* Must match what the knowledge store was initialised with — changing this requires wiping the store.
|
|
426
|
+
*/
|
|
427
|
+
outputDimensionality?: number;
|
|
428
|
+
/** Max retries on transient errors. Default: 3. */
|
|
429
|
+
retries?: number;
|
|
430
|
+
/** Delay between retries in ms. Default: 1000. */
|
|
431
|
+
retryDelay?: number;
|
|
432
|
+
}
|
|
433
|
+
declare class VertexAIEmbedder implements Embedder {
|
|
434
|
+
readonly dimensions: number;
|
|
435
|
+
private readonly projectId;
|
|
436
|
+
private readonly location;
|
|
437
|
+
private readonly model;
|
|
438
|
+
private readonly outputDimensionality;
|
|
439
|
+
private readonly retries;
|
|
440
|
+
private readonly retryDelay;
|
|
441
|
+
constructor(options?: VertexAIEmbedderOptions);
|
|
442
|
+
embed(text: string): Promise<number[]>;
|
|
443
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
444
|
+
private _request;
|
|
445
|
+
private _getAccessToken;
|
|
446
|
+
}
|
|
447
|
+
|
|
314
448
|
declare function keywordSearch(text: string, query: string): number;
|
|
315
449
|
declare function combineScores(semanticScore: number, keywordScore: number, semanticWeight?: number): number;
|
|
316
450
|
|
|
317
|
-
export { ApiDataSource, type ApiDataSourceOptions, type Chunk, ChunkTooLargeError, type ChunkUpdate, DimensionMismatchError, type Embedder, EmbeddingError, type EmbeddingProgressEvent, type EmbeddingProgressHandler, type ErrorHandler, IngestionError, Knowledge, KnowledgeError, type KnowledgeOptions, type KnowledgeProvider, KnowledgeProviderError, type KnowledgeSource, type KnowledgeTool, type KnowledgeToolParams, type KnowledgeToolResult, MarkdownSource, type MarkdownSourceOptions, MemoryProvider, type MemoryProviderOptions, type MetadataFilter, OllamaEmbedder, type OllamaEmbedderOptions, OpenAIEmbedder, type OpenAIEmbedderOptions, PersistentKnowledgeProvider, type PersistentKnowledgeProviderOptions, type QueryOptions, type QueryResult, type SyncEvent, type SyncEventHandler, WebUrlSource, type WebUrlSourceOptions, combineScores, keywordSearch };
|
|
451
|
+
export { ApiDataSource, type ApiDataSourceOptions, type Chunk, ChunkTooLargeError, type ChunkUpdate, DimensionMismatchError, type Embedder, EmbeddingError, type EmbeddingProgressEvent, type EmbeddingProgressHandler, type ErrorHandler, IngestionError, JSONSource, type JSONSourceOptions, Knowledge, KnowledgeError, type KnowledgeOptions, type KnowledgeProvider, KnowledgeProviderError, type KnowledgeSource, type KnowledgeTool, type KnowledgeToolParams, type KnowledgeToolResult, MarkdownSource, type MarkdownSourceOptions, MemoryProvider, type MemoryProviderOptions, type MetadataFilter, OllamaEmbedder, type OllamaEmbedderOptions, OpenAIEmbedder, type OpenAIEmbedderOptions, OpenRouterEmbedder, type OpenRouterEmbedderOptions, PersistentKnowledgeProvider, type PersistentKnowledgeProviderOptions, PostgresSource, type PostgresSourceOptions, type QueryOptions, type QueryResult, SQLiteSource, type SQLiteSourceOptions, type SyncEvent, type SyncEventHandler, VertexAIEmbedder, type VertexAIEmbedderOptions, WebUrlSource, type WebUrlSourceOptions, combineScores, keywordSearch };
|