11_unified_brain

command
v2.59.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 14 Imported by: 0

README

11 · Unified Brain — two live databases, streaming CDC, and reasoning

A complex, multi-source CortexDB application. It merges two live databases into one privacy-safe knowledge graph, keeps both continuously in sync, and reasons over the result — with no LLM and no embedder (deterministic lexical retrieval + SPARQL + RDFS/SHACL).

Postgres (customers, orders)  ─┐  connector desensitize ┐
MySQL    (tickets, free-text)  ┘  (signed plan)          ├─▶ one CortexDB brain
                                                          │
  continuous CDC:  PG logical replication + MySQL binlog ─┘  (both stream concurrently)
                                                          │
  reasoning:  RDFS inference · SPARQL aggregates · SHACL validation

What it demonstrates

  • Dual source → one graph. Customers/orders (Postgres) and support tickets (MySQL) become one knowledge graph: Customer ──placed──▶ Order and Customer ──raised──▶ Ticket.
  • Free-text PII redaction. Ticket bodies contain phone numbers and emails in prose; the connector redacts them in place ([REDACTED:phone], [REDACTED:email]) before indexing — including on the live CDC path.
  • Concurrent streaming CDC. A Postgres logical-replication watcher and a MySQL binlog watcher run at the same time; a live INSERT in either database lands in the brain within milliseconds.
  • RDFS inference. Customer rdfs:subClassOf Party materializes a derived rdf:type Party for every customer.
  • SPARQL aggregate. "Priority customers" = COUNT(paid orders) >= 2 via GROUP BY … HAVING.
  • SHACL validation. A shape requires every Customer to have a city; the demo seeds one customer without a city and the validator catches it.

Run it

docker run --rm -d --name cx_pg -e POSTGRES_PASSWORD=p -p 5432:5432 postgres:16 -c wal_level=logical
docker run --rm -d --name cx_my -e MYSQL_ROOT_PASSWORD=p -e MYSQL_DATABASE=test -p 3306:3306 mysql:8

go run ./examples/11_unified_brain \
  -pg 'postgres://postgres:p@localhost:5432/postgres?sslmode=disable' \
  -my 'root:p@tcp(localhost:3306)/test'

The program seeds both databases (including a publication for Postgres logical replication), so a fresh pair of containers is all you need.

Prerequisites

  • Postgres with wal_level=logical (the -c wal_level=logical flag above).
  • MySQL with ROW binlog + binlog_row_image=FULL (defaults in mysql:8).

No LLM, embedder, or API key — the whole pipeline is deterministic.

Documentation

Overview

Unified support brain — a complex, multi-source CortexDB application.

It unifies TWO live databases into one privacy-safe knowledge graph and keeps them continuously in sync, then reasons over the result:

Postgres (customers, orders)  ─┐  connector desensitize ┐
MySQL    (tickets, free-text)  ┘  (signed plan)          ├─▶ one CortexDB brain
                                                          │
  continuous CDC:  PG logical replication + MySQL binlog ─┘  (both stream concurrently)
                                                          │
  reasoning:  RDFS inference · SPARQL aggregates · SHACL validation

What it demonstrates beyond a basic RAG demo:

  • DUAL SOURCE: customers/orders from Postgres + support tickets from MySQL, merged into a single knowledge graph (Customer ──placed──▶ Order, Customer ──raised──▶ Ticket).
  • FREE-TEXT PII: ticket bodies contain phones/emails in prose; the connector redacts them in place before indexing.
  • STREAMING CDC from BOTH at once: a Postgres logical-replication watcher and a MySQL binlog watcher run concurrently; live INSERT/UPDATE/DELETE in either database flow into the brain within milliseconds.
  • REASONING: RDFS-lite inference materializes derived types; a SPARQL aggregate finds "priority" customers (>=2 paid orders); SHACL validates a data-quality constraint and catches a real gap.

No LLM or embedder required — deterministic lexical retrieval + SPARQL.

Prerequisites: a Postgres with wal_level=logical and a MySQL with ROW binlog (both are the defaults for `postgres:16 -c wal_level=logical` and `mysql:8`).

Usage:

go run ./examples/11_unified_brain \
  -pg  'postgres://postgres:p@localhost:5432/postgres?sslmode=disable' \
  -my  'root:p@tcp(localhost:3306)/test'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL