Skip to content

semantic cache: min similarity + fallback logging - #5742

Closed
kohlivrinda wants to merge 1 commit into
07-30-smenatic_router_budgeting_telemetry_managementfrom
07-31-semantic_cache_min_similarity_fallback_logging
Closed

kohlivrinda wants to merge 1 commit into
07-30-smenatic_router_budgeting_telemetry_managementfrom
07-31-semantic_cache_min_similarity_fallback_logging

Conversation

@kohlivrinda

Copy link
Copy Markdown
Member

Summary

Briefly explain the purpose of this PR and the problem it solves.

Changes

  • What was changed and why
  • Any notable design decisions or trade-offs

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

Describe the steps to validate this change. Include commands and expected outcomes.

# Core/Transports
go version
go test ./...

# UI
cd ui
pnpm i || npm i
pnpm test || npm test
pnpm build || npm run build

If adding new configs or environment variables, document them here.

Screenshots/Recordings

If UI changes, add before/after screenshots or short clips.

Breaking changes

  • Yes
  • No

If yes, describe impact and migration instructions.

Related issues

Link related issues and discussions. Example: Closes #123

Security considerations

Note any security implications (auth, secrets, PII, sandboxing, etc.).

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

kohlivrinda commented Jul 31, 2026 •

Copy link
Copy Markdown
Member Author

@kohlivrinda kohlivrinda mentioned this pull request Jul 31, 2026
18 tasks
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b484c5f-dcbe-4f5d-9403-4d84acbf548e

📥 Commits

Reviewing files that changed from the base of the PR and between 7fb8358 and cca0807.

📒 Files selected for processing (10)
  • framework/configstore/complexityconfig.go
  • framework/configstore/complexityconfig_test.go
  • plugins/governance/complexity/semanticclassifier.go
  • plugins/governance/complexity/semanticclassifier_test.go
  • plugins/governance/main.go
  • plugins/governance/prerequesthookcomplexity_test.go
  • plugins/governance/utils.go
  • transports/config.schema.json
  • ui/app/workspace/complexity-router/page.tsx
  • ui/lib/types/complexityRouter.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • ui/lib/types/complexityRouter.ts
  • plugins/governance/utils.go
  • ui/app/workspace/complexity-router/page.tsx
  • framework/configstore/complexityconfig_test.go
  • plugins/governance/complexity/semanticclassifier_test.go
  • plugins/governance/main.go
  • framework/configstore/complexityconfig.go
  • transports/config.schema.json
  • plugins/governance/prerequesthookcomplexity_test.go
  • plugins/governance/complexity/semanticclassifier.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added an optional minimum similarity threshold for semantic complexity classification.
    • Classification results now include similarity scores, thresholds, and acceptance status.
    • Below-threshold matches use the configured fallback classifier.
    • Routing logs may include matched exemplars for clearer diagnostics.
    • Documented backend-specific similarity scales and fallback behavior.
  • Bug Fixes

    • Added validation for thresholds from 0 inclusive to below 1.
    • Improved logging for unavailable classifiers, timeouts, and rejected matches.
    • Preserved diagnostic details for near-threshold matches.
    • Timeout logs now include the configured duration.

Walkthrough

The change adds a configurable [0, 1) minimum similarity threshold. Classification retains near matches, reports acceptance details, and distinguishes unavailable, rejected, and timed-out results in fallback routing logs.

Changes

Semantic similarity threshold

Layer / File(s) Summary
Configuration contract and validation
framework/configstore/complexityconfig.go, framework/configstore/complexityconfig_test.go, transports/config.schema.json, ui/lib/types/complexityRouter.ts, ui/app/workspace/complexity-router/page.tsx
Adds MinSimilarity serialization, normalization, validation, schema support, UI typing, and boundary-value tests.
Application-level semantic acceptance
plugins/governance/complexity/semanticclassifier.go, plugins/governance/complexity/semanticclassifier_test.go
Queries nonnegative similarity matches and reports the score, configured threshold, and acceptance status. Tests cover borderline scores and deterministic embeddings.
Fallback routing and diagnostics
plugins/governance/main.go, plugins/governance/utils.go, plugins/governance/prerequesthookcomplexity_test.go
Distinguishes semantic rejection, unavailability, and timeout conditions. Routing logs include threshold metrics, timeout duration, or truncated exemplars. The regression test verifies lexical fallback routing.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Mergeability Score: ⚪ Minimal · up to cca08

The current changes introduce no evidenced merge-blocking risk, so the PR is merge-ready after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant RoutingEngine
  participant SemanticClassifier
  participant EmbeddingBackend
  participant FallbackClassifier
  participant RoutingLog

  RoutingEngine->>SemanticClassifier: classify request
  SemanticClassifier->>EmbeddingBackend: query nearest nonnegative-similarity exemplar
  EmbeddingBackend-->>SemanticClassifier: return tier and similarity score
  SemanticClassifier-->>RoutingEngine: return acceptance or timeout result
  alt rejected or timed out
    RoutingEngine->>FallbackClassifier: apply fallback classifier
    RoutingEngine->>RoutingLog: record rejection or timeout diagnostic
  else accepted
    RoutingEngine->>RoutingLog: record matched exemplar
  end
Loading

Possibly related PRs

Suggested reviewers: akshaydeo, impoiler, madhuvod

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements semantic similarity thresholds and fallback logging, but linked issue #123 requires File API support for providers. Link the issue that covers semantic classification changes, or add the required File API support described in issue #123.
Out of Scope Changes check ⚠️ Warning All reviewed changes are unrelated to the linked File API Support objective in issue #123. Update the linked issue to match this PR's semantic classification scope, or remove the unrelated changes.
Description check ⚠️ Warning The description contains only unfilled template text and omits the PR purpose, changes, testing steps, affected areas, and other required details. Replace the placeholder text with implementation details, selected change and area types, test commands and results, breaking-change status, security notes, and checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly summarizes the main changes: adding a semantic similarity threshold and improving fallback logging.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-31-semantic_cache_min_similarity_fallback_logging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from fad423e to 7166123 Compare July 31, 2026 13:39
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 7d1b1d3 to 3767315 Compare July 31, 2026 13:39
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 3767315 to 28e1a04 Compare July 31, 2026 14:20
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 7166123 to 0f9b878 Compare July 31, 2026 14:20
@kohlivrinda
kohlivrinda marked this pull request as ready for review July 31, 2026 14:22
@coderabbitai
coderabbitai Bot requested review from Madhuvod and akshaydeo July 31, 2026 14:23

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/governance/main.go`:
- Around line 753-771: Preserve the rejected semanticResult state through the
fallback decision instead of treating it as unavailable when Fallback() is none.
Update the fallback-disabled handling near the semantic classification branch to
emit a message identifying the rejected result and its below-MinSimilarity
score, while retaining the existing unavailable message only for cases where
classification truly did not produce a result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e1837271-32b1-4b84-897e-8873ae059635

📥 Commits

Reviewing files that changed from the base of the PR and between 28e1a04 and 0f9b878.

📒 Files selected for processing (6)
  • framework/configstore/complexityconfig.go
  • framework/configstore/complexityconfig_test.go
  • plugins/governance/complexity/semanticclassifier.go
  • plugins/governance/complexity/semanticclassifier_test.go
  • plugins/governance/main.go
  • transports/config.schema.json

Comment thread plugins/governance/main.go
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 0f9b878 to 70c8105 Compare July 31, 2026 14:34
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 28e1a04 to 1f63f63 Compare July 31, 2026 14:34
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 70c8105 to 3497493 Compare August 3, 2026 05:22
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 1f63f63 to 05e4036 Compare August 3, 2026 05:22
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 3497493 to a0da8fb Compare August 3, 2026 07:33
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from a0da8fb to d3e61c4 Compare August 3, 2026 08:21
@Madhuvod
Madhuvod force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from c62e576 to f668fe4 Compare August 10, 2026 19:03
@Madhuvod
Madhuvod force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 03ac36e to f7a2a26 Compare August 11, 2026 03:08
@Madhuvod
Madhuvod force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from f668fe4 to 1a0bc54 Compare August 11, 2026 03:08
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 1a0bc54 to b7f532c Compare August 11, 2026 10:44
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from f7a2a26 to 3b2841d Compare August 11, 2026 10:44
@Madhuvod
Madhuvod force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from b7f532c to ded8846 Compare August 11, 2026 12:48
@Madhuvod
Madhuvod force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 3b2841d to 879943d Compare August 11, 2026 12:48
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 879943d to ac97779 Compare August 11, 2026 17:43
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from ded8846 to 5fba23f Compare August 11, 2026 17:43
@Madhuvod
Madhuvod force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from ac97779 to abec8d9 Compare August 11, 2026 19:10
@Madhuvod
Madhuvod force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 5fba23f to 32b5ba8 Compare August 11, 2026 19:10
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from 32b5ba8 to d1121fc Compare August 12, 2026 09:55
@kohlivrinda
kohlivrinda force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch 2 times, most recently from 1c09e09 to bd540fe Compare August 12, 2026 15:04
@kohlivrinda
kohlivrinda force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch from d1121fc to c0f5bdd Compare August 12, 2026 15:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
framework/configstore/complexityconfig.go (1)

222-237: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Serialize Timeout as milliseconds.

Line 222 writes a duration string such as "100ms". Config JSON duration fields must use milliseconds. Emit float64(c.Timeout) / float64(time.Millisecond) as the JSON value. Keep the current dual-format decoder so existing stored strings remain readable.

As per coding guidelines, “Config duration fields serialized as JSON must use milliseconds even when represented as time.Duration in Go.”

Proposed fix
 func (c ComplexitySemanticConfig) MarshalJSON() ([]byte, error) {
 	type alias ComplexitySemanticConfig
-	var timeout string
+	var timeout float64
 	if c.Timeout != 0 {
-		timeout = c.Timeout.String()
+		timeout = float64(c.Timeout) / float64(time.Millisecond)
 	}
 	return json.Marshal(struct {
-		Timeout string `json:"timeout,omitempty"`
+		Timeout float64 `json:"timeout,omitempty"`
 		alias
 	}{
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/configstore/complexityconfig.go` around lines 222 - 237, Update
ComplexitySemanticConfig.MarshalJSON to serialize Timeout as a numeric
millisecond value using the time.Duration-to-milliseconds conversion, rather
than a duration string. Preserve the existing omitempty behavior for zero
Timeout and leave the dual-format decoder unchanged so previously stored strings
remain readable.

Source: Coding guidelines

ui/lib/types/complexityRouter.ts (1)

19-30: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve semantic.fallback when saving the form.

The resolver strips fallback before updateConfig(values), so saving a config with "none" restores the backend default "lexical".

  • Add fallback?: "lexical" | "none" to SemanticConfig.
  • Add fallback: z.enum(["lexical", "none"]).optional() to the semantic schema.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/lib/types/complexityRouter.ts` around lines 19 - 30, Preserve the semantic
fallback value when saving by adding optional fallback support to SemanticConfig
in ui/lib/types/complexityRouter.ts and to the semantic validation schema in
ui/app/workspace/complexity-router/page.tsx (anchor lines 19-30; sibling lines
106-115), restricting values to "lexical" or "none" so the resolver passes it
through to updateConfig(values).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@framework/configstore/complexityconfig.go`:
- Around line 222-237: Update ComplexitySemanticConfig.MarshalJSON to serialize
Timeout as a numeric millisecond value using the time.Duration-to-milliseconds
conversion, rather than a duration string. Preserve the existing omitempty
behavior for zero Timeout and leave the dual-format decoder unchanged so
previously stored strings remain readable.

In `@ui/lib/types/complexityRouter.ts`:
- Around line 19-30: Preserve the semantic fallback value when saving by adding
optional fallback support to SemanticConfig in ui/lib/types/complexityRouter.ts
and to the semantic validation schema in
ui/app/workspace/complexity-router/page.tsx (anchor lines 19-30; sibling lines
106-115), restricting values to "lexical" or "none" so the resolver passes it
through to updateConfig(values).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 111ddd87-fbb1-47d4-959f-8846e1ea2a56

📥 Commits

Reviewing files that changed from the base of the PR and between 5fba23f and c0f5bdd.

📒 Files selected for processing (6)
  • framework/configstore/complexityconfig.go
  • framework/configstore/complexityconfig_test.go
  • plugins/governance/complexity/semanticclassifier.go
  • plugins/governance/complexity/semanticclassifier_test.go
  • ui/app/workspace/complexity-router/page.tsx
  • ui/lib/types/complexityRouter.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • plugins/governance/complexity/semanticclassifier_test.go
  • framework/configstore/complexityconfig_test.go
  • plugins/governance/complexity/semanticclassifier.go

@Madhuvod
Madhuvod force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from bd540fe to 6048a47 Compare August 12, 2026 19:25
@Madhuvod
Madhuvod force-pushed the 07-31-semantic_cache_min_similarity_fallback_logging branch 2 times, most recently from 1f64df7 to e459d95 Compare August 12, 2026 21:16
@Madhuvod
Madhuvod force-pushed the 07-30-smenatic_router_budgeting_telemetry_management branch from 6048a47 to c439781 Compare August 12, 2026 21:16
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant