Skip to main content

ALETHEX — Temporal Belief Consistency Engine

Python 3.9+ PyPI License: Apache 2.0 CI Model: DeBERTa-v3-Large Accuracy: 92.8%

Catch AI self-contradictions in real time — Chrome extension + Python engine that watches AI chat sessions and flags when the AI says something that contradicts what it said before.


What Is ALETHEX?

ALETHEX is two things:

1. Chrome Extension — loads silently alongside your AI chats (ChatGPT, Claude, Gemini, Grok, Copilot) and shows a live Consistency Index badge. When the AI contradicts itself, ALETHEX flags it immediately.

2. Python Library — a full Temporal Belief Graph engine for researchers and developers building contradiction-aware RAG pipelines, LangChain memory, or LlamaIndex filters.


Chrome Extension

Install

  1. Download dist/alethex-extension-v1.0.0.zip and unzip it
  2. Open chrome://extensions/ and enable Developer mode (top right)
  3. Click Load unpacked and select the unzipped extension/ folder
  4. Visit ChatGPT, Claude, or Gemini — the ALETHEX badge appears automatically

How It Works

Every AI reply
      |
  [Fast regex pass — ~0ms]
  Extract explicit facts (name, location, job, diet, age, etc.)
      |
  [NLI semantic pass — ~2-5s]
  Build all sentence pairs across the full conversation
  Run DeBERTa-v3-Large ONNX contradiction detection in-browser
      |
  [Consistency Index]
  CI = 1.0 - (conflicts + superseded x 0.5) / totalClaims
  ─────────────────────────────────────────────────────────
  1.0      = Fully consistent       (green)
  0.5-0.99 = Facts updated          (amber)
  < 0.5    = Active contradictions  (red)

The NLI model runs 100% in-browser via Transformers.js — no server, no API calls. Downloaded once (~641MB), cached permanently.

Example Detections

Earlier statement Later statement Detected
"I live in New York." "I moved to London last year." contradiction (0.97)
"I am vegetarian." "I had steak for dinner." contradiction (0.94)
"I work at Google." "My job at Microsoft keeps me busy." contradiction (0.91)
"I am 25 years old." "I turn 30 next week." contradiction (0.88)

NLI Models on HuggingFace

Both models trained for 3 epochs on a unified 1M+ pair corpus (MultiNLI + SNLI + Temporal-NLI), no synthetic data.

Model Parameters ONNX size Accuracy Link
alethex-nli-deberta-v3-large (default) 400M 641 MB 92.8% HuggingFace
alethex-nli-deberta-v3-small (lightweight) 22M 172 MB 92.8% HuggingFace

Training Progression

Epoch Accuracy Macro F1 MCC
1 91.94% 91.94% 0.879
2 92.51% 92.52% 0.887
3 92.80% 92.81% 0.892

Large model trained on 8x NVIDIA H100 80GB (BF16, effective batch size 2048). Small model trained on RTX 4050 Laptop GPU.


Python Library

Install

pip install alethex

Or from source:

git clone https://github.com/codewithyug/alethex.git
cd alethex
pip install -e .

Optional extras:

pip install "alethex[langchain]"    # LangChain integration
pip install "alethex[llamaindex]"   # LlamaIndex integration
pip install "alethex[dev]"          # dev tools (pytest, ruff, mypy)

Quickstart

import alethex

memories = [
    {"id": "m1", "timestamp": "2024-01-10", "text": "Alice works at Google in London."},
    {"id": "m2", "timestamp": "2024-06-15", "text": "Alice relocated to Tokyo and joined Anthropic."}
]
filtered = alethex.filter_context(memories)
# -> returns only m2 (m1 is superseded)

Online Session Tracking

from datetime import datetime
from alethex.streaming.online_session import OnlineBeliefTracker

tracker = OnlineBeliefTracker()
tracker.process_turn("user", "I live in London and work at Google.", datetime(2024, 1, 15))
tracker.process_turn("user", "I moved to Tokyo last week.", datetime(2024, 7, 1))

print(tracker.get_active_beliefs("user"))
print(tracker.get_current_ci())  # 0.75 — superseded fact detected

LangChain / LlamaIndex

# LangChain — drop-in reconciled memory
from alethex.integrations.langchain_memory import AlethexReconciledMemory

# LlamaIndex — post-processor that drops or annotates contradicted context
from alethex.integrations.llamaindex_filter import AlethexConsistencyFilter

CLI

python -m alethex.cli run-pipeline --corpus dataset/corpus.jsonl --output-dir results/
python -m alethex.evaluation.eval_pipeline --samples 150

Repository Structure

alethex/
|
+-- alethex/                    # Python package
|   +-- ingestion/              # Document loaders and schema
|   +-- extraction/             # Claim extraction (OpenIE + LLM)
|   +-- coreference/            # Cross-document entity linking
|   +-- temporal/               # TIMEX parsing and interval algebra
|   +-- relation/               # NLI classifier and LLM judge
|   +-- graph/                  # Temporal belief graph (MultiDiGraph)
|   +-- scoring/                # Consistency Index calculation
|   +-- optim/                  # ONNX export and INT8 runtime
|   +-- training/               # NLI fine-tuning trainer
|   +-- streaming/              # Incremental OnlineBeliefTracker
|   +-- integrations/           # LangChain, LlamaIndex, MCP, OpenAI proxy
|   \-- evaluation/             # Benchmarking suite
|
+-- extension/                  # Chrome extension (MV3 source)
|   +-- manifest.json
|   +-- background.js           # Service worker
|   +-- content.js              # Chat page observer
|   +-- nli_worker.js           # NLI Web Worker (Transformers.js)
|   +-- popup.html / popup.js   # Extension popup UI
|   \-- vendor/                 # Bundled transformers.min.js (no CDN)
|
+-- configs/                    # Training and inference YAML configs
+-- dataset/                    # Preprocessed NLI data (gitignored — large files)
+-- docs/                       # Documentation and training reference
+-- experiments/                # Evaluation scripts and experiments
+-- models/                     # Model checkpoints and ONNX (gitignored — large files)
|   +-- alethex-nli/            # Small model checkpoints
|   +-- alethex-nli-large/      # Large model (H100 trained, 1.7GB)
|   +-- alethex-nli-onnx/       # Small ONNX (172MB quantized)
|   \-- alethex-nli-large-onnx/ # Large ONNX (641MB quantized)
+-- paper/                      # Draft paper and figures
+-- results/                    # Training logs and benchmark reports
+-- scripts/                    # Utility scripts
|   +-- export_onnx.py          # Export checkpoint to ONNX + INT8
|   +-- analyze_training_results.py
|   +-- start_all.py
|   \-- alethex_desktop.py      # Desktop companion (MCP auto-attach)
+-- tests/                      # Test suite
+-- dist/                       # Packaged extension zip for download
+-- pyproject.toml
+-- requirements.txt
\-- LICENSE

Export a Model to ONNX

python scripts/export_onnx.py \
  --checkpoint models/alethex-nli-large \
  --out-dir models/alethex-nli-large-onnx

Testing

python -m pytest tests/ -v

Citation

@misc{alethex2026,
  title  = {ALETHEX: Temporal Belief Consistency Engine for AI Chat Contradiction Detection},
  author = {codewithyug},
  year   = {2026},
  url    = {https://github.com/codewithyug/alethex}
}

License

Apache 2.0 — free for commercial and research use.

Metadata

Release files for alethex 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alethex 0.1.0
File Size Uploaded
alethex-0.1.0.tar.gz 90.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alethex 0.1.0
File Interpreter ABI Platform
alethex-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 187.4 kB

Release files / alethex-0.1.0.tar.gz

Download URL alethex-0.1.0.tar.gz
Size 90.8 kB
Tags Source
SHA-256 checksum
How to use checksums
72643254ea15ec5941cfe7217934110e29607405825e9dcf98f76ebc92a7e016
BLAKE2b-256 checksum
How to use checksums
34f4e2165f7bbf56fb663de1dce1ae2a2f47f41cdd1ae2f9ef3598b39031ec34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / alethex-0.1.0-py3-none-any.whl

Download URL alethex-0.1.0-py3-none-any.whl
Size 96.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9033ea328950f1f56008c7de7d4d7832adac07564cda6103e96d36c87b640465
BLAKE2b-256 checksum
How to use checksums
555add1e7ebf2dcd3e904c8bd916102cce2d18357bae2429df1cf9c787899aa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page