claude-memory-layer 1.0.34 → 1.0.36

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.
@@ -3692,6 +3692,16 @@ var SQLiteEventStore = class {
3692
3692
  getDatabase() {
3693
3693
  return this.db;
3694
3694
  }
3695
+ hasTableColumn(tableName, columnName) {
3696
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName))
3697
+ return false;
3698
+ try {
3699
+ const rows = sqliteAll(this.db, `PRAGMA table_info("${tableName}")`, []);
3700
+ return rows.some((row) => row.name === columnName);
3701
+ } catch {
3702
+ return false;
3703
+ }
3704
+ }
3695
3705
  async recordRetrievalTrace(input) {
3696
3706
  await this.initialize();
3697
3707
  const traceId = randomUUID5();
@@ -3757,17 +3767,18 @@ var SQLiteEventStore = class {
3757
3767
  async getRetrievalTraceStats() {
3758
3768
  await this.initialize();
3759
3769
  try {
3770
+ const rewrittenQueryRewriteKindSql = this.hasTableColumn("retrieval_traces", "query_rewrite_kind") ? REWRITTEN_QUERY_REWRITE_KIND_SQL : "0";
3760
3771
  const row = sqliteGet(
3761
3772
  this.db,
3762
3773
  `SELECT
3763
3774
  COUNT(*) as total_queries,
3764
3775
  AVG(candidate_count) as avg_candidate_count,
3765
3776
  AVG(selected_count) as avg_selected_count,
3766
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN 1 ELSE 0 END) as rewritten_queries,
3767
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3768
- SUM(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3769
- AVG(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3770
- AVG(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3777
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN 1 ELSE 0 END) as rewritten_queries,
3778
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3779
+ SUM(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3780
+ AVG(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3781
+ AVG(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3771
3782
  CASE
3772
3783
  WHEN SUM(candidate_count) > 0 THEN (SUM(selected_count) * 1.0 / SUM(candidate_count))
3773
3784
  ELSE 0