@lov3kaizen/agentsea-embeddings 1.1.0 → 1.2.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.
@@ -457,13 +457,17 @@ var RedisCache = class extends BaseCache {
457
457
  async set(key, entry) {
458
458
  const client = await this.ensureConnected();
459
459
  const data = JSON.stringify(entry);
460
- const options = {};
460
+ let ttl = 0;
461
461
  if (entry.ttl > 0) {
462
- options.EX = entry.ttl;
462
+ ttl = entry.ttl;
463
463
  } else if (this.config.defaultTTL && this.config.defaultTTL > 0) {
464
- options.EX = this.config.defaultTTL;
464
+ ttl = this.config.defaultTTL;
465
+ }
466
+ if (ttl > 0) {
467
+ await client.set(this.prefixKey(key), data, "EX", ttl);
468
+ } else {
469
+ await client.set(this.prefixKey(key), data);
465
470
  }
466
- await client.set(this.prefixKey(key), data, options);
467
471
  this.stats.entries++;
468
472
  }
469
473
  async has(key) {
@@ -10,7 +10,7 @@ import {
10
10
  createSQLiteCache,
11
11
  createStandardTieredCache,
12
12
  createTieredCache
13
- } from "../chunk-MNJPAUDC.mjs";
13
+ } from "../chunk-QG3YCWYG.mjs";
14
14
  import "../chunk-3KM32UQK.mjs";
15
15
  export {
16
16
  BaseCache,
@@ -409,13 +409,17 @@ var RedisCache = class extends BaseCache {
409
409
  async set(key, entry) {
410
410
  const client = await this.ensureConnected();
411
411
  const data = JSON.stringify(entry);
412
- const options = {};
412
+ let ttl = 0;
413
413
  if (entry.ttl > 0) {
414
- options.EX = entry.ttl;
414
+ ttl = entry.ttl;
415
415
  } else if (this.config.defaultTTL && this.config.defaultTTL > 0) {
416
- options.EX = this.config.defaultTTL;
416
+ ttl = this.config.defaultTTL;
417
+ }
418
+ if (ttl > 0) {
419
+ await client.set(this.prefixKey(key), data, "EX", ttl);
420
+ } else {
421
+ await client.set(this.prefixKey(key), data);
417
422
  }
418
- await client.set(this.prefixKey(key), data, options);
419
423
  this.stats.entries++;
420
424
  }
421
425
  async has(key) {
@@ -2,8 +2,37 @@ import {
2
2
  EmbeddingModel
3
3
  } from "./chunk-QAITLJ2E.mjs";
4
4
 
5
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
6
+ import { webcrypto as crypto } from "crypto";
7
+
8
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
9
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
10
+
11
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
12
+ var POOL_SIZE_MULTIPLIER = 128;
13
+ var pool;
14
+ var poolOffset;
15
+ function fillPool(bytes) {
16
+ if (!pool || pool.length < bytes) {
17
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
18
+ crypto.getRandomValues(pool);
19
+ poolOffset = 0;
20
+ } else if (poolOffset + bytes > pool.length) {
21
+ crypto.getRandomValues(pool);
22
+ poolOffset = 0;
23
+ }
24
+ poolOffset += bytes;
25
+ }
26
+ function nanoid(size = 21) {
27
+ fillPool(size |= 0);
28
+ let id = "";
29
+ for (let i = poolOffset - size; i < poolOffset; i++) {
30
+ id += urlAlphabet[pool[i] & 63];
31
+ }
32
+ return id;
33
+ }
34
+
5
35
  // src/chunking/BaseChunker.ts
6
- import { nanoid } from "nanoid";
7
36
  var defaultTokenCounter = (text) => {
8
37
  return Math.ceil(text.length / 4);
9
38
  };
@@ -1098,6 +1127,7 @@ async function chunk(text, strategy = "recursive", options) {
1098
1127
  }
1099
1128
 
1100
1129
  export {
1130
+ nanoid,
1101
1131
  defaultTokenCounter,
1102
1132
  BaseChunker,
1103
1133
  mergeSmallChunks,
@@ -39,8 +39,37 @@ __export(chunking_exports, {
39
39
  });
40
40
  module.exports = __toCommonJS(chunking_exports);
41
41
 
42
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
43
+ var import_node_crypto = require("crypto");
44
+
45
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
46
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
47
+
48
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
49
+ var POOL_SIZE_MULTIPLIER = 128;
50
+ var pool;
51
+ var poolOffset;
52
+ function fillPool(bytes) {
53
+ if (!pool || pool.length < bytes) {
54
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
55
+ import_node_crypto.webcrypto.getRandomValues(pool);
56
+ poolOffset = 0;
57
+ } else if (poolOffset + bytes > pool.length) {
58
+ import_node_crypto.webcrypto.getRandomValues(pool);
59
+ poolOffset = 0;
60
+ }
61
+ poolOffset += bytes;
62
+ }
63
+ function nanoid(size = 21) {
64
+ fillPool(size |= 0);
65
+ let id = "";
66
+ for (let i = poolOffset - size; i < poolOffset; i++) {
67
+ id += urlAlphabet[pool[i] & 63];
68
+ }
69
+ return id;
70
+ }
71
+
42
72
  // src/chunking/BaseChunker.ts
43
- var import_nanoid = require("nanoid");
44
73
  var defaultTokenCounter = (text) => {
45
74
  return Math.ceil(text.length / 4);
46
75
  };
@@ -82,7 +111,7 @@ var BaseChunker = class {
82
111
  if (options.source) metadata.source = options.source;
83
112
  if (options.type) metadata.type = options.type;
84
113
  return {
85
- id: (0, import_nanoid.nanoid)(),
114
+ id: nanoid(),
86
115
  text,
87
116
  index,
88
117
  startPosition,
@@ -190,7 +219,7 @@ function splitLargeChunks(chunks, maxTokens, tokenCounter) {
190
219
  if (testTokens > maxTokens && currentText) {
191
220
  result.push({
192
221
  ...chunk2,
193
- id: (0, import_nanoid.nanoid)(),
222
+ id: nanoid(),
194
223
  text: currentText,
195
224
  startPosition: currentStart,
196
225
  endPosition: currentStart + currentText.length,
@@ -206,7 +235,7 @@ function splitLargeChunks(chunks, maxTokens, tokenCounter) {
206
235
  if (currentText) {
207
236
  result.push({
208
237
  ...chunk2,
209
- id: (0, import_nanoid.nanoid)(),
238
+ id: nanoid(),
210
239
  text: currentText,
211
240
  startPosition: currentStart,
212
241
  endPosition: currentStart + currentText.length,
@@ -15,7 +15,7 @@ import {
15
15
  defaultTokenCounter,
16
16
  mergeSmallChunks,
17
17
  splitLargeChunks
18
- } from "../chunk-DJAURHAS.mjs";
18
+ } from "../chunk-U6EYWYUD.mjs";
19
19
  import "../chunk-QAITLJ2E.mjs";
20
20
  export {
21
21
  BaseChunker,
package/dist/index.js CHANGED
@@ -1814,8 +1814,37 @@ function createHuggingFaceProvider(config) {
1814
1814
  return new HuggingFaceProvider(config);
1815
1815
  }
1816
1816
 
1817
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
1818
+ var import_node_crypto = require("crypto");
1819
+
1820
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
1821
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1822
+
1823
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
1824
+ var POOL_SIZE_MULTIPLIER = 128;
1825
+ var pool;
1826
+ var poolOffset;
1827
+ function fillPool(bytes) {
1828
+ if (!pool || pool.length < bytes) {
1829
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
1830
+ import_node_crypto.webcrypto.getRandomValues(pool);
1831
+ poolOffset = 0;
1832
+ } else if (poolOffset + bytes > pool.length) {
1833
+ import_node_crypto.webcrypto.getRandomValues(pool);
1834
+ poolOffset = 0;
1835
+ }
1836
+ poolOffset += bytes;
1837
+ }
1838
+ function nanoid(size = 21) {
1839
+ fillPool(size |= 0);
1840
+ let id = "";
1841
+ for (let i = poolOffset - size; i < poolOffset; i++) {
1842
+ id += urlAlphabet[pool[i] & 63];
1843
+ }
1844
+ return id;
1845
+ }
1846
+
1817
1847
  // src/chunking/BaseChunker.ts
1818
- var import_nanoid = require("nanoid");
1819
1848
  var defaultTokenCounter = (text) => {
1820
1849
  return Math.ceil(text.length / 4);
1821
1850
  };
@@ -1857,7 +1886,7 @@ var BaseChunker = class {
1857
1886
  if (options.source) metadata.source = options.source;
1858
1887
  if (options.type) metadata.type = options.type;
1859
1888
  return {
1860
- id: (0, import_nanoid.nanoid)(),
1889
+ id: nanoid(),
1861
1890
  text,
1862
1891
  index,
1863
1892
  startPosition,
@@ -1965,7 +1994,7 @@ function splitLargeChunks(chunks, maxTokens, tokenCounter) {
1965
1994
  if (testTokens > maxTokens && currentText) {
1966
1995
  result.push({
1967
1996
  ...chunk2,
1968
- id: (0, import_nanoid.nanoid)(),
1997
+ id: nanoid(),
1969
1998
  text: currentText,
1970
1999
  startPosition: currentStart,
1971
2000
  endPosition: currentStart + currentText.length,
@@ -1981,7 +2010,7 @@ function splitLargeChunks(chunks, maxTokens, tokenCounter) {
1981
2010
  if (currentText) {
1982
2011
  result.push({
1983
2012
  ...chunk2,
1984
- id: (0, import_nanoid.nanoid)(),
2013
+ id: nanoid(),
1985
2014
  text: currentText,
1986
2015
  startPosition: currentStart,
1987
2016
  endPosition: currentStart + currentText.length,
@@ -3316,13 +3345,17 @@ var RedisCache = class extends BaseCache {
3316
3345
  async set(key, entry) {
3317
3346
  const client = await this.ensureConnected();
3318
3347
  const data = JSON.stringify(entry);
3319
- const options = {};
3348
+ let ttl = 0;
3320
3349
  if (entry.ttl > 0) {
3321
- options.EX = entry.ttl;
3350
+ ttl = entry.ttl;
3322
3351
  } else if (this.config.defaultTTL && this.config.defaultTTL > 0) {
3323
- options.EX = this.config.defaultTTL;
3352
+ ttl = this.config.defaultTTL;
3353
+ }
3354
+ if (ttl > 0) {
3355
+ await client.set(this.prefixKey(key), data, "EX", ttl);
3356
+ } else {
3357
+ await client.set(this.prefixKey(key), data);
3324
3358
  }
3325
- await client.set(this.prefixKey(key), data, options);
3326
3359
  this.stats.entries++;
3327
3360
  }
3328
3361
  async has(key) {
@@ -5467,7 +5500,6 @@ function createStore(type, config) {
5467
5500
  }
5468
5501
 
5469
5502
  // src/versioning/VersionRegistry.ts
5470
- var import_nanoid2 = require("nanoid");
5471
5503
  var import_eventemitter32 = __toESM(require("eventemitter3"));
5472
5504
  var VersionRegistry = class extends import_eventemitter32.default {
5473
5505
  versions = /* @__PURE__ */ new Map();
@@ -5488,7 +5520,7 @@ var VersionRegistry = class extends import_eventemitter32.default {
5488
5520
  register(version) {
5489
5521
  const newVersion = {
5490
5522
  ...version,
5491
- id: (0, import_nanoid2.nanoid)(),
5523
+ id: nanoid(),
5492
5524
  createdAt: Date.now(),
5493
5525
  active: false,
5494
5526
  deprecated: false
@@ -5719,7 +5751,6 @@ function createVersionRegistry(options) {
5719
5751
 
5720
5752
  // src/quality/DriftDetector.ts
5721
5753
  var import_eventemitter33 = __toESM(require("eventemitter3"));
5722
- var import_nanoid3 = require("nanoid");
5723
5754
  var DriftDetector = class extends import_eventemitter33.default {
5724
5755
  reference = null;
5725
5756
  config;
@@ -5754,7 +5785,7 @@ var DriftDetector = class extends import_eventemitter33.default {
5754
5785
  varianceVector.push(variance(values));
5755
5786
  }
5756
5787
  this.reference = {
5757
- id: (0, import_nanoid3.nanoid)(),
5788
+ id: nanoid(),
5758
5789
  model,
5759
5790
  version,
5760
5791
  sampleCount: embeddings.length,
@@ -5929,7 +5960,7 @@ var DriftDetector = class extends import_eventemitter33.default {
5929
5960
  */
5930
5961
  emitAlert(result) {
5931
5962
  const alert = {
5932
- id: (0, import_nanoid3.nanoid)(),
5963
+ id: nanoid(),
5933
5964
  type: "drift_detected",
5934
5965
  severity: result.severity,
5935
5966
  message: `Embedding drift detected with score ${result.driftScore.toFixed(3)}`,
package/dist/index.mjs CHANGED
@@ -1,16 +1,3 @@
1
- import {
2
- BaseCache,
3
- MemoryCache,
4
- RedisCache,
5
- SQLiteCache,
6
- TieredCache,
7
- createCache,
8
- createMemoryCache,
9
- createRedisCache,
10
- createSQLiteCache,
11
- createStandardTieredCache,
12
- createTieredCache
13
- } from "./chunk-MNJPAUDC.mjs";
14
1
  import {
15
2
  BaseChunker,
16
3
  CodeChunker,
@@ -27,8 +14,22 @@ import {
27
14
  createSemanticChunker,
28
15
  defaultTokenCounter,
29
16
  mergeSmallChunks,
17
+ nanoid,
30
18
  splitLargeChunks
31
- } from "./chunk-DJAURHAS.mjs";
19
+ } from "./chunk-U6EYWYUD.mjs";
20
+ import {
21
+ BaseCache,
22
+ MemoryCache,
23
+ RedisCache,
24
+ SQLiteCache,
25
+ TieredCache,
26
+ createCache,
27
+ createMemoryCache,
28
+ createRedisCache,
29
+ createSQLiteCache,
30
+ createStandardTieredCache,
31
+ createTieredCache
32
+ } from "./chunk-QG3YCWYG.mjs";
32
33
  import {
33
34
  BaseProvider,
34
35
  CohereProvider,
@@ -43,7 +44,7 @@ import {
43
44
  createOpenAIProvider,
44
45
  createRandomProvider,
45
46
  createVoyageProvider
46
- } from "./chunk-5GTQFVEI.mjs";
47
+ } from "./chunk-G4WUUZJH.mjs";
47
48
  import {
48
49
  BaseStore,
49
50
  ChromaStore,
@@ -55,8 +56,13 @@ import {
55
56
  createPineconeStore,
56
57
  createQdrantStore,
57
58
  createStore
58
- } from "./chunk-JHWMXQ56.mjs";
59
+ } from "./chunk-MDU673U5.mjs";
59
60
  import "./chunk-2TCNSTX3.mjs";
61
+ import {
62
+ EmbeddingModel,
63
+ ModelRegistry,
64
+ modelRegistry
65
+ } from "./chunk-QAITLJ2E.mjs";
60
66
  import {
61
67
  batch,
62
68
  cacheKey,
@@ -81,11 +87,6 @@ import {
81
87
  variance,
82
88
  withConcurrency
83
89
  } from "./chunk-3KM32UQK.mjs";
84
- import {
85
- EmbeddingModel,
86
- ModelRegistry,
87
- modelRegistry
88
- } from "./chunk-QAITLJ2E.mjs";
89
90
 
90
91
  // src/core/EmbeddingManager.ts
91
92
  import EventEmitter from "eventemitter3";
@@ -433,7 +434,6 @@ function createEmbeddingManager(config) {
433
434
  }
434
435
 
435
436
  // src/versioning/VersionRegistry.ts
436
- import { nanoid } from "nanoid";
437
437
  import EventEmitter2 from "eventemitter3";
438
438
  var VersionRegistry = class extends EventEmitter2 {
439
439
  versions = /* @__PURE__ */ new Map();
@@ -685,7 +685,6 @@ function createVersionRegistry(options) {
685
685
 
686
686
  // src/quality/DriftDetector.ts
687
687
  import EventEmitter3 from "eventemitter3";
688
- import { nanoid as nanoid2 } from "nanoid";
689
688
  var DriftDetector = class extends EventEmitter3 {
690
689
  reference = null;
691
690
  config;
@@ -720,7 +719,7 @@ var DriftDetector = class extends EventEmitter3 {
720
719
  varianceVector.push(variance(values));
721
720
  }
722
721
  this.reference = {
723
- id: nanoid2(),
722
+ id: nanoid(),
724
723
  model,
725
724
  version,
726
725
  sampleCount: embeddings.length,
@@ -895,7 +894,7 @@ var DriftDetector = class extends EventEmitter3 {
895
894
  */
896
895
  emitAlert(result) {
897
896
  const alert = {
898
- id: nanoid2(),
897
+ id: nanoid(),
899
898
  type: "drift_detected",
900
899
  severity: result.severity,
901
900
  message: `Embedding drift detected with score ${result.driftScore.toFixed(3)}`,
@@ -12,10 +12,10 @@ import {
12
12
  createOpenAIProvider,
13
13
  createRandomProvider,
14
14
  createVoyageProvider
15
- } from "../chunk-5GTQFVEI.mjs";
15
+ } from "../chunk-G4WUUZJH.mjs";
16
16
  import "../chunk-2TCNSTX3.mjs";
17
- import "../chunk-3KM32UQK.mjs";
18
17
  import "../chunk-QAITLJ2E.mjs";
18
+ import "../chunk-3KM32UQK.mjs";
19
19
  export {
20
20
  BaseProvider,
21
21
  CohereProvider,
@@ -17,10 +17,10 @@ import {
17
17
  createQdrantStore,
18
18
  createStore,
19
19
  createWeaviateStore
20
- } from "../chunk-JHWMXQ56.mjs";
20
+ } from "../chunk-MDU673U5.mjs";
21
21
  import "../chunk-2TCNSTX3.mjs";
22
- import "../chunk-3KM32UQK.mjs";
23
22
  import "../chunk-QAITLJ2E.mjs";
23
+ import "../chunk-3KM32UQK.mjs";
24
24
  export {
25
25
  BaseStore,
26
26
  ChromaStore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lov3kaizen/agentsea-embeddings",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Vector embedding lifecycle management toolkit for Node.js - versioning, caching, chunking, drift detection, and migration",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -61,12 +61,12 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "eventemitter3": "^5.0.0",
64
- "lru-cache": "^10.0.0",
65
- "nanoid": "^5.0.0"
64
+ "lru-cache": "^10.0.0"
66
65
  },
67
66
  "devDependencies": {
68
67
  "@types/better-sqlite3": "^7.6.0",
69
68
  "@types/node": "^20.0.0",
69
+ "nanoid": "^5.0.0",
70
70
  "tsup": "^8.0.0",
71
71
  "typescript": "^5.3.0",
72
72
  "vitest": "^3.2.6"
@@ -94,8 +94,8 @@
94
94
  "node": ">=20.0.0"
95
95
  },
96
96
  "scripts": {
97
- "build": "tsup src/index.ts src/chunking/index.ts src/caching/index.ts src/stores/index.ts src/providers/index.ts --format cjs,esm --dts --clean --external ioredis --external better-sqlite3 --external chromadb --external @pinecone-database/pinecone --external @qdrant/js-client-rest --external weaviate-ts-client --external cohere-ai --external ollama --external pg --external @zilliz/milvus2-sdk-node --external @xenova/transformers",
98
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
97
+ "build": "tsup",
98
+ "dev": "tsup --watch",
99
99
  "test": "vitest run",
100
100
  "test:watch": "vitest",
101
101
  "test:coverage": "vitest run --coverage",
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  importOptional
3
3
  } from "./chunk-2TCNSTX3.mjs";
4
+ import {
5
+ EmbeddingModel
6
+ } from "./chunk-QAITLJ2E.mjs";
4
7
  import {
5
8
  batch,
6
9
  measureTime,
7
10
  retry,
8
11
  withConcurrency
9
12
  } from "./chunk-3KM32UQK.mjs";
10
- import {
11
- EmbeddingModel
12
- } from "./chunk-QAITLJ2E.mjs";
13
13
 
14
14
  // src/providers/BaseProvider.ts
15
15
  var BaseProvider = class extends EmbeddingModel {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  importOptional
3
3
  } from "./chunk-2TCNSTX3.mjs";
4
- import {
5
- batch
6
- } from "./chunk-3KM32UQK.mjs";
7
4
  import {
8
5
  EmbeddingModel
9
6
  } from "./chunk-QAITLJ2E.mjs";
7
+ import {
8
+ batch
9
+ } from "./chunk-3KM32UQK.mjs";
10
10
 
11
11
  // src/stores/BaseStore.ts
12
12
  var BaseStore = class {