Skip to content

feat:add RAG service type — API design & validation#297

Open
tsivaprasad wants to merge 2 commits intomainfrom
PLAT-488-rag-service-api-design-validation
Open

feat:add RAG service type — API design & validation#297
tsivaprasad wants to merge 2 commits intomainfrom
PLAT-488-rag-service-api-design-validation

Conversation

@tsivaprasad
Copy link
Contributor

@tsivaprasad tsivaprasad commented Mar 13, 2026

Summary

This PR adds rag as a supported service type in the Control Plane API, including configuration parsing and validation for RAG pipeline definitions. It serves as the foundation for RAG service support, with instance provisioning to be introduced in a follow-up PR.

Changes

  • Add rag to the service_type enum in the Goa design and regenerate all API/OpenAPI artifacts
  • Introduce RAGServiceConfig struct and ParseRAGServiceConfig with validation covering: required fields (pipelines, name, tables, embedding_llm, rag_llm), provider enums, API key requirements per provider (anthropic/openai/voyage require api_key; ollama does not), and numeric range checks (token_budget, top_n, search.vector_weight)
  • Wire RAG config validation into validateServiceSpec alongside the existing MCP path
  • Add recursive scrubSensitiveConfig helper so nested sensitive keys (e.g. pipelines[].embedding_llm.api_key) are stripped from API read responses
  • Register rag-server:latest in ServiceVersions to enable version compatibility checks
  • Guard GenerateServiceInstanceResources to return a clear "not yet supported" error for non-MCP types

Testing

Unit tests (29 new RAG config tests)

go test ./server/internal/database/... -run TestParseRAG -v

Manual Verification:

  1. Created Cluster
  2. Created a database using the following command:
    restish control-plane-local-1 create-database < ../demo/488/rag_create_db.json
    [rag_create_db.json](https://github.com/user-attachments/files/25973502/rag_create_db.json)

The database create request and the response was returned with HTTP 200 OK.
Verified that no sensitive keys are exposed in the API response.

  1. Database creation fails with the following error because this PR stops at adding the rag service type and does not yet implement instance provisioning.
    host-1-1 | 2:28PM ERR failed to update database error={"error":"failed to execute plan update: failed to get service resources for rag on host-1: failed to generate service instance resources: service type \"rag\" instance generation is not yet supported","kind":"*fmt.wrapError","stack":null}

Checklist

  • Tests added or updated (unit and/or e2e, as needed)

Notes for Reviewers

This PR intentionally does not provision a RAG service instance. Submitting with service_type: "rag" will pass API validation but fail at the workflow layer with "service type "rag" instance generation is not yet supported". This is by design for this ticket.

PLAT-488

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98a04412-8340-43e7-b844-62c30d03618d

📥 Commits

Reviewing files that changed from the base of the PR and between c6a2728 and 3d8b945.

📒 Files selected for processing (2)
  • server/internal/database/rag_service_config.go
  • server/internal/orchestrator/swarm/orchestrator.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/internal/orchestrator/swarm/orchestrator.go

📝 Walkthrough

Walkthrough

Adds RAG service support: API schema accepts "rag"; adds RAG config parsing and validation; introduces recursive sensitive-data scrubbing; extensive RAG config tests; registers a RAG service image and adds an orchestrator guard that errors for non-mcp service types during resource generation.

Changes

Cohort / File(s) Summary
API Schema & Design
api/apiv1/design/database.go
Expanded ServiceSpec.service_type enum from mcp to mcp, rag and updated examples.
API Conversion Layer
server/internal/api/apiv1/convert.go
Added recursive scrub utilities (scrubSensitiveConfig, scrubSensitiveValue) and replaced inline filtering of svc.Config with recursive scrubbing to remove sensitive keys in nested structures.
API Validation Layer
server/internal/api/apiv1/validate.go
Accepted service_type "rag"; switched dispatch to a switch and added validateRAGServiceConfig to validate RAG configs alongside existing MCP validation.
RAG Service Config (impl & validators)
server/internal/database/rag_service_config.go
New typed model and parser ParseRAGServiceConfig plus types (RAGServiceConfig, RAGPipeline, RAGPipelineTable, RAGPipelineLLMConfig, RAGPipelineSearch, RAGDefaults) and validators (validateRAGPipeline, validateRAGTable, validateRAGLLMConfig) enforcing required fields, bounds, uniqueness, provider rules, and unknown-field protection.
RAG Service Tests
server/internal/database/rag_service_config_test.go
Added extensive tests (minimal/full valid cases, provider permutations including Ollama, Anthropic, Voyage, OpenAI, error cases, and helper minimalRAGConfig).
Orchestrator Layer
server/internal/orchestrator/swarm/orchestrator.go, server/internal/orchestrator/swarm/service_images.go
Added an early guard in resource generation to return an error for non-mcp service types; registered a rag service image entry (rag-server:latest).

Poem

🐇 I hopped through enums and nested maps,
I found pipelines, tables, and provider wraps,
I scrubbed secrets softly, deep and light,
Validated tokens, weights, and names just right,
Now RAG joins MCP beneath the moonlight. 🌙

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: adding RAG as a new service type with API design and validation work.
Description check ✅ Passed Description follows the template with all required sections: Summary, Changes, Testing, Checklist, and Notes for Reviewers. All key information is present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch PLAT-488-rag-service-api-design-validation
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.

OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
server/internal/orchestrator/swarm/orchestrator.go (1)

404-425: Consider moving the service type guard before image lookup.

The guard at lines 422-425 runs after GetServiceImage (line 406) and ValidateCompatibility (line 413). Moving the type check earlier would fail faster for unsupported types without unnecessary image operations.

♻️ Optional: Reorder for earlier failure
 func (o *Orchestrator) GenerateServiceInstanceResources(spec *database.ServiceInstanceSpec) (*database.ServiceInstanceResources, error) {
+	// Only MCP service instance generation is currently implemented.
+	if spec.ServiceSpec.ServiceType != "mcp" {
+		return nil, fmt.Errorf("service type %q instance generation is not yet supported", spec.ServiceSpec.ServiceType)
+	}
+
 	// Get service image based on service type and version
 	serviceImage, err := o.serviceVersions.GetServiceImage(spec.ServiceSpec.ServiceType, spec.ServiceSpec.Version)
 	if err != nil {
 		return nil, fmt.Errorf("failed to get service image: %w", err)
 	}
 
 	// Validate compatibility with database version
 	if spec.PgEdgeVersion != nil {
 		if err := serviceImage.ValidateCompatibility(
 			spec.PgEdgeVersion.PostgresVersion,
 			spec.PgEdgeVersion.SpockVersion,
 		); err != nil {
 			return nil, fmt.Errorf("service %q version %q is not compatible with this database: %w",
 				spec.ServiceSpec.ServiceType, spec.ServiceSpec.Version, err)
 		}
 	}
 
-	// Only MCP service instance generation is currently implemented.
-	if spec.ServiceSpec.ServiceType != "mcp" {
-		return nil, fmt.Errorf("service type %q instance generation is not yet supported", spec.ServiceSpec.ServiceType)
-	}
-
 	// Parse the MCP service config from the untyped config map
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/internal/orchestrator/swarm/orchestrator.go` around lines 404 - 425,
In GenerateServiceInstanceResources, check the service type early and return for
unsupported types before calling o.serviceVersions.GetServiceImage or invoking
serviceImage.ValidateCompatibility; specifically, move the guard that inspects
spec.ServiceSpec.ServiceType (the "mcp" check) to the top of the function
(before GetServiceImage and ValidateCompatibility) so unsupported types
short-circuit and avoid unnecessary image lookup and compatibility validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/internal/orchestrator/swarm/orchestrator.go`:
- Around line 404-425: In GenerateServiceInstanceResources, check the service
type early and return for unsupported types before calling
o.serviceVersions.GetServiceImage or invoking
serviceImage.ValidateCompatibility; specifically, move the guard that inspects
spec.ServiceSpec.ServiceType (the "mcp" check) to the top of the function
(before GetServiceImage and ValidateCompatibility) so unsupported types
short-circuit and avoid unnecessary image lookup and compatibility validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0307bfb7-2ce4-45cf-bc9b-0715cd8a396e

📥 Commits

Reviewing files that changed from the base of the PR and between 673a4a6 and d56897d.

⛔ Files ignored due to path filters (6)
  • api/apiv1/gen/http/control_plane/client/types.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/server/types.go is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.yaml is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.yaml is excluded by !**/gen/**
📒 Files selected for processing (7)
  • api/apiv1/design/database.go
  • server/internal/api/apiv1/convert.go
  • server/internal/api/apiv1/validate.go
  • server/internal/database/rag_service_config.go
  • server/internal/database/rag_service_config_test.go
  • server/internal/orchestrator/swarm/orchestrator.go
  • server/internal/orchestrator/swarm/service_images.go

@tsivaprasad tsivaprasad force-pushed the PLAT-488-rag-service-api-design-validation branch from d56897d to c6a2728 Compare March 16, 2026 10:55
Copy link

@coderabbitai coderabbitai bot left a comment

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 (1)
server/internal/orchestrator/swarm/orchestrator.go (1)

405-425: ⚠️ Potential issue | 🟠 Major

Move unsupported-type gating before image/compatibility checks.

Line 406 and Lines 412-420 run before the unsupported-type guard on Line 423, so non-MCP requests can fail with image/compatibility errors instead of the intended explicit “not yet supported” error.

Proposed fix
 func (o *Orchestrator) GenerateServiceInstanceResources(spec *database.ServiceInstanceSpec) (*database.ServiceInstanceResources, error) {
+	// Only MCP service instance generation is currently implemented.
+	if spec.ServiceSpec.ServiceType != "mcp" {
+		return nil, fmt.Errorf("service type %q instance generation is not yet supported", spec.ServiceSpec.ServiceType)
+	}
+
 	// Get service image based on service type and version
 	serviceImage, err := o.serviceVersions.GetServiceImage(spec.ServiceSpec.ServiceType, spec.ServiceSpec.Version)
 	if err != nil {
 		return nil, fmt.Errorf("failed to get service image: %w", err)
 	}
@@
-	// Only MCP service instance generation is currently implemented.
-	if spec.ServiceSpec.ServiceType != "mcp" {
-		return nil, fmt.Errorf("service type %q instance generation is not yet supported", spec.ServiceSpec.ServiceType)
-	}
-
 	// Parse the MCP service config from the untyped config map
 	mcpConfig, errs := database.ParseMCPServiceConfig(spec.ServiceSpec.Config, false)

As per coding guidelines: "Domain-specific errors should be defined in each package; API errors should be mapped to HTTP status codes via Goa".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/internal/orchestrator/swarm/orchestrator.go` around lines 405 - 425,
Move the unsupported-type guard for spec.ServiceSpec.ServiceType != "mcp" to run
before calling o.serviceVersions.GetServiceImage and before
serviceImage.ValidateCompatibility so non-MCP requests immediately return the
explicit "not yet supported" error instead of hitting image/compatibility paths;
replace the generic fmt.Errorf with a package-level domain-specific error (e.g.,
ErrServiceTypeNotSupported) declared in this package and return that from the
function so the API layer (Goa) can map it to the appropriate HTTP status code.
🧹 Nitpick comments (1)
server/internal/database/rag_service_config.go (1)

72-80: Make unknown-key error ordering deterministic.

When multiple unknown top-level keys are present, map iteration order makes the joined message unstable. Sorting unknownKeys before Join keeps errors deterministic.

Proposed refactor
 	if len(unknownKeys) > 0 {
+		slices.Sort(unknownKeys)
 		errs = append(errs, fmt.Errorf("unknown config key(s): %s", strings.Join(unknownKeys, ", ")))
 		return nil, errs
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/internal/database/rag_service_config.go` around lines 72 - 80, The
unknownKeys slice collected from the config map should be sorted to make the
error message deterministic; locate the block that builds unknownKeys
(referencing ragKnownTopLevelKeys and the local variable unknownKeys) and,
before calling strings.Join(unknownKeys, ", "), call sort.Strings(unknownKeys)
(and add an import for "sort" if missing) so the appended error message produced
for errs is stable across runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@server/internal/orchestrator/swarm/orchestrator.go`:
- Around line 405-425: Move the unsupported-type guard for
spec.ServiceSpec.ServiceType != "mcp" to run before calling
o.serviceVersions.GetServiceImage and before serviceImage.ValidateCompatibility
so non-MCP requests immediately return the explicit "not yet supported" error
instead of hitting image/compatibility paths; replace the generic fmt.Errorf
with a package-level domain-specific error (e.g., ErrServiceTypeNotSupported)
declared in this package and return that from the function so the API layer
(Goa) can map it to the appropriate HTTP status code.

---

Nitpick comments:
In `@server/internal/database/rag_service_config.go`:
- Around line 72-80: The unknownKeys slice collected from the config map should
be sorted to make the error message deterministic; locate the block that builds
unknownKeys (referencing ragKnownTopLevelKeys and the local variable
unknownKeys) and, before calling strings.Join(unknownKeys, ", "), call
sort.Strings(unknownKeys) (and add an import for "sort" if missing) so the
appended error message produced for errs is stable across runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d49275b6-5f8a-439c-baaf-91097adc1a04

📥 Commits

Reviewing files that changed from the base of the PR and between d56897d and c6a2728.

⛔ Files ignored due to path filters (6)
  • api/apiv1/gen/http/control_plane/client/types.go is excluded by !**/gen/**
  • api/apiv1/gen/http/control_plane/server/types.go is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi.yaml is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.json is excluded by !**/gen/**
  • api/apiv1/gen/http/openapi3.yaml is excluded by !**/gen/**
📒 Files selected for processing (7)
  • api/apiv1/design/database.go
  • server/internal/api/apiv1/convert.go
  • server/internal/api/apiv1/validate.go
  • server/internal/database/rag_service_config.go
  • server/internal/database/rag_service_config_test.go
  • server/internal/orchestrator/swarm/orchestrator.go
  • server/internal/orchestrator/swarm/service_images.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • api/apiv1/design/database.go
  • server/internal/orchestrator/swarm/service_images.go
  • server/internal/api/apiv1/convert.go

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