claude-memory-layer 1.0.34 → 1.0.35

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.
@@ -3578,6 +3578,16 @@ var SQLiteEventStore = class {
3578
3578
  getDatabase() {
3579
3579
  return this.db;
3580
3580
  }
3581
+ hasTableColumn(tableName, columnName) {
3582
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName))
3583
+ return false;
3584
+ try {
3585
+ const rows = sqliteAll(this.db, `PRAGMA table_info("${tableName}")`, []);
3586
+ return rows.some((row) => row.name === columnName);
3587
+ } catch {
3588
+ return false;
3589
+ }
3590
+ }
3581
3591
  async recordRetrievalTrace(input) {
3582
3592
  await this.initialize();
3583
3593
  const traceId = randomUUID5();
@@ -3643,17 +3653,18 @@ var SQLiteEventStore = class {
3643
3653
  async getRetrievalTraceStats() {
3644
3654
  await this.initialize();
3645
3655
  try {
3656
+ const rewrittenQueryRewriteKindSql = this.hasTableColumn("retrieval_traces", "query_rewrite_kind") ? REWRITTEN_QUERY_REWRITE_KIND_SQL : "0";
3646
3657
  const row = sqliteGet(
3647
3658
  this.db,
3648
3659
  `SELECT
3649
3660
  COUNT(*) as total_queries,
3650
3661
  AVG(candidate_count) as avg_candidate_count,
3651
3662
  AVG(selected_count) as avg_selected_count,
3652
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN 1 ELSE 0 END) as rewritten_queries,
3653
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3654
- SUM(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3655
- AVG(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3656
- AVG(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3663
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN 1 ELSE 0 END) as rewritten_queries,
3664
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3665
+ SUM(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3666
+ AVG(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3667
+ AVG(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3657
3668
  CASE
3658
3669
  WHEN SUM(candidate_count) > 0 THEN (SUM(selected_count) * 1.0 / SUM(candidate_count))
3659
3670
  ELSE 0