claude-memory-layer 1.0.46 → 1.0.47

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.
@@ -2681,6 +2681,7 @@ var VectorOutbox = class {
2681
2681
  // src/core/retrieval-debug-lanes.ts
2682
2682
  var RETRIEVAL_DEBUG_LANE_NAMES = [
2683
2683
  "raw_event",
2684
+ "session_event",
2684
2685
  "session_summary",
2685
2686
  "graph_path",
2686
2687
  "facet_match"
@@ -9164,6 +9165,7 @@ var Retriever = class {
9164
9165
  }
9165
9166
  async retrieve(query, options = {}) {
9166
9167
  const opts = { ...DEFAULT_OPTIONS, ...options };
9168
+ const retrievalMode = options.retrievalMode ?? ((options.strategy ?? DEFAULT_OPTIONS.strategy) === "auto" ? "session-event-hybrid" : "event");
9167
9169
  const sessionFilter = opts.scope?.sessionId ?? opts.sessionId;
9168
9170
  const fallbackTrace = [];
9169
9171
  const qualityQuery = buildRetrievalQualityQuery(query);
@@ -9194,6 +9196,7 @@ var Retriever = class {
9194
9196
  decayPolicy: opts.decayPolicy,
9195
9197
  intentRewrite: opts.intentRewrite === true,
9196
9198
  graphHop: opts.graphHop,
9199
+ retrievalMode,
9197
9200
  projectScopeMode: opts.projectScopeMode,
9198
9201
  projectHash: opts.projectHash,
9199
9202
  allowedProjectHashes: opts.allowedProjectHashes,
@@ -9212,6 +9215,7 @@ var Retriever = class {
9212
9215
  rerankWeights: opts.rerankWeights,
9213
9216
  decayPolicy: opts.decayPolicy,
9214
9217
  graphHop: opts.graphHop,
9218
+ retrievalMode,
9215
9219
  projectScopeMode: opts.projectScopeMode,
9216
9220
  projectHash: opts.projectHash,
9217
9221
  allowedProjectHashes: opts.allowedProjectHashes,
@@ -9231,6 +9235,7 @@ var Retriever = class {
9231
9235
  rerankWeights: opts.rerankWeights,
9232
9236
  decayPolicy: opts.decayPolicy,
9233
9237
  graphHop: opts.graphHop,
9238
+ retrievalMode,
9234
9239
  projectScopeMode: opts.projectScopeMode,
9235
9240
  projectHash: opts.projectHash,
9236
9241
  allowedProjectHashes: opts.allowedProjectHashes,
@@ -9251,10 +9256,26 @@ var Retriever = class {
9251
9256
  query,
9252
9257
  minScore: opts.minScore
9253
9258
  });
9259
+ const expandedSummary = retrievalMode === "session-event-hybrid" ? await this.expandSessionEventHybrid(filteredSummary, {
9260
+ query: qualityQuery,
9261
+ currentStateQuery: query,
9262
+ limit: opts.topK * 4
9263
+ }) : filteredSummary;
9264
+ const scopedExpandedSummary = retrievalMode === "session-event-hybrid" ? await this.applyScopeFilters(expandedSummary, {
9265
+ scope: opts.scope,
9266
+ projectScopeMode: opts.projectScopeMode,
9267
+ projectHash: opts.projectHash,
9268
+ allowedProjectHashes: opts.allowedProjectHashes,
9269
+ facets: opts.facets
9270
+ }) : expandedSummary;
9271
+ const finalSummary = retrievalMode === "session-event-hybrid" ? this.applyQualityFilters(scopedExpandedSummary, {
9272
+ query,
9273
+ minScore: opts.minScore
9274
+ }) : scopedExpandedSummary;
9254
9275
  current = {
9255
- results: filteredSummary,
9256
- candidateResults: filteredSummary,
9257
- matchResult: this.matcher.matchSearchResults(filteredSummary, () => 0)
9276
+ results: finalSummary,
9277
+ candidateResults: finalSummary,
9278
+ matchResult: this.matcher.matchSearchResults(finalSummary, () => 0)
9258
9279
  };
9259
9280
  fallbackTrace.push("fallback:summary");
9260
9281
  }
@@ -9340,13 +9361,18 @@ var Retriever = class {
9340
9361
  initialResults = this.mergeResults(initialResults, rewrittenResults, input.topK * 3);
9341
9362
  }
9342
9363
  }
9343
- const expandedResults = input.graphHop?.enabled === false ? initialResults : await this.expandGraphHops(initialResults, {
9364
+ const graphExpandedResults = input.graphHop?.enabled === false ? initialResults : await this.expandGraphHops(initialResults, {
9344
9365
  query,
9345
9366
  queryGraphEnabled: this.queryGraphExpansionEnabled,
9346
9367
  maxHops: clampGraphHops(input.graphHop?.maxHops ?? 1),
9347
9368
  hopPenalty: Math.max(0, input.graphHop?.hopPenalty ?? 0.08),
9348
9369
  limit: input.topK * 4
9349
9370
  });
9371
+ const expandedResults = input.retrievalMode === "session-event-hybrid" ? await this.expandSessionEventHybrid(graphExpandedResults, {
9372
+ query: rerankQuery,
9373
+ currentStateQuery: query,
9374
+ limit: input.topK * 4
9375
+ }) : graphExpandedResults;
9350
9376
  const rerankedResults = input.rerankWithKeyword ? this.rerankByKeywordOverlap(expandedResults, rerankQuery, input.rerankWeights, input.decayPolicy) : expandedResults;
9351
9377
  const filtered = await this.applyScopeFilters(rerankedResults, {
9352
9378
  scope: input.scope,
@@ -9394,6 +9420,47 @@ var Retriever = class {
9394
9420
  }
9395
9421
  return [...byId.values()].sort((a, b) => b.score - a.score).slice(0, limit);
9396
9422
  }
9423
+ async expandSessionEventHybrid(seeds, opts) {
9424
+ if (seeds.length === 0 || opts.limit <= seeds.length) return seeds;
9425
+ const queryTokens = this.tokenize(opts.query);
9426
+ if (queryTokens.length === 0) return seeds;
9427
+ const byId = /* @__PURE__ */ new Map();
9428
+ for (const seed of seeds) byId.set(seed.eventId, seed);
9429
+ const bestSeedBySession = /* @__PURE__ */ new Map();
9430
+ for (const seed of [...seeds].sort((a, b) => b.score - a.score || compareStable(a.eventId, b.eventId))) {
9431
+ if (!seed.sessionId || bestSeedBySession.has(seed.sessionId)) continue;
9432
+ bestSeedBySession.set(seed.sessionId, seed);
9433
+ }
9434
+ const suppressStaleState = isCurrentStateQuery(opts.currentStateQuery);
9435
+ for (const [sessionId, seed] of bestSeedBySession) {
9436
+ const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9437
+ for (const event of [...sessionEvents].sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime())) {
9438
+ if (byId.has(event.id)) continue;
9439
+ if (isLowSignalContextContent(event.content)) continue;
9440
+ if (suppressStaleState && isStaleOrSupersededContent(event.content)) continue;
9441
+ const lexicalScore = this.keywordOverlap(queryTokens, this.tokenize(event.content));
9442
+ if (lexicalScore <= 0) continue;
9443
+ if (shouldApplyTechnicalGuard(opts.query) && !hasTechnicalTermOverlap(opts.query, event.content)) continue;
9444
+ const score = Math.min(0.95, Math.max(0.35, seed.score * 0.72 + lexicalScore * 0.28));
9445
+ const row = withRetrievalLane({
9446
+ id: `session-event-${seed.eventId}-${event.id}`,
9447
+ eventId: event.id,
9448
+ content: event.content,
9449
+ score,
9450
+ sessionId: event.sessionId,
9451
+ eventType: event.eventType,
9452
+ timestamp: event.timestamp.toISOString(),
9453
+ semanticScore: seed.semanticScore ?? seed.score,
9454
+ lexicalScore,
9455
+ recencyScore: seed.recencyScore
9456
+ }, { lane: "session_event", reason: `same_session:${seed.eventId}`, score });
9457
+ byId.set(row.eventId, row);
9458
+ if (byId.size >= opts.limit) break;
9459
+ }
9460
+ if (byId.size >= opts.limit) break;
9461
+ }
9462
+ return [...byId.values()].sort((a, b) => b.score - a.score || compareStable(a.eventId, b.eventId)).slice(0, opts.limit);
9463
+ }
9397
9464
  async expandGraphHops(seeds, opts) {
9398
9465
  const byId = /* @__PURE__ */ new Map();
9399
9466
  for (const s of seeds) byId.set(s.eventId, s);