Not a database. A substrate for intelligence.
CNS stores and reasons over Atoms (facts, entities, rules, programs) and Fibers (typed relations) with co-resident Aspects:
vector[]— multi-space semantics (pgvector/N dims)symbol— AST / Datalog / SMT termstext— canonical and free-form stringsmedia— blobs + typed metadatabelief— confidence, evidence, contradictions, recencyprovenance— signed source chainstape— bitemporal:valid_from,valid_to,observed_at
Learning happens inside the store (resolution, contradiction detection, summarization, belief updates) and is addressable via CQL, a cognition query language blending similarity, structure, time, and executable rules.
cns/
├─ cns_py/ # Python core: CQL executor, graph, demo API, helpers
│ ├─ api/ # FastAPI demo server (/cql, /graph/neighborhood)
│ └─ cql/, graph/, ... # planner, traversal, belief math, etc.
├─ migrations/ # SQL migrations (golang-migrate style)
├─ scripts/ # local dev helpers (bash/ps1)
├─ cns_ui/ # Tauri + TS desktop Explorer (IB Explorer Alpha)
├─ Makefile # see targets below
└─ .env.example # sample config
- Docker + Docker Compose
make- (Optional)
psqlCLI for local poking
Run these from the repo root:
# 1) Start infra
make up
# waits until Postgres is healthy, pgvector ready, CNS API bootsThe make up target will:
- start
postgreswithpgvectorinstalled - run migrations in
migrations/ - seed minimal system rows (builtin spaces, root rules)
- start
cns-apionhttp://localhost:8080
If you prefer it verbose:
docker compose up -d
./scripts/wait-for-db.sh
./scripts/migrate.sh up
./scripts/seed.sh minimal# Check extension + schema
scripts/psql.sh -c "CREATE EXTENSION IF NOT EXISTS vector; SELECT extname FROM pg_extension WHERE extname='vector';"
scripts/psql.sh -c "\dt cns.*"curl -X POST http://localhost:8080/v1/atom \
-H "Content-Type: application/json" \
-d '{
"kind": "entity",
"label": "person",
"text": "Paige Fialho",
"aspects": {
"belief": {"p": 0.94, "source": "seed"},
"tape": {"observed_at": "now"}
}
}'curl -X POST http://localhost:8080/cql -H "Content-Type: application/json" -d '{
"query": "MATCH label=\"FrameworkX\" PREDICATE supports_tls ASOF 2025-01-01T00:00:00Z RETURN EXPLAIN PROVENANCE"
}'Output:
{
"results": [
{
"subject_label": "FrameworkX",
"predicate": "supports_tls",
"object_label": "TLS1.3",
"confidence": 0.958,
"fiber_id": 495,
"observed_at": "2026-01-02T17:54:09.078654+00:00",
"provenance": [
{
"source_id": "demo_seed:fiber:495",
"uri": "https://example.org/demo/tls-policy",
"line_span": null,
"fetched_at": "2026-01-02T17:54:09.077461+00:00",
"hash": "demo-sha256-placeholder"
}
]
}
],
"explain": {
"steps": ["... (execution plan) ..."],
"total_ms": 12.3
}
}Copy the example and adjust:
cp .env.example .env
# minimally set:
# CNS_DB_URL=postgres://cns:cns@localhost:5432/cns?sslmode=disable # pragma: allowlist secret
# CNS_API_PORT=8080
# CNS_VECTOR_DIMS=1536Atoms (cns.atom)
id uuid pkkind text—entity|fact|rule|programlabel text— type name (e.g.,person,company,address)text text— canonical text formsymbol jsonb— AST/terms (nullable)media bytea+media_type text(nullable)vector vector— length =CNS_VECTOR_DIMS(nullable)created_at timestamptzupdated_at timestamptz
Fibers (cns.fiber)
src uuid fk → atom.iddst uuid fk → atom.idrel text— relation type (e.g.,knows,located_in)weight real— soft strengthtape_valid tstzrange— bitemporal validityobserved_at timestamptzprovenance jsonb— signed chainbelief jsonb—{p, evidence[], contradictions[]}
Indices
- GIN on
symbol,provenance - HNSW/ivfflat on
vector - B-tree on
label,(src,rel,dst),observed_at
belief.pin[0,1]; Bayesian update with source reliabilitycontradictions[]carry pointers to conflicting atoms/fiberstape_validuseststzrange(valid_from, valid_to)observed_atanchors when we first saw it (ingest clock)
- Resolution: semantic + symbolic + graph features → merge/same-as fibers
- Contradiction detection: rule-backed diffs over overlapping
tape_valid - Summarization: compress neighborhood →
summaryatoms with provenance - Belief update: scheduled recalculation after new evidence
Run locally:
make jobs # runs all jobs once
make jobs/er # just entity resolutionSimilarity + structure:
MATCH (p:person)-[r:knows]->(q:person)
WHERE sim(p.vector, :$emb("Alex from Jensen-verse")) > 0.75
AND tape_overlaps(r.tape_valid, '2020-01-01', '2024-12-31')
RETURN p, q, r
ORDER BY belief(r).p DESC
LIMIT 25;Executable rule:
RULE likely_duplicate(p, q) :-
label(p)='person' AND label(q)='person'
AND sim(p.vector, q.vector) > 0.92
AND overlap(name(p), name(q)) > 0.8;Time-aware contradiction:
SELECT contradicting_pairs(a1, a2)
FROM atoms a1, atoms a2
WHERE a1.label='address' AND a2.label='address'
AND entity_of(a1)=entity_of(a2)
AND a1.text != a2.text
AND tape_overlap(a1, a2);make up # compose up + migrate + seed + core API (legacy)
make down # stop containers
make logs # tail api + db logs
make migrate/up # apply migrations
make migrate/down # rollback last migration
make seed # load minimal builtin spaces + rules
make dev # hot-reload api (watchexec/nodemon/go-run etc.)
make jobs # run all learning jobs once
make run-api # run FastAPI demo API (CQL + /graph/neighborhood) locally-
Where to run things
- All
makecommands: repo root - SQL pokes:
scripts/psql.sh -c "..."(wrapspsqlwith env) - FastAPI demo API:
make run-api(serves/cqland/graph/neighborhoodonhttp://127.0.0.1:8000) - Desktop Explorer: see
cns_ui/README.mdfor the Tauri-based IB Explorer UI
- All
-
Vector dims must match your embedder. Default
1536(OpenAI-like). ChangeCNS_VECTOR_DIMSand re-migrate if you switch. -
Idempotency: seeds and jobs are idempotent; safe to rerun.
-
Zero-trust provenance: signers/keys recorded in
provenance; verification runs on ingest and prior to merges.
- Dev brings up Postgres without TLS and API with no auth. Please don’t point it at the internet (hi, future you).
- Prod profile: mTLS between API and DB, signed provenance enforcement, audit log on all rule executions, row-level security on tenants.
- CQL planner heuristics v1 (vector + symbolic co-planning)
- Online ER (streaming merges with quarantine)
- Belief math plugin API
- Snapshot/restore of bitemporal slices
- Multi-embedder spaces per aspect
Pre-alpha. Expect breaking changes. If it breaks, you own both halves (kidding… mostly).
Coming Soon!! Once we have something that works, we’ll update that.
This project follows a strict branching strategy:
dev: The active development branch. All feature work, experiments, and PRs targetdev.main: The stable release branch. We only mergedevtomainafter all verification gates (tests, lint, perf) are green.
Submitting Changes:
- Checkout
dev. - Create your feature branch off
dev. - Submit PR to
dev. - After validation,
devis promoted tomain.