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.
@@ -3590,6 +3590,16 @@ var SQLiteEventStore = class {
3590
3590
  getDatabase() {
3591
3591
  return this.db;
3592
3592
  }
3593
+ hasTableColumn(tableName, columnName) {
3594
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName))
3595
+ return false;
3596
+ try {
3597
+ const rows = sqliteAll(this.db, `PRAGMA table_info("${tableName}")`, []);
3598
+ return rows.some((row) => row.name === columnName);
3599
+ } catch {
3600
+ return false;
3601
+ }
3602
+ }
3593
3603
  async recordRetrievalTrace(input) {
3594
3604
  await this.initialize();
3595
3605
  const traceId = randomUUID5();
@@ -3655,17 +3665,18 @@ var SQLiteEventStore = class {
3655
3665
  async getRetrievalTraceStats() {
3656
3666
  await this.initialize();
3657
3667
  try {
3668
+ const rewrittenQueryRewriteKindSql = this.hasTableColumn("retrieval_traces", "query_rewrite_kind") ? REWRITTEN_QUERY_REWRITE_KIND_SQL : "0";
3658
3669
  const row = sqliteGet(
3659
3670
  this.db,
3660
3671
  `SELECT
3661
3672
  COUNT(*) as total_queries,
3662
3673
  AVG(candidate_count) as avg_candidate_count,
3663
3674
  AVG(selected_count) as avg_selected_count,
3664
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN 1 ELSE 0 END) as rewritten_queries,
3665
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3666
- SUM(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3667
- AVG(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3668
- AVG(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3675
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN 1 ELSE 0 END) as rewritten_queries,
3676
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3677
+ SUM(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3678
+ AVG(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3679
+ AVG(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3669
3680
  CASE
3670
3681
  WHEN SUM(candidate_count) > 0 THEN (SUM(selected_count) * 1.0 / SUM(candidate_count))
3671
3682
  ELSE 0