Skip to content

Add semantic-cache package: Valkey-native LLM cache with observability#55

Merged
KIvanow merged 13 commits intomasterfrom
semantic-cache
Mar 22, 2026
Merged

Add semantic-cache package: Valkey-native LLM cache with observability#55
KIvanow merged 13 commits intomasterfrom
semantic-cache

Conversation

@KIvanow
Copy link
Member

@KIvanow KIvanow commented Mar 21, 2026

Standalone semantic cache backed by Valkey Search vector similarity. Includes OpenTelemetry tracing, Prometheus metrics, LangChain and Vercel AI SDK adapters, runnable example with mock embedder, and Jekyll docs page. Handles Valkey Search 1.2 API divergences from


Note

Medium Risk
Introduces a new production-facing package plus an automated npm/GitHub release workflow; risk is mainly around correctness of Valkey Search command usage and publish/versioning automation.

Overview
Adds a new @betterdb/semantic-cache package: a Valkey/Redis-backed semantic cache that stores embeddings in hashes, performs vector KNN lookups via FT.SEARCH, supports TTL + batch invalidation, and emits built-in OpenTelemetry spans and Prometheus metrics.

Includes framework integrations via optional subpath exports (/langchain adapter and /ai middleware), plus unit + integration tests and a runnable example (with a mock embedder + Docker Valkey bundle) to validate end-to-end behavior.

Adds docs pages under docs/packages/*, a CHANGELOG.md/package README.md, updates pnpm-lock.yaml, and introduces a GitHub Actions workflow to publish on semantic-cache-v* tags (build, publish with provenance, create GitHub release, then verify the npm artifact).

Written by Cursor Bugbot for commit ab06c6d. This will update automatically on new commits. Configure here.

Standalone semantic cache backed by Valkey Search vector similarity. Includes OpenTelemetry tracing, Prometheus metrics, LangChain and Vercel AI SDK adapters, runnable example with mock embedder, and Jekyll docs page. Handles Valkey Search 1.2 API divergences from
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: Dimension fallback returns 0 instead of probing embedFn
    • initialize() now probes embedFn whenever FT.INFO dimension parsing returns 0, preventing _dimension from being stuck at 0.
  • ✅ Fixed: iovalkey listed in both dependencies and peerDependencies
    • Removed iovalkey from dependencies and kept it as a peer dependency while adding it to devDependencies for local tests.
  • ✅ Fixed: Development context files with local paths committed
    • Deleted both committed .betterdb_context.md artifacts and added .betterdb_context.md to root .gitignore to prevent recommits.

Create PR

Or push these changes by commenting:

@cursor push d71c559b52
Preview (d71c559b52)
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -70,3 +70,4 @@
 packages/mcp/.mcpregistry_github_token
 .gitignore
 packages/mcp/.mcpregistry_registry_token
+.betterdb_context.md

diff --git a/packages/semantic-cache/.betterdb_context.md b/packages/semantic-cache/.betterdb_context.md
deleted file mode 100644
--- a/packages/semantic-cache/.betterdb_context.md
+++ /dev/null
@@ -1,93 +1,0 @@
-
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/shared/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/shared/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/.github/workflows/mcp-release.yml
-- Scaffolded @betterdb/mcp package with MCP server, REST API integration via agent token auth, and GitHub Actions publishing workflow matching the agent release pattern. (2026-03-12)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/examples/basic/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/examples/basic/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/src/index.ts
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
\ No newline at end of file

diff --git a/packages/semantic-cache/examples/basic/.betterdb_context.md b/packages/semantic-cache/examples/basic/.betterdb_context.md
deleted file mode 100644
--- a/packages/semantic-cache/examples/basic/.betterdb_context.md
+++ /dev/null
@@ -1,57 +1,0 @@
-
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/examples/basic/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/examples/basic/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/examples/basic/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/src/index.ts
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/src/index.ts
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/src/index.ts
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/src/index.ts
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/package.json
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Fixed 5 high/medium/low severity review findings for Valkey Search tree provider: input validation, prefix matching, parallel FT.INFO calls, context-key gating, and formatting. (2026-03-18)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/src/index.ts
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
-
-## File History: /home/kristiyan/projects/valkey/monitor/packages/semantic-cache/README.md
-- Implemented SSH tunnel support for remote Valkey/Redis connections and updated package.json and README.md for improved marketplace discoverability of the feature. (2026-03-04)
-- Removed Docker, rewrote install to compile binaries on user machine, made npm package source-only with config fallback for standalone executables, added validation gate before publish. (2026-03-02)
\ No newline at end of file

diff --git a/packages/semantic-cache/package.json b/packages/semantic-cache/package.json
--- a/packages/semantic-cache/package.json
+++ b/packages/semantic-cache/package.json
@@ -30,13 +30,13 @@
   },
   "dependencies": {
     "@opentelemetry/api": "^1.9.0",
-    "iovalkey": "^0.2.0",
     "prom-client": "^15.1.3"
   },
   "devDependencies": {
     "@langchain/core": ">=0.3.0",
     "@types/node": "^20.0.0",
     "ai": ">=4.0.0",
+    "iovalkey": "^0.2.0",
     "typescript": "^5.4.0",
     "vitest": "^1.6.0"
   },

diff --git a/packages/semantic-cache/src/SemanticCache.ts b/packages/semantic-cache/src/SemanticCache.ts
--- a/packages/semantic-cache/src/SemanticCache.ts
+++ b/packages/semantic-cache/src/SemanticCache.ts
@@ -70,7 +70,9 @@
       try {
         try {
           const info = (await this.client.call('FT.INFO', this.indexName)) as unknown[];
-          this._dimension = this.parseDimensionFromInfo(info);
+          const parsedDimension = this.parseDimensionFromInfo(info);
+          this._dimension =
+            parsedDimension > 0 ? parsedDimension : await this.probeDimension();
           this._initialized = true;
         } catch (err: unknown) {
           const message =
@@ -83,18 +85,8 @@
             message.toLowerCase().includes('no such index') ||
             message.toLowerCase().includes('not found')
           ) {
-            let probeVec: number[];
-            try {
-              probeVec = await this.embedFn('probe');
-            } catch (embedErr) {
-              throw new EmbeddingError(
-                `embedFn failed: ${embedErr instanceof Error ? embedErr.message : String(embedErr)}`,
-                embedErr,
-              );
-            }
+            this._dimension = await this.probeDimension();
 
-            this._dimension = probeVec.length;
-
             try {
               await this.client.call(
                 'FT.CREATE',
@@ -570,6 +562,18 @@
     this._initialized = false;
   }
 
+  private async probeDimension(): Promise<number> {
+    try {
+      const probeVec = await this.embedFn('probe');
+      return probeVec.length;
+    } catch (embedErr) {
+      throw new EmbeddingError(
+        `embedFn failed: ${embedErr instanceof Error ? embedErr.message : String(embedErr)}`,
+        embedErr,
+      );
+    }
+  }
+
   private parseDimensionFromInfo(info: unknown[]): number {
     // FT.INFO returns a flat array: [key, value, key, value, ...]
     // We need to find the 'attributes' section which contains field definitions.
@@ -616,7 +620,7 @@
       }
     }
 
-    // Fallback: if we can't parse dimension from info, call embedFn
+    // Fallback probing happens in initialize() when this returns 0.
     return 0;
   }
 }

diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -376,9 +376,6 @@
       '@opentelemetry/api':
         specifier: ^1.9.0
         version: 1.9.0
-      iovalkey:
-        specifier: ^0.2.0
-        version: 0.2.2
       prom-client:
         specifier: ^15.1.3
         version: 15.1.3
@@ -392,6 +389,9 @@
       ai:
         specifier: '>=4.0.0'
         version: 6.0.134(zod@4.3.5)
+      iovalkey:
+        specifier: ^0.2.0
+        version: 0.2.2
       typescript:
         specifier: ^5.4.0
         version: 5.9.3

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

KIvanow added 4 commits March 22, 2026 00:16
…Fn('probe') when parseDimensionFromInfo returns 0

  - Remove iovalkey from dependencies (keep as peerDependency only)
  - Add _initialized guard to invalidate() and indexInfo()
  - Fix search_latency_ms to exclude embedding time
  - Fix race condition in adapter ensureInitialized() with promise guard
  - Add security note to filter parameter JSDoc
   - Fix CI verify step swallowing publish failures                                                                                                             - Update docs: stale error class names and invalidate return type
  - Add promise guard with failure reset to initialize() and adapter ensureInitialized()
  - Remove stale close() entry and old error class names from CHANGELOG
  - Add ESM import paths to package.json exports map
  - Add security JSDoc to invalidate() filter parameter
  - Reset _initPromise in flush() so initialize() works after flush
  - Record search_latency_ms and embedding_latency_ms on miss spans
  - Add _initialized guard to stats()
  - Document k > 1 as reserved for future use
  - Re-throw EmbeddingError before index-not-found pattern matching
  - Tighten 'not found' match to 'not found in database' to avoid masking unrelated errors
  - Add embedding dimension validation to check()
  - Move _initialized/_initPromise reset to start of flush()
if (!text) return;
await this.cache.store(prompt, text, {
model: this.modelHash(llm_string),
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LangChain adapter stores model hash regardless of filter setting

Low Severity

The update() method always stores model: this.modelHash(llm_string) regardless of the filterByModel setting. When filterByModel is false, lookup() doesn't filter by model, but update() still writes a hashed model tag to every entry. This creates an inconsistency: if a user later enables filterByModel, old entries will only match the model that originally stored them — a silent behavior change that may be surprising.

Fix in Cursor Fix in Web

Extract traced(), embed(), recordStat(), assertInitialized(),
assertDimension(), isIndexNotFoundError(), errMsg() helpers to
replace code that was duplicated 2-6x across methods. Flatten
_doInitialize into detectOrCreateIndex(). Replace magic 1000 with
INVALIDATE_BATCH_SIZE constant. Deduplicate STOP_WORDS in examples.
  - Rename detectOrCreateIndex → ensureIndexAndGetDimension
  - Change embed() to return durationSec (seconds) matching traced()
  - Inline parseScore() at its single call site
  - Clarify traced() JSDoc: callers must not call span.end/setStatus
msg.includes('no such index') ||
msg.includes('not found')
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overly broad error matching silently swallows unrelated errors

High Severity

isIndexNotFoundError checks msg.includes('not found'), which is far too broad. It matches any error containing "not found" — e.g., "ERR command not found" (when the valkey-search module isn't loaded), "module not found", or "Field not found in schema". This causes flush() and ensureIndexAndGetDimension() to silently swallow real errors, treating them as a benign "index doesn't exist" condition. In ensureIndexAndGetDimension, this means the code falls through to re-creating the index instead of surfacing the actual failure. The documented Valkey Search 1.2 message is "Index with name '...' not found in database 0" — the check needs to be more specific, such as requiring both 'index' and 'not found' in the message.

Additional Locations (2)
Fix in Cursor Fix in Web

if (d > 0) dim = d;
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dimension parser iterates by 1 instead of 2

Low Severity

The inner loop in parseDimensionFromInfo uses j++ to iterate over FT.INFO attribute arrays that are structured as flat key-value pairs (and similarly the nested k loop). This treats every element as a potential key, including values from the previous pair. It works today because no known FT.INFO values collide with the checked keys ('type', 'dim', 'index', 'dimensions'), but it's semantically incorrect for key-value pair iteration and fragile against future format changes.

Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@KIvanow KIvanow merged commit caf9607 into master Mar 22, 2026
3 checks passed
@KIvanow KIvanow deleted the semantic-cache branch March 22, 2026 15:04
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant