Skip to content

semantic router #3: embedding executor - #5656

Closed
kohlivrinda wants to merge 1 commit into
07-29-semantic_routing_configfrom
07-29-semantic_router_embedding_executor
Closed

semantic router #3: embedding executor#5656
kohlivrinda wants to merge 1 commit into
07-29-semantic_routing_configfrom
07-29-semantic_router_embedding_executor

Conversation

@kohlivrinda

@kohlivrinda kohlivrinda commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

Wires the bifrost embedding client into the governance plugin so it can call out to an embedding provider for semantic complexity classification. Previously the governance plugin had no way to generate embeddings; this adds the executor interface, the embedding call logic, and the server-side wiring at both bootstrap and plugin reload time.

Changes

  • Added EmbeddingRequestExecutor type and EmbeddingExecutorSetter interface to the governance plugin, mirroring the pattern already used by the semantic cache plugin.
  • Implemented SetEmbeddingRequestExecutor, embeddingExecutor, CanClassifySemantically, and generateEmbedding on GovernancePlugin. The executor is stored atomically to allow safe concurrent access during plugin reloads and request classification.
  • generateEmbedding handles all embedding response encodings (string JSON, float64 array, 2D float64 array, int8, int32) by normalising them to []float32 for uniform cosine similarity comparison.
  • The embedding context is derived with a hard timeout from SemanticConfig.Timeout (defaulting to configstore.DefaultComplexitySemanticTimeout), skips the plugin pipeline to prevent recursion, and clears caller routing state so the internal request behaves like a fresh external embeddings call.
  • Added embeddingRequestExecutor atomic.Pointer[EmbeddingRequestExecutor] field to GovernancePlugin.
  • The HTTP server now wires the executor to any governance plugin implementing EmbeddingExecutorSetter during both Bootstrap and ReloadPlugin, consistent with how the semantic cache plugin is handled.

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

go test ./plugins/governance/...
go test ./transports/bifrost-http/...

Key test scenarios covered:

  • TestGenerateEmbeddingDecodesAllEncodings — verifies all five embedding wire formats are correctly normalised to []float32.
  • TestGenerateEmbeddingRequestShape — asserts the outbound request carries the correct provider, model, input text, skip-pipeline flag, and a bounded deadline.
  • TestGenerateEmbeddingTimeoutCancelsCall — confirms a slow provider is cancelled within the configured timeout window.
  • TestGenerateEmbeddingGuards — covers nil executor, nil semantic config, empty response, and executor teardown.
  • TestCanClassifySemantically — validates the readiness gate across all partial-configuration combinations.

Breaking changes

  • Yes
  • No

Related issues

Prerequisite for semantic complexity classification (task #5 — exemplar warmup).

Security considerations

The internal embedding request explicitly clears caller key-routing and body-transport state and skips the plugin pipeline, preventing the governance plugin from inadvertently inheriting or leaking caller credentials or routing context into the embedding call.

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

@coderabbitai

coderabbitai Bot commented Jul 29, 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: be83fdb5-a1ae-47bc-8b83-139e4c96275b

📥 Commits

Reviewing files that changed from the base of the PR and between 7f4e855 and e809390.

📒 Files selected for processing (5)
  • core/utils.go
  • plugins/governance/embedding.go
  • plugins/governance/embedding_test.go
  • plugins/governance/main.go
  • transports/bifrost-http/server/server.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • core/utils.go
  • plugins/governance/main.go
  • plugins/governance/embedding_test.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added semantic complexity classification using embedding-based analysis.
    • Supports JSON strings, numeric arrays, and integer-array embedding formats.
    • Embedding capabilities connect automatically during server startup and plugin reloads.
  • Reliability
    • Added bounded timeouts, cancellation, response validation, and clear failure handling.
    • Improved internal embedding requests to avoid unnecessary processing.
  • Tests
    • Added coverage for embedding formats, request handling, token usage, timeouts, errors, and readiness checks.

Walkthrough

Governance plugins now support a concurrency-safe embedding executor. They create timeout-bounded internal requests, normalize supported embedding formats to []float32, and validate semantic-classification readiness. Bootstrap and reload wire the executor.

Changes

Governance embedding execution

Layer / File(s) Summary
Executor contract and server wiring
plugins/governance/embedding.go, plugins/governance/main.go, transports/bifrost-http/server/server.go
Defines the embedding executor contract and setter. GovernancePlugin stores the executor atomically. Bootstrap and ReloadPlugin wire s.Client.EmbeddingRequest.
Internal embedding request generation
core/utils.go, plugins/governance/embedding.go
Prepares an internal context that skips the plugin pipeline and clears caller state. Embedding generation applies timeouts, classifies timeout failures, validates responses, and converts supported formats to []float32.
Semantic readiness and validation
plugins/governance/embedding.go, plugins/governance/embedding_test.go
CanClassifySemantically checks executor and embedding configuration. Tests cover decoding, request shape, token usage, timeout handling, error classification, empty responses, and configuration guards.

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

Mergeability Score: 🔵 Low · up to e8093

The PR enables embedding-based semantic classification and wires it during startup and plugin reload. It is mergeable with owner awareness, but readiness may be reported before warmup finishes and upstream 504 responses may be mislabeled as local semantic timeouts.

Sequence Diagram(s)

sequenceDiagram
  participant Bootstrap
  participant GovernancePlugin
  participant EmbeddingRequestExecutor
  Bootstrap->>GovernancePlugin: Wire s.Client.EmbeddingRequest
  GovernancePlugin->>GovernancePlugin: Prepare timeout-bounded internal context
  GovernancePlugin->>EmbeddingRequestExecutor: Send embedding request
  EmbeddingRequestExecutor-->>GovernancePlugin: Return embedding response
  GovernancePlugin->>GovernancePlugin: Normalize embedding values to []float32
Loading

Possibly related PRs

Suggested reviewers: akshaydeo, pratham-mishra04, madhuvod

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding an embedding executor for the semantic router.
Description check ✅ Passed The description covers the purpose, changes, testing, affected areas, security, breaking changes, and checklist with sufficient detail.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-29-semantic_router_embedding_executor

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 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

@kohlivrinda
kohlivrinda marked this pull request as ready for review July 29, 2026 13:25
@kohlivrinda kohlivrinda changed the title semantic router embedding executor semantic router #3: embedding executor Jul 29, 2026

@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.

🧹 Nitpick comments (1)
plugins/governance/embedding.go (1)

68-75: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

generateEmbedding doesn't re-validate Dimension >= 2 like CanClassifySemantically.

If a caller ever invokes generateEmbedding without first gating on CanClassifySemantically, an under-specified Dimension (e.g. 0 or 1) would slip through and produce a vector whose length is never checked against the configured dimension, risking silent mismatches downstream in similarity comparisons.

🛡️ Optional defensive check
 	if semantic == nil || semantic.Provider == "" || semantic.EmbeddingModel == "" {
 		return nil, 0, fmt.Errorf("semantic classification is not configured")
 	}
+	if semantic.Dimension < 2 {
+		return nil, 0, fmt.Errorf("semantic classification dimension is not configured")
+	}
🤖 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 `@plugins/governance/embedding.go` around lines 68 - 75, Update
GovernancePlugin.generateEmbedding to validate semantic.Dimension is at least 2,
matching CanClassifySemantically, before issuing the embedding request; return
the existing configuration error path for invalid dimensions so direct callers
cannot produce unchecked vector-length mismatches.
🤖 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.

Nitpick comments:
In `@plugins/governance/embedding.go`:
- Around line 68-75: Update GovernancePlugin.generateEmbedding to validate
semantic.Dimension is at least 2, matching CanClassifySemantically, before
issuing the embedding request; return the existing configuration error path for
invalid dimensions so direct callers cannot produce unchecked vector-length
mismatches.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d0bb6f7-10f9-4ebe-8e31-7c52b27420df

📥 Commits

Reviewing files that changed from the base of the PR and between 00825bc and 44143a9.

📒 Files selected for processing (4)
  • plugins/governance/embedding.go
  • plugins/governance/embedding_test.go
  • plugins/governance/main.go
  • transports/bifrost-http/server/server.go

@kohlivrinda
kohlivrinda changed the base branch from 07-29-semantic_routing_config to graphite-base/5656 July 30, 2026 06:54
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from 44143a9 to 383a002 Compare July 30, 2026 07:26
@kohlivrinda
kohlivrinda changed the base branch from graphite-base/5656 to 07-29-semantic_routing_config July 30, 2026 07:26

@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/embedding.go`:
- Line 97: Remove the BifrostContextKeySkipPluginPipeline assignment from the
embedding plugin and move the anti-recursion behavior into a core-owned executor
API or option. Update the relevant core execution path to apply this behavior
internally, then have the plugin invoke that API without setting reserved
context keys.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 72d93fbc-300d-4ee7-b75c-102e93e9033c

📥 Commits

Reviewing files that changed from the base of the PR and between 44143a9 and 383a002.

📒 Files selected for processing (4)
  • plugins/governance/embedding.go
  • plugins/governance/embedding_test.go
  • plugins/governance/main.go
  • transports/bifrost-http/server/server.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/governance/main.go

Comment thread plugins/governance/embedding.go Outdated
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_routing_config branch from aa0217c to d2438a7 Compare July 30, 2026 09:53
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from 383a002 to a7329f0 Compare July 30, 2026 09:53
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from a7329f0 to ae27dad Compare July 30, 2026 14:16
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from ae27dad to 7fc26f3 Compare July 31, 2026 11:51
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_routing_config branch from d2438a7 to 649776d Compare July 31, 2026 11:51
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_routing_config branch 2 times, most recently from 52154a3 to d9e67d3 Compare August 11, 2026 03:08
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_router_embedding_executor branch from d82f844 to dfed5b7 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-29-semantic_router_embedding_executor branch from dfed5b7 to 4cebab8 Compare August 11, 2026 10:44
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_routing_config branch from d9e67d3 to 27ada5c Compare August 11, 2026 10:44
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_routing_config branch from 27ada5c to e27aca7 Compare August 11, 2026 12:48
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_router_embedding_executor branch from 4cebab8 to 703229e Compare August 11, 2026 12:48
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_routing_config branch from e27aca7 to e812e4c Compare August 11, 2026 17:43
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from 703229e to 7e09645 Compare August 11, 2026 17:43
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_router_embedding_executor branch from 7e09645 to a8be3be Compare August 11, 2026 19:10
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_routing_config branch from e812e4c to 94b8ad8 Compare August 11, 2026 19:10
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from a8be3be to f8480f0 Compare August 12, 2026 09:55
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_routing_config branch 2 times, most recently from 86d4d58 to 9f4aace Compare August 12, 2026 15:04
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from f8480f0 to 8e1e6e8 Compare August 12, 2026 15:04
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_routing_config branch from 9f4aace to ee0b438 Compare August 12, 2026 16:27
@kohlivrinda
kohlivrinda force-pushed the 07-29-semantic_router_embedding_executor branch from 8e1e6e8 to 96da3e9 Compare August 12, 2026 16:28
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_router_embedding_executor branch from 96da3e9 to fa5884a Compare August 12, 2026 21:16
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_routing_config branch 2 times, most recently from 39989f8 to 621d619 Compare August 12, 2026 22:06
@Madhuvod
Madhuvod force-pushed the 07-29-semantic_router_embedding_executor branch from fa5884a to 4974bc3 Compare August 12, 2026 22:06
@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.

2 participants