Skip to content

Repository files navigation

Cortex

A value-driven cognitive memory layer for AI agents — for Node.js and the browser.

Cortex is not another vector database. It is the "brain" of agent memory: it decides what to remember, when to remember, when to forget, when to stay silent, and how to resolve contradictions — while ordinary storage-and-retrieval concerns are delegated to pluggable backends.

npm install @agentix-e/cortex-core @agentix-e/cortex-node

Why Cortex

Most memory systems solve the "external hard drive" problem (store embeddings, retrieve by similarity). Cortex solves the "mind" problem:

  • Value-driven memory — decide what is worth remembering by estimated future utility, not raw similarity.
  • Abstention — refuse to answer when no memory is reliable enough (calibrated confidence), instead of forcing a top-k result.
  • Asynchronous consolidation — a background "sleep" process distills episodic memories into semantic knowledge using Hebbian dynamics and an FSRS forgetting curve.
  • Retrieval-as-consolidation — every retrieval strengthens what it touches and credits success/failure back to the responsible memories.
  • Bitemporal facts — every fact carries valid time and system time, making knowledge update, contradiction resolution, and audit native.
  • Provenance & trust — every memory records its source and source trust, and every fact carries both time axes, so origin, supersession and as-of reconstruction are native and auditable. Derivation history is not yet recorded — see the status note below.

Status. cortex-core is a validated library of cognitive contracts and pure algorithms: it is fully unit-tested and holds ≥95% coverage on all four dimensions. It is not yet the engine behind our published LongMemEval-S number — the evaluation harness drives its own memory implementation and consumes only statistics helpers and one vector index from core. cortex-memory now composes core's value gates into a runnable MemorySystem (129 tests, 100% coverage on all four dimensions, passing the harness's conformance suite unmodified), so the cognitive layer is reachable; whether it helps is an A/B that has not been run. Three documented capabilities remain unwired: optimal-transport distillation (sinkhorn, exported but uncalled), TD(λ) credit assignment (not implemented), and fact derivation history (not implemented — Fact carries origin, trust and both time axes, but not which prior facts produced it). See docs/DESIGN-CORTEX-MEMORY.md and docs/AUDIT-CODE-VS-DOCS.md for the full, measured reconciliation.

Packages

Package Role
@agentix-e/cortex-core Contracts + pure algorithms, zero I/O, Node + browser
@agentix-e/cortex-node Embedded SQLite (better-sqlite3) and remote PostgreSQL backends
@agentix-e/cortex-llm Pluggable LLM and embedding adapters (OpenAI-compatible + local transformers.js)
@agentix-e/cortex-memory Composition layer: wires cortex-core's value gates into one conformance-passing MemorySystem
@agentix-e/cortex-eval Scientific evaluation harness (metrics, t-test, ablation) + LongMemEval-style mini benchmark

Quick Start

import {
  BruteForceVectorIndex,
  MemoryGraph,
  decideWrite,
  decideRetrieval,
  defaultValueFunction,
} from '@agentix-e/cortex-core';
import { SqliteStorage } from '@agentix-e/cortex-node';

// 1. Pluggable storage (embedded SQLite).
const storage = new SqliteStorage({ filename: ':memory:' });

// 2. Vector index for similarity search.
const index = new BruteForceVectorIndex();

// 3. Associative memory graph for multi-hop retrieval.
const graph = new MemoryGraph();

// 4. Value-driven write decision.
const candidate = { /* a candidate memory */ };
const decision = decideWrite(candidate, defaultValueFunction, 0.5);
if (decision.write) {
  await storage.put('memories', candidate.id, candidate);
}

// 5. Abstention-aware retrieval.
const retrieved = await index.search(embedding, 10);
const answer = decideRetrieval(retrieved, defaultValueFunction, 0.5);
if (!answer.retrieve) {
  // Stay silent instead of hallucinating.
}

Requirements

  • Node.js >= 22
  • pnpm >= 9

License

MIT

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages