Skip to content

LLM-Dev-Ops/ruvector-service

Repository files navigation

Node.js 20 LTS TypeScript Express PostgreSQL Cloud Run

πŸ›‘οΈ Ruvector Service

Enterprise-grade decision engine & vector operations API
Stateless Β· SPARC-compliant Β· Production-hardened

License Coverage Status


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Ruvector Service                          β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Ingest  β”‚  β”‚  Query   β”‚  β”‚ Simulate  β”‚  β”‚   Decisions    β”‚  β”‚
β”‚  β”‚ Handler β”‚  β”‚ Handler  β”‚  β”‚  Handler  β”‚  β”‚  & Approvals   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β”‚            β”‚              β”‚                  β”‚           β”‚
β”‚  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚              Middleware Layer                               β”‚ β”‚
β”‚  β”‚  Validation Β· Correlation Β· Metrics Β· Latency Budget       β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚       β”‚                                               β”‚         β”‚
β”‚  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ VectorClient β”‚                          β”‚  DatabaseClient  β”‚ β”‚
β”‚  β”‚  (RuvVector) β”‚                          β”‚   (PostgreSQL)   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

Feature Description
πŸ”’ Execution Authority HMAC-SHA256 signed execution IDs β€” Ruvector is the sole minting authority
πŸ“Š Decision Events Real-time decision event polling & ingestion for orchestration engines
🧠 Learning Signals Approval learning and feedback assimilation agents with latency budgets
⚑ Circuit Breaker Automatic failure isolation with configurable thresholds and recovery
πŸ“ˆ Prometheus Metrics Full observability with request duration, throughput, and pool gauges
πŸ”„ Graceful Shutdown Connection draining within configurable timeout on SIGTERM/SIGINT
πŸ›‘οΈ Startup Hardening 4-phase boot: env assertions β†’ DB init β†’ storage health β†’ data integrity
🐳 Cloud Run Ready Stateless, single-process, <256 MB baseline, 8080 health-checked

πŸ“‘ API Reference

Health & Monitoring

Method Endpoint Description
GET /health 🟒 Liveness probe with database connectivity check
GET /ready 🟒 Readiness probe with VectorClient dependency check
GET /metrics πŸ“ˆ Prometheus metrics (requests, latency, connections, circuit state)
GET /metadata πŸ“‹ Service metadata and capability discovery

Plans API

Method Endpoint Description
POST /v1/plans Create a new plan
GET /v1/plans List plans (filterable by org_id)
GET /v1/plans/:id Retrieve a plan by ID
DELETE /v1/plans/:id Delete a plan

Deployments API

Method Endpoint Description
POST /v1/deployments Create a deployment record
GET /v1/deployments List deployments (filter by environment, status)
GET /v1/deployments/:id Retrieve a deployment by ID
PUT /v1/deployments/:id Update a deployment
DELETE /v1/deployments/:id Delete a deployment

Decisions & Approvals API

Method Endpoint Description
POST /v1/decisions Store a new decision record
GET /v1/decisions List decisions
GET /v1/decisions/:id Retrieve a decision by ID
POST /decision/approval Process approval event and apply learning

Execution Authority API

Method Endpoint Description
POST /v1/executions/accept πŸ” Synchronous execution acceptance (canonical mint)
GET /v1/executions/:id Retrieve an execution record
GET /v1/executions List executions
POST /v1/executions/validate Validate execution ID + authority signature

Simulations API

Method Endpoint Description
POST /v1/simulations Accept simulation intent and mint execution authority

Decision Events API

Method Endpoint Description
GET /events/decisions πŸ“‘ Poll decision events (cursor-based, supports types, after, limit)
POST /events/decisions πŸ“₯ Ingest decision events from orchestration

Learning Signals API

Method Endpoint Description
POST /learning/learn Approval learning agent (latency-budgeted)
POST /learning/assimilate Feedback assimilation agent (latency-budgeted)
GET /learning/inspect Inspect learning events (read-only)

Legacy Vector Operations

Method Endpoint Description
POST /ingest Ingest a normalized event with vector embedding
POST /query Query vectors with similarity search and filters
POST /simulate Multi-vector similarity search for recommendations
POST /graph Graph operations
POST /predict Run ML predictions

πŸš€ Quick Start

Prerequisites

  • Node.js 20.x LTS or higher
  • PostgreSQL 16+
  • RuvVector backend service

Install

npm install

Configure

cp .env.example .env
# Edit .env with your configuration

Run (Development)

npm run dev

Run (Production)

npm run build
npm start

βš™οΈ Configuration

All configuration is via environment variables. No .env files in production.

Required

Variable Description
EXECUTION_HMAC_SECRET πŸ” HMAC-SHA256 signing secret for execution authority
RUVVECTOR_DB_PASSWORD PostgreSQL password

Database (PostgreSQL)

Variable Default Description
RUVVECTOR_DB_HOST localhost Database hostname
RUVVECTOR_DB_PORT 5432 Database port
RUVVECTOR_DB_NAME ruvector-postgres Database name
RUVVECTOR_DB_USER postgres Database user
RUVVECTOR_DB_PASSWORD β€” Database password
RUVVECTOR_DB_MAX_CONNECTIONS 20 Connection pool size
RUVVECTOR_DB_IDLE_TIMEOUT 30000 Idle timeout (ms)
RUVVECTOR_DB_CONNECTION_TIMEOUT 10000 Connection timeout (ms)
RUVVECTOR_DB_SSL false Enable SSL

RuvVector Backend

Variable Default Description
RUVVECTOR_SERVICE_URL http://localhost:6379 RuvVector service URL
RUVVECTOR_API_KEY β€” API key (optional)
RUVVECTOR_TIMEOUT 30000 Request timeout (ms)
RUVVECTOR_POOL_SIZE 10 Connection pool size

Circuit Breaker

Variable Default Description
CIRCUIT_BREAKER_THRESHOLD 5 Failures before opening
CIRCUIT_BREAKER_TIMEOUT 30000 Open state duration (ms)
CIRCUIT_BREAKER_RESET 60000 Full reset timeout (ms)

Service

Variable Default Description
PORT 3000 HTTP listen port
LOG_LEVEL info Log level (debug, info, warn, error, fatal)
SHUTDOWN_TIMEOUT 30000 Graceful shutdown timeout (ms)
MAX_LATENCY_MS 2000 Learning endpoint latency budget (ms)
METRICS_ENABLED true Enable Prometheus metrics
METRICS_PORT 9090 Metrics port

🐳 Docker

# Build
docker build -t ruvector-service .

# Run
docker run -p 8080:8080 --env-file .env ruvector-service

☁️ Deploy to Cloud Run

gcloud run deploy ruvector-service \
  --source=. \
  --region=us-central1 \
  --port=8080 \
  --memory=256Mi \
  --cpu=1 \
  --max-instances=10 \
  --set-env-vars="NODE_ENV=production,LOG_LEVEL=info,MAX_LATENCY_MS=2000,RUVVECTOR_DB_SSL=true" \
  --set-secrets="RUVVECTOR_DB_HOST=RUVECTOR_DB_HOST:latest,RUVVECTOR_DB_PORT=RUVECTOR_DB_PORT:latest,RUVVECTOR_DB_NAME=RUVECTOR_DB_NAME:latest,RUVVECTOR_DB_USER=RUVECTOR_DB_USER:latest,RUVVECTOR_DB_PASSWORD=RUVECTOR_DB_PASSWORD:latest,EXECUTION_HMAC_SECRET=EXECUTION_HMAC_SECRET:latest" \
  --add-cloudsql-instances=agentics-dev:us-central1:ruvector-postgres \
  --allow-unauthenticated

πŸ§ͺ Testing

# Unit tests
npm test

# Integration tests
npm run test:integration

# Watch mode
npm run test:watch

πŸ“Š Prometheus Metrics

Available at GET /metrics:

Metric Type Description
http_request_duration_seconds Histogram Request latency by endpoint
http_requests_total Counter Total requests by endpoint and status
active_connections Gauge Current active connections
vector_operation_duration_seconds Histogram Vector operation latency
vector_operations_total Counter Total vector operations

πŸ—‚οΈ Project Structure

ruvector-service/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts                # πŸš€ Application entry point & route registration
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── index.ts            # βš™οΈ Environment variable configuration
β”‚   β”œβ”€β”€ handlers/
β”‚   β”‚   β”œβ”€β”€ health.ts           # Health & readiness probes
β”‚   β”‚   β”œβ”€β”€ ingest.ts           # Vector ingestion
β”‚   β”‚   β”œβ”€β”€ query.ts            # Vector querying
β”‚   β”‚   β”œβ”€β”€ simulate.ts         # Similarity simulations
β”‚   β”‚   β”œβ”€β”€ plans.ts            # Plans CRUD
β”‚   β”‚   β”œβ”€β”€ deployments.ts      # Deployments CRUD
β”‚   β”‚   β”œβ”€β”€ decisions.ts        # Decisions API
β”‚   β”‚   β”œβ”€β”€ approvals.ts        # Approval processing
β”‚   β”‚   β”œβ”€β”€ executions.ts       # Execution authority minting
β”‚   β”‚   β”œβ”€β”€ simulations.ts      # Simulation intent acceptance
β”‚   β”‚   β”œβ”€β”€ decisionEvents.ts   # Decision event polling & ingestion
β”‚   β”‚   └── learning.ts         # Learning signal agents
β”‚   β”œβ”€β”€ clients/
β”‚   β”‚   β”œβ”€β”€ VectorClient.ts     # RuvVector backend client
β”‚   β”‚   └── DatabaseClient.ts   # PostgreSQL connection pool
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ validation.ts       # Zod request validation
β”‚   β”‚   β”œβ”€β”€ errorHandler.ts     # Error handling
β”‚   β”‚   └── latencyBudget.ts    # Learning endpoint latency enforcement
β”‚   β”œβ”€β”€ guards/
β”‚   β”‚   └── immutability.ts     # Historical data integrity checks
β”‚   β”œβ”€β”€ startup.ts              # Startup hardening assertions
β”‚   └── utils/
β”‚       β”œβ”€β”€ logger.ts           # Pino structured logging
β”‚       β”œβ”€β”€ metrics.ts          # Prometheus metric definitions
β”‚       └── correlation.ts      # Correlation ID utilities
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/                   # Unit tests
β”‚   └── integration/            # Integration tests
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ deploy.sh               # Deployment script (ruv-cloud)
β”‚   └── deploy-cloudrun.sh      # Deployment script (agentics-dev)
β”œβ”€β”€ Dockerfile                  # Multi-stage production build
β”œβ”€β”€ cloudbuild.yaml             # Google Cloud Build pipeline
β”œβ”€β”€ tsconfig.json               # TypeScript configuration
β”œβ”€β”€ jest.config.js              # Jest test configuration
β”œβ”€β”€ .env.example                # Environment variable reference
└── package.json                # Dependencies and scripts

🚨 Error Response Format

All errors follow a consistent SPARC-compliant structure:

{
  "error": "error_code",
  "message": "Human-readable error message",
  "correlationId": "uuid",
  "details": []
}

πŸ“„ License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages