claude-memory-layer 1.0.19 → 1.0.21

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.
@@ -91,8 +91,8 @@ var ConfigSchema = z.object({
91
91
  }).default({}),
92
92
  embedding: z.object({
93
93
  provider: z.enum(["local", "openai"]).default("local"),
94
- model: z.string().default("Xenova/all-MiniLM-L6-v2"),
95
- openaiModel: z.string().default("text-embedding-3-small"),
94
+ model: z.string().default("jinaai/jina-embeddings-v5-text-nano-text-matching"),
95
+ openaiModel: z.string().default("jinaai/jina-embeddings-v5-text-nano-text-matching"),
96
96
  batchSize: z.number().default(32)
97
97
  }).default({}),
98
98
  retrieval: z.object({
@@ -2183,6 +2183,33 @@ var SQLiteEventStore = class {
2183
2183
  ids
2184
2184
  );
2185
2185
  }
2186
+ /**
2187
+ * Clear embedding outbox (used for embedding model migration)
2188
+ */
2189
+ async clearEmbeddingOutbox() {
2190
+ await this.initialize();
2191
+ sqliteRun(this.db, `DELETE FROM embedding_outbox`);
2192
+ }
2193
+ /**
2194
+ * Count total events
2195
+ */
2196
+ async countEvents() {
2197
+ await this.initialize();
2198
+ const row = sqliteGet(this.db, `SELECT COUNT(*) as count FROM events`);
2199
+ return row?.count || 0;
2200
+ }
2201
+ /**
2202
+ * Get events page in timestamp ascending order (stable migration/reindex scans)
2203
+ */
2204
+ async getEventsPage(limit = 1e3, offset = 0) {
2205
+ await this.initialize();
2206
+ const rows = sqliteAll(
2207
+ this.db,
2208
+ `SELECT * FROM events ORDER BY timestamp ASC LIMIT ? OFFSET ?`,
2209
+ [limit, offset]
2210
+ );
2211
+ return rows.map(this.rowToEvent);
2212
+ }
2186
2213
  /**
2187
2214
  * Mark outbox items as failed
2188
2215
  */
@@ -3940,6 +3967,23 @@ var VectorStore = class {
3940
3967
  const result = await this.table.countRows();
3941
3968
  return result;
3942
3969
  }
3970
+ /**
3971
+ * Clear all vectors (used for embedding model migration)
3972
+ */
3973
+ async clearAll() {
3974
+ await this.initialize();
3975
+ if (!this.db)
3976
+ return;
3977
+ try {
3978
+ if (typeof this.db.dropTable === "function") {
3979
+ await this.db.dropTable(this.tableName);
3980
+ } else if (typeof this.db.drop_table === "function") {
3981
+ await this.db.drop_table(this.tableName);
3982
+ }
3983
+ } catch {
3984
+ }
3985
+ this.table = null;
3986
+ }
3943
3987
  /**
3944
3988
  * Check if vector exists for event
3945
3989
  */
@@ -3952,13 +3996,15 @@ var VectorStore = class {
3952
3996
  };
3953
3997
 
3954
3998
  // src/core/embedder.ts
3955
- import { pipeline } from "@xenova/transformers";
3999
+ import { pipeline } from "@huggingface/transformers";
3956
4000
  var Embedder = class {
3957
4001
  pipeline = null;
3958
4002
  modelName;
4003
+ activeModelName;
3959
4004
  initialized = false;
3960
- constructor(modelName = "Xenova/all-MiniLM-L6-v2") {
4005
+ constructor(modelName = "jinaai/jina-embeddings-v5-text-nano-text-matching") {
3961
4006
  this.modelName = modelName;
4007
+ this.activeModelName = modelName;
3962
4008
  }
3963
4009
  /**
3964
4010
  * Initialize the embedding pipeline
@@ -3966,8 +4012,21 @@ var Embedder = class {
3966
4012
  async initialize() {
3967
4013
  if (this.initialized)
3968
4014
  return;
3969
- this.pipeline = await pipeline("feature-extraction", this.modelName);
3970
- this.initialized = true;
4015
+ try {
4016
+ this.pipeline = await pipeline("feature-extraction", this.modelName);
4017
+ this.activeModelName = this.modelName;
4018
+ this.initialized = true;
4019
+ return;
4020
+ } catch (primaryError) {
4021
+ const fallbackModel = process.env.CLAUDE_MEMORY_EMBEDDING_FALLBACK_MODEL || "onnx-community/embeddinggemma-300m-ONNX";
4022
+ if (fallbackModel === this.modelName) {
4023
+ throw primaryError;
4024
+ }
4025
+ console.warn(`[Embedder] Primary model failed (${this.modelName}). Falling back to ${fallbackModel}`);
4026
+ this.pipeline = await pipeline("feature-extraction", fallbackModel);
4027
+ this.activeModelName = fallbackModel;
4028
+ this.initialized = true;
4029
+ }
3971
4030
  }
3972
4031
  /**
3973
4032
  * Generate embedding for a single text
@@ -3984,7 +4043,7 @@ var Embedder = class {
3984
4043
  const vector = Array.from(output.data);
3985
4044
  return {
3986
4045
  vector,
3987
- model: this.modelName,
4046
+ model: this.activeModelName,
3988
4047
  dimensions: vector.length
3989
4048
  };
3990
4049
  }
@@ -4008,7 +4067,7 @@ var Embedder = class {
4008
4067
  const vector = Array.from(output.data);
4009
4068
  results.push({
4010
4069
  vector,
4011
- model: this.modelName,
4070
+ model: this.activeModelName,
4012
4071
  dimensions: vector.length
4013
4072
  });
4014
4073
  }
@@ -4032,13 +4091,14 @@ var Embedder = class {
4032
4091
  * Get model name
4033
4092
  */
4034
4093
  getModelName() {
4035
- return this.modelName;
4094
+ return this.activeModelName;
4036
4095
  }
4037
4096
  };
4038
4097
  var defaultEmbedder = null;
4039
4098
  function getDefaultEmbedder() {
4099
+ const envModel = process.env.CLAUDE_MEMORY_EMBEDDING_MODEL;
4040
4100
  if (!defaultEmbedder) {
4041
- defaultEmbedder = new Embedder();
4101
+ defaultEmbedder = new Embedder(envModel || void 0);
4042
4102
  }
4043
4103
  return defaultEmbedder;
4044
4104
  }