Skip to main content

E-08 Relational Storage

Brick E: Data, RAG, context, memory. French version: E-08-relational-storage

1. Role and responsibilities​

PostgreSQL, schema eai, source of truth of the Control Plane with per tenant RLS.

  • Ordered V### migrations (eai.schema_migrations)
  • RLS via current_setting('app.tenant_id')
  • PITR backups

2. Position in the architecture and interactions​

  • Callers: All Control Plane services.
  • Execution path: Synchronous, transactional.
  • Every interaction goes through the Control Plane API v1 (/v1) behind the API Gateway (D-14).

3. Open source component and developed part​

  • Open source: PostgreSQL 16
  • Developed: Schema, RLS policies, migrations.
  • External integration through an adapter eai/integrations/<system>.py with an in-process fallback when the URL is not configured.

4. Data model​

Tables (schema eai, tenant_id RLS):

  • eai.* (toutes)
  • eai.schema_migrations

Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.

5. Contract​

  • Applied contract: all contracts (persistence)
  • Key fields: tenant_id uuid NOT NULL
  • Validation: POST /v1/contracts/{name}/validate; manifest apply: POST /v1/manifests/apply.

6. API endpoints​

  • GET /readyz

Request GET /readyz:

{}

Response:

{
"status": "ready",
"checks": {
"postgres": "ok",
"migrations": "V059"
}
}

7. SDK examples​

Python:

from enterprise_ai import EnterpriseAI

client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
# accès via les ressources du SDK, jamais direct
client.agents.list()

TypeScript:

import { EnterpriseAI } from "@enterprise-ai/sdk";

const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
await client.agents.list();

Java:

EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
client.agents().list();

Go:

c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
c.Agents.List(ctx)

8. Configuration​

  • Environment variables: EAI_DATABASE_URL
  • Helm values keys: controlPlane.secrets, controlPlane.config.EAI_DATABASE_URL

9. Security controls​

  • SET LOCAL app.tenant_id per transaction
  • Encryption at rest and TLS
  • Every request carries the tenant resolved from the credential; PostgreSQL RLS
  • Every mutation and policy decision writes a hash-chained audit event

10. Observability​

  • Prometheus metrics: pg_stat_database_xact_commit, eai_db_pool_in_use
  • Traces: OpenTelemetry spans with GenAI semantic conventions (gen_ai.operation.name, gen_ai.agent.id, gen_ai.tool.name), attributes eai.tenant_id, eai.run_id, traceparent propagation.
  • Audit actions:

11. FinOps units​

  • Storage and IOPS.
  • Emitted as Usage Event (POST /v1/finops/usage) with tenant, project, agent and run.

12. Failure modes and resilience​

  • Transactional outbox for events
  • Read replica, HA failover
  • Normalized errors (error envelope, message_i18n en/fr)

13. Standalone adoption (client of a client)​

  • PostgreSQL alone is enough for the Control Plane minimal mode.
  • SDK: enterprise_ai.privacy / dlp / knowledge_bases / memory / retention / lineage
  • Minimal deployment: Helm chart with controlPlane.enabled=true and PostgreSQL; disabled external components use their in-process fallback.

14. Acceptance tests​

  1. Query without app.tenant_id returns no row
  2. Cross-tenant access refused
  3. Error returned in fr with Accept-Language: fr