mem0ai 2.3.0 → 2.4.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/dist/oss/index.js CHANGED
@@ -83,6 +83,7 @@ var MemoryConfigSchema = import_zod.z.object({
83
83
  config: import_zod.z.object({
84
84
  collectionName: import_zod.z.string().optional(),
85
85
  dimension: import_zod.z.number().optional(),
86
+ dbPath: import_zod.z.string().optional(),
86
87
  client: import_zod.z.any().optional()
87
88
  }).passthrough()
88
89
  }),
@@ -122,7 +123,10 @@ var MemoryConfigSchema = import_zod.z.object({
122
123
  var import_openai = __toESM(require("openai"));
123
124
  var OpenAIEmbedder = class {
124
125
  constructor(config) {
125
- this.openai = new import_openai.default({ apiKey: config.apiKey });
126
+ this.openai = new import_openai.default({
127
+ apiKey: config.apiKey,
128
+ baseURL: config.baseURL || config.url
129
+ });
126
130
  this.model = config.model || "text-embedding-3-small";
127
131
  this.embeddingDims = config.embeddingDims || 1536;
128
132
  }
@@ -471,14 +475,37 @@ var MistralLLM = class {
471
475
 
472
476
  // src/oss/src/vector_stores/memory.ts
473
477
  var import_better_sqlite3 = __toESM(require("better-sqlite3"));
478
+ var import_fs2 = __toESM(require("fs"));
479
+ var import_path2 = __toESM(require("path"));
480
+
481
+ // src/oss/src/utils/sqlite.ts
482
+ var import_fs = __toESM(require("fs"));
483
+ var import_os = __toESM(require("os"));
474
484
  var import_path = __toESM(require("path"));
485
+ function getDefaultVectorStoreDbPath() {
486
+ return import_path.default.join(import_os.default.homedir(), ".mem0", "vector_store.db");
487
+ }
488
+ function ensureSQLiteDirectory(dbPath) {
489
+ if (!dbPath || dbPath === ":memory:" || dbPath.startsWith("file:")) {
490
+ return;
491
+ }
492
+ import_fs.default.mkdirSync(import_path.default.dirname(dbPath), { recursive: true });
493
+ }
494
+
495
+ // src/oss/src/vector_stores/memory.ts
475
496
  var MemoryVectorStore = class {
476
497
  constructor(config) {
477
498
  this.dimension = config.dimension || 1536;
478
- this.dbPath = import_path.default.join(process.cwd(), "vector_store.db");
479
- if (config.dbPath) {
480
- this.dbPath = config.dbPath;
499
+ this.dbPath = config.dbPath || getDefaultVectorStoreDbPath();
500
+ if (!config.dbPath) {
501
+ const oldDefault = import_path2.default.join(process.cwd(), "vector_store.db");
502
+ if (import_fs2.default.existsSync(oldDefault) && oldDefault !== this.dbPath) {
503
+ console.warn(
504
+ `[mem0] Default vector_store.db location changed from ${oldDefault} to ${this.dbPath}. Move your existing file or set vectorStore.config.dbPath explicitly.`
505
+ );
506
+ }
481
507
  }
508
+ ensureSQLiteDirectory(this.dbPath);
482
509
  this.db = new import_better_sqlite3.default(this.dbPath);
483
510
  this.init();
484
511
  }
@@ -635,7 +662,7 @@ var MemoryVectorStore = class {
635
662
 
636
663
  // src/oss/src/vector_stores/qdrant.ts
637
664
  var import_js_client_rest = require("@qdrant/js-client-rest");
638
- var fs = __toESM(require("fs"));
665
+ var fs3 = __toESM(require("fs"));
639
666
  var Qdrant = class {
640
667
  constructor(config) {
641
668
  if (config.client) {
@@ -655,8 +682,8 @@ var Qdrant = class {
655
682
  if (!Object.keys(params).length) {
656
683
  params.path = config.path;
657
684
  if (!config.onDisk && config.path) {
658
- if (fs.existsSync(config.path) && fs.statSync(config.path).isDirectory()) {
659
- fs.rmSync(config.path, { recursive: true });
685
+ if (fs3.existsSync(config.path) && fs3.statSync(config.path).isDirectory()) {
686
+ fs3.rmSync(config.path, { recursive: true });
660
687
  }
661
688
  }
662
689
  }
@@ -771,19 +798,7 @@ var Qdrant = class {
771
798
  async getUserId() {
772
799
  var _a2;
773
800
  try {
774
- const collections = await this.client.getCollections();
775
- const userCollectionExists = collections.collections.some(
776
- (col) => col.name === "memory_migrations"
777
- );
778
- if (!userCollectionExists) {
779
- await this.client.createCollection("memory_migrations", {
780
- vectors: {
781
- size: 1,
782
- distance: "Cosine",
783
- on_disk: false
784
- }
785
- });
786
- }
801
+ await this.ensureCollection("memory_migrations", 1);
787
802
  const result = await this.client.scroll("memory_migrations", {
788
803
  limit: 1,
789
804
  with_payload: true
@@ -828,56 +843,50 @@ var Qdrant = class {
828
843
  throw error;
829
844
  }
830
845
  }
831
- async initialize() {
832
- var _a2, _b;
846
+ async ensureCollection(name, size) {
847
+ var _a2, _b, _c;
833
848
  try {
834
- const collections = await this.client.getCollections();
835
- const exists = collections.collections.some(
836
- (c) => c.name === this.collectionName
837
- );
838
- if (!exists) {
839
- try {
840
- await this.client.createCollection(this.collectionName, {
841
- vectors: {
842
- size: this.dimension,
843
- distance: "Cosine"
844
- }
845
- });
846
- } catch (error) {
847
- if ((error == null ? void 0 : error.status) === 409) {
848
- const collectionInfo = await this.client.getCollection(
849
- this.collectionName
850
- );
849
+ await this.client.createCollection(name, {
850
+ vectors: {
851
+ size,
852
+ distance: "Cosine"
853
+ }
854
+ });
855
+ } catch (error) {
856
+ if ((error == null ? void 0 : error.status) === 409) {
857
+ if (name === this.collectionName) {
858
+ try {
859
+ const collectionInfo = await this.client.getCollection(name);
851
860
  const vectorConfig = (_b = (_a2 = collectionInfo.config) == null ? void 0 : _a2.params) == null ? void 0 : _b.vectors;
852
- if (!vectorConfig || vectorConfig.size !== this.dimension) {
861
+ if (vectorConfig && vectorConfig.size !== size) {
853
862
  throw new Error(
854
- `Collection ${this.collectionName} exists but has wrong configuration. Expected vector size: ${this.dimension}, got: ${vectorConfig == null ? void 0 : vectorConfig.size}`
863
+ `Collection ${name} exists but has wrong vector size. Expected: ${size}, got: ${vectorConfig.size}`
855
864
  );
856
865
  }
857
- } else {
858
- throw error;
859
- }
860
- }
861
- }
862
- const userExists = collections.collections.some(
863
- (c) => c.name === "memory_migrations"
864
- );
865
- if (!userExists) {
866
- try {
867
- await this.client.createCollection("memory_migrations", {
868
- vectors: {
869
- size: 1,
870
- // Minimal size since we only store user_id
871
- distance: "Cosine"
866
+ } catch (verifyError) {
867
+ if ((_c = verifyError == null ? void 0 : verifyError.message) == null ? void 0 : _c.includes("wrong vector size")) {
868
+ throw verifyError;
872
869
  }
873
- });
874
- } catch (error) {
875
- if ((error == null ? void 0 : error.status) === 409) {
876
- } else {
877
- throw error;
870
+ console.warn(
871
+ `Collection '${name}' exists (409) but dimension verification failed: ${(verifyError == null ? void 0 : verifyError.message) || verifyError}. Proceeding anyway.`
872
+ );
878
873
  }
879
874
  }
875
+ } else {
876
+ throw error;
880
877
  }
878
+ }
879
+ }
880
+ async initialize() {
881
+ if (!this._initPromise) {
882
+ this._initPromise = this._doInitialize();
883
+ }
884
+ return this._initPromise;
885
+ }
886
+ async _doInitialize() {
887
+ try {
888
+ await this.ensureCollection(this.collectionName, this.dimension);
889
+ await this.ensureCollection("memory_migrations", 1);
881
890
  } catch (error) {
882
891
  console.error("Error initializing Qdrant:", error);
883
892
  throw error;
@@ -1172,6 +1181,12 @@ var VectorizeDB = class {
1172
1181
  }
1173
1182
  }
1174
1183
  async initialize() {
1184
+ if (!this._initPromise) {
1185
+ this._initPromise = this._doInitialize();
1186
+ }
1187
+ return this._initPromise;
1188
+ }
1189
+ async _doInitialize() {
1175
1190
  var _a2, _b, _c, _d, _e;
1176
1191
  try {
1177
1192
  let indexFound = false;
@@ -1395,6 +1410,12 @@ var RedisDB = class {
1395
1410
  }
1396
1411
  }
1397
1412
  async initialize() {
1413
+ if (!this._initPromise) {
1414
+ this._initPromise = this._doInitialize();
1415
+ }
1416
+ return this._initPromise;
1417
+ }
1418
+ async _doInitialize() {
1398
1419
  try {
1399
1420
  await this.client.connect();
1400
1421
  console.log("Connected to Redis");
@@ -1827,6 +1848,12 @@ var SupabaseDB = class {
1827
1848
  });
1828
1849
  }
1829
1850
  async initialize() {
1851
+ if (!this._initPromise) {
1852
+ this._initPromise = this._doInitialize();
1853
+ }
1854
+ return this._initPromise;
1855
+ }
1856
+ async _doInitialize() {
1830
1857
  try {
1831
1858
  const testVector = Array(1536).fill(0);
1832
1859
  try {
@@ -2054,6 +2081,7 @@ See the SQL migration instructions in the code comments.`
2054
2081
  var import_better_sqlite32 = __toESM(require("better-sqlite3"));
2055
2082
  var SQLiteManager = class {
2056
2083
  constructor(dbPath) {
2084
+ ensureSQLiteDirectory(dbPath);
2057
2085
  this.db = new import_better_sqlite32.default(dbPath);
2058
2086
  this.init();
2059
2087
  }
@@ -2223,7 +2251,7 @@ var GoogleEmbedder = class {
2223
2251
  const response = await this.google.models.embedContent({
2224
2252
  model: this.model,
2225
2253
  contents: texts,
2226
- config: { outputDimensionality: 768 }
2254
+ config: { outputDimensionality: this.embeddingDims }
2227
2255
  });
2228
2256
  return response.embeddings.map((item) => item.values);
2229
2257
  }
@@ -2618,7 +2646,7 @@ function getUpdateMemoryMessages(retrievedOldMemory, newRetrievedFacts) {
2618
2646
  Do not return anything except the JSON format.`;
2619
2647
  }
2620
2648
  function removeCodeBlocks(text) {
2621
- return text.replace(/```[^`]*```/g, "");
2649
+ return text.replace(/```(?:\w+)?\n?([\s\S]*?)```/g, "$1").trim();
2622
2650
  }
2623
2651
 
2624
2652
  // src/oss/src/graphs/tools.ts
@@ -3123,6 +3151,12 @@ var AzureAISearch = class {
3123
3151
  * Initialize the Azure AI Search index if it doesn't exist
3124
3152
  */
3125
3153
  async initialize() {
3154
+ if (!this._initPromise) {
3155
+ this._initPromise = this._doInitialize();
3156
+ }
3157
+ return this._initPromise;
3158
+ }
3159
+ async _doInitialize() {
3126
3160
  try {
3127
3161
  const collections = await this.listCols();
3128
3162
  if (!collections.includes(this.indexName)) {
@@ -3694,7 +3728,7 @@ var DEFAULT_MEMORY_CONFIG = {
3694
3728
  // src/oss/src/config/manager.ts
3695
3729
  var ConfigManager = class {
3696
3730
  static mergeConfig(userConfig = {}) {
3697
- var _a2, _b, _c;
3731
+ var _a2, _b, _c, _d, _e, _f, _g;
3698
3732
  const mergedConfig = {
3699
3733
  version: userConfig.version || DEFAULT_MEMORY_CONFIG.version,
3700
3734
  embedder: {
@@ -3712,6 +3746,7 @@ var ConfigManager = class {
3712
3746
  return {
3713
3747
  apiKey: (userConf == null ? void 0 : userConf.apiKey) !== void 0 ? userConf.apiKey : defaultConf.apiKey,
3714
3748
  model: finalModel,
3749
+ baseURL: userConf == null ? void 0 : userConf.baseURL,
3715
3750
  url: userConf == null ? void 0 : userConf.url,
3716
3751
  embeddingDims: userConf == null ? void 0 : userConf.embeddingDims,
3717
3752
  modelProperties: (userConf == null ? void 0 : userConf.modelProperties) !== void 0 ? userConf.modelProperties : defaultConf.modelProperties
@@ -3721,24 +3756,22 @@ var ConfigManager = class {
3721
3756
  vectorStore: {
3722
3757
  provider: ((_b = userConfig.vectorStore) == null ? void 0 : _b.provider) || DEFAULT_MEMORY_CONFIG.vectorStore.provider,
3723
3758
  config: (() => {
3724
- var _a3;
3759
+ var _a3, _b2, _c2;
3725
3760
  const defaultConf = DEFAULT_MEMORY_CONFIG.vectorStore.config;
3726
3761
  const userConf = (_a3 = userConfig.vectorStore) == null ? void 0 : _a3.config;
3762
+ const explicitDimension = (userConf == null ? void 0 : userConf.dimension) || ((_c2 = (_b2 = userConfig.embedder) == null ? void 0 : _b2.config) == null ? void 0 : _c2.embeddingDims) || void 0;
3727
3763
  if ((userConf == null ? void 0 : userConf.client) && typeof userConf.client === "object") {
3728
3764
  return {
3729
3765
  client: userConf.client,
3730
- // Include other fields from userConf if necessary, or omit defaults
3731
3766
  collectionName: userConf.collectionName,
3732
- // Can be undefined
3733
- dimension: userConf.dimension || defaultConf.dimension,
3734
- // Merge dimension
3767
+ dimension: explicitDimension,
3735
3768
  ...userConf
3736
3769
  // Include any other passthrough fields from user
3737
3770
  };
3738
3771
  } else {
3739
3772
  return {
3740
3773
  collectionName: (userConf == null ? void 0 : userConf.collectionName) || defaultConf.collectionName,
3741
- dimension: (userConf == null ? void 0 : userConf.dimension) || defaultConf.dimension,
3774
+ dimension: explicitDimension,
3742
3775
  // Ensure client is not carried over from defaults if not provided by user
3743
3776
  client: void 0,
3744
3777
  // Include other passthrough fields from userConf even if no client
@@ -3767,16 +3800,28 @@ var ConfigManager = class {
3767
3800
  };
3768
3801
  })()
3769
3802
  },
3770
- historyDbPath: userConfig.historyDbPath || DEFAULT_MEMORY_CONFIG.historyDbPath,
3803
+ historyDbPath: userConfig.historyDbPath || ((_e = (_d = userConfig.historyStore) == null ? void 0 : _d.config) == null ? void 0 : _e.historyDbPath) || ((_g = (_f = DEFAULT_MEMORY_CONFIG.historyStore) == null ? void 0 : _f.config) == null ? void 0 : _g.historyDbPath),
3771
3804
  customPrompt: userConfig.customPrompt,
3772
3805
  graphStore: {
3773
3806
  ...DEFAULT_MEMORY_CONFIG.graphStore,
3774
3807
  ...userConfig.graphStore
3775
3808
  },
3776
- historyStore: {
3777
- ...DEFAULT_MEMORY_CONFIG.historyStore,
3778
- ...userConfig.historyStore
3779
- },
3809
+ historyStore: (() => {
3810
+ var _a3, _b2;
3811
+ const defaultHistoryStore = DEFAULT_MEMORY_CONFIG.historyStore;
3812
+ const historyProvider = ((_a3 = userConfig.historyStore) == null ? void 0 : _a3.provider) || defaultHistoryStore.provider;
3813
+ const isSqlite = historyProvider.toLowerCase() === "sqlite";
3814
+ return {
3815
+ ...defaultHistoryStore,
3816
+ ...userConfig.historyStore,
3817
+ provider: historyProvider,
3818
+ config: {
3819
+ ...isSqlite ? defaultHistoryStore.config : {},
3820
+ ...isSqlite && userConfig.historyDbPath ? { historyDbPath: userConfig.historyDbPath } : {},
3821
+ ...(_b2 = userConfig.historyStore) == null ? void 0 : _b2.config
3822
+ }
3823
+ };
3824
+ })(),
3780
3825
  disableHistory: userConfig.disableHistory || DEFAULT_MEMORY_CONFIG.disableHistory,
3781
3826
  enableGraph: userConfig.enableGraph || DEFAULT_MEMORY_CONFIG.enableGraph
3782
3827
  };
@@ -3886,6 +3931,8 @@ Memory Format:
3886
3931
  source -- relationship -- destination
3887
3932
 
3888
3933
  Provide a list of deletion instructions, each specifying the relationship to be deleted.
3934
+
3935
+ Respond in JSON format.
3889
3936
  `;
3890
3937
  function getDeleteMessages(existingMemoriesString, data, userId) {
3891
3938
  return [
@@ -4023,7 +4070,7 @@ var MemoryGraph = class {
4023
4070
  [
4024
4071
  {
4025
4072
  role: "system",
4026
- content: `You are a smart assistant who understands entities and their types in a given text. If user message contains self reference such as 'I', 'me', 'my' etc. then use ${filters["userId"]} as the source entity. Extract all the entities from the text. ***DO NOT*** answer the question itself if the given text is a question.`
4073
+ content: `You are a smart assistant who understands entities and their types in a given text. If user message contains self reference such as 'I', 'me', 'my' etc. then use ${filters["userId"]} as the source entity. Extract all the entities from the text. ***DO NOT*** answer the question itself if the given text is a question. Respond in JSON format.`
4027
4074
  },
4028
4075
  { role: "user", content: data }
4029
4076
  ],
@@ -4521,10 +4568,6 @@ var Memory = class _Memory {
4521
4568
  this.config.embedder.provider,
4522
4569
  this.config.embedder.config
4523
4570
  );
4524
- this.vectorStore = VectorStoreFactory.create(
4525
- this.config.vectorStore.provider,
4526
- this.config.vectorStore.config
4527
- );
4528
4571
  this.llm = LLMFactory.create(
4529
4572
  this.config.llm.provider,
4530
4573
  this.config.llm.config
@@ -4532,16 +4575,10 @@ var Memory = class _Memory {
4532
4575
  if (this.config.disableHistory) {
4533
4576
  this.db = new DummyHistoryManager();
4534
4577
  } else {
4535
- const defaultConfig = {
4536
- provider: "sqlite",
4537
- config: {
4538
- historyDbPath: this.config.historyDbPath || ":memory:"
4539
- }
4540
- };
4541
- this.db = this.config.historyStore && !this.config.disableHistory ? HistoryManagerFactory.create(
4578
+ this.db = HistoryManagerFactory.create(
4542
4579
  this.config.historyStore.provider,
4543
4580
  this.config.historyStore
4544
- ) : HistoryManagerFactory.create("sqlite", defaultConfig);
4581
+ );
4545
4582
  }
4546
4583
  this.collectionName = this.config.vectorStore.config.collectionName;
4547
4584
  this.apiVersion = this.config.version || "v1.0";
@@ -4550,7 +4587,51 @@ var Memory = class _Memory {
4550
4587
  if (this.enableGraph && this.config.graphStore) {
4551
4588
  this.graphMemory = new MemoryGraph(this.config);
4552
4589
  }
4553
- this._initializeTelemetry();
4590
+ this._initPromise = this._autoInitialize().catch((error) => {
4591
+ this._initError = error instanceof Error ? error : new Error(String(error));
4592
+ console.error(this._initError);
4593
+ });
4594
+ }
4595
+ /**
4596
+ * If no explicit dimension was provided, runs a probe embedding to
4597
+ * detect it. Then creates and initializes the vector store.
4598
+ */
4599
+ async _autoInitialize() {
4600
+ if (!this.config.vectorStore.config.dimension) {
4601
+ try {
4602
+ const probe = await this.embedder.embed("dimension probe");
4603
+ this.config.vectorStore.config.dimension = probe.length;
4604
+ } catch (error) {
4605
+ throw new Error(
4606
+ `Failed to auto-detect embedding dimension from provider '${this.config.embedder.provider}': ${error.message}. Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.`
4607
+ );
4608
+ }
4609
+ }
4610
+ this.vectorStore = VectorStoreFactory.create(
4611
+ this.config.vectorStore.provider,
4612
+ this.config.vectorStore.config
4613
+ );
4614
+ await this.vectorStore.initialize();
4615
+ await this._initializeTelemetry();
4616
+ }
4617
+ /**
4618
+ * Ensures that auto-initialization (dimension detection + vector store
4619
+ * creation) has completed before any public method proceeds.
4620
+ * If a previous init attempt failed, retries automatically.
4621
+ */
4622
+ async _ensureInitialized() {
4623
+ await this._initPromise;
4624
+ if (this._initError) {
4625
+ this._initError = void 0;
4626
+ this._initPromise = this._autoInitialize().catch((error) => {
4627
+ this._initError = error instanceof Error ? error : new Error(String(error));
4628
+ console.error(this._initError);
4629
+ });
4630
+ await this._initPromise;
4631
+ if (this._initError) {
4632
+ throw this._initError;
4633
+ }
4634
+ }
4554
4635
  }
4555
4636
  async _initializeTelemetry() {
4556
4637
  try {
@@ -4597,6 +4678,7 @@ var Memory = class _Memory {
4597
4678
  }
4598
4679
  }
4599
4680
  async add(messages, config) {
4681
+ await this._ensureInitialized();
4600
4682
  await this._captureEvent("add", {
4601
4683
  message_count: Array.isArray(messages) ? messages.length : 1,
4602
4684
  has_metadata: !!config.metadata,
@@ -4783,6 +4865,7 @@ ${parsedMessages}`
4783
4865
  return results;
4784
4866
  }
4785
4867
  async get(memoryId) {
4868
+ await this._ensureInitialized();
4786
4869
  const memory = await this.vectorStore.get(memoryId);
4787
4870
  if (!memory) return null;
4788
4871
  const filters = {
@@ -4815,6 +4898,7 @@ ${parsedMessages}`
4815
4898
  return { ...memoryItem, ...filters };
4816
4899
  }
4817
4900
  async search(query, config) {
4901
+ await this._ensureInitialized();
4818
4902
  await this._captureEvent("search", {
4819
4903
  query_length: query.length,
4820
4904
  limit: config.limit,
@@ -4870,17 +4954,20 @@ ${parsedMessages}`
4870
4954
  };
4871
4955
  }
4872
4956
  async update(memoryId, data) {
4957
+ await this._ensureInitialized();
4873
4958
  await this._captureEvent("update", { memory_id: memoryId });
4874
4959
  const embedding = await this.embedder.embed(data);
4875
4960
  await this.updateMemory(memoryId, data, { [data]: embedding });
4876
4961
  return { message: "Memory updated successfully!" };
4877
4962
  }
4878
4963
  async delete(memoryId) {
4964
+ await this._ensureInitialized();
4879
4965
  await this._captureEvent("delete", { memory_id: memoryId });
4880
4966
  await this.deleteMemory(memoryId);
4881
4967
  return { message: "Memory deleted successfully!" };
4882
4968
  }
4883
4969
  async deleteAll(config) {
4970
+ await this._ensureInitialized();
4884
4971
  await this._captureEvent("delete_all", {
4885
4972
  has_user_id: !!config.userId,
4886
4973
  has_agent_id: !!config.agentId,
@@ -4903,9 +4990,11 @@ ${parsedMessages}`
4903
4990
  return { message: "Memories deleted successfully!" };
4904
4991
  }
4905
4992
  async history(memoryId) {
4993
+ await this._ensureInitialized();
4906
4994
  return this.db.getHistory(memoryId);
4907
4995
  }
4908
4996
  async reset() {
4997
+ await this._ensureInitialized();
4909
4998
  await this._captureEvent("reset");
4910
4999
  await this.db.reset();
4911
5000
  if (this.config.vectorStore.provider.toLowerCase() !== "langchain") {
@@ -4929,18 +5018,19 @@ ${parsedMessages}`
4929
5018
  this.config.embedder.provider,
4930
5019
  this.config.embedder.config
4931
5020
  );
4932
- this.vectorStore = VectorStoreFactory.create(
4933
- this.config.vectorStore.provider,
4934
- this.config.vectorStore.config
4935
- // This will pass the original client instance back
4936
- );
4937
5021
  this.llm = LLMFactory.create(
4938
5022
  this.config.llm.provider,
4939
5023
  this.config.llm.config
4940
5024
  );
4941
- this._initializeTelemetry();
5025
+ this._initError = void 0;
5026
+ this._initPromise = this._autoInitialize().catch((error) => {
5027
+ this._initError = error instanceof Error ? error : new Error(String(error));
5028
+ console.error(this._initError);
5029
+ });
5030
+ await this._initPromise;
4942
5031
  }
4943
5032
  async getAll(config) {
5033
+ await this._ensureInitialized();
4944
5034
  await this._captureEvent("get_all", {
4945
5035
  limit: config.limit,
4946
5036
  has_user_id: !!config.userId,