Skip to content

samueldanso/neriamind

Repository files navigation

NeriaMind

A living alignment graph for verifiable AI-generated knowledge, built on OriginTrail DKG, powered by MCP & x402.

License: MIT OriginTrail Polkadot

📚 Challenge 1: Grokipedia Vs Wikipedia — Content Comparison and Trust Annotation


📖 Overview

NeriaMind is an AI-powered knowledge alignment system that transforms AI-generated encyclopedia content into verifiable intelligence. As Grokipedia emerges to rival Wikipedia, the need for systematic verification becomes critical.

The system compares Grokipedia entries against Wikipedia articles to detect factual inconsistencies, missing context, AI hallucinations, and bias, then publishes Verifiable Truth Notes (structured JSON-LD Knowledge Assets) to the OriginTrail Decentralized Knowledge Graph. AI agents access verified knowledge through 14 MCP tools, while economic accountability is enforced through x402 micropayments and TRAC/NEURO staking.

Think: X's Community Notes for AI encyclopedias — 8 curated topics analyzed, discrepancies published as verifiable Knowledge Assets on OriginTrail DKG, with real blockchain settlement via x402 and token staking.


🔥 The Problem

AI-generated encyclopedias are proliferating without verification infrastructure:

  • 🤖 Grokipedia claims "fact-checked by Grok" but LLMs hallucinate facts
  • 📝 No provenance for AI-generated claims — users can't trace sources
  • 💸 No economic consequence for misinformation — no accountability
  • 🤷 No systematic verification between AI encyclopedias and human-curated sources

💡 The Solution

NeriaMind is a 3-layer verification system that transforms encyclopedia comparisons into verifiable, economically-accountable knowledge on the DKG.

How It Works:

  1. 📊 Multi-modal fetching — Wikipedia via MediaWiki API, Grokipedia via Puppeteer scraping (text, images, videos)
  2. 🧮 Semantic analysis — OpenAI text-embedding-3-small computes similarity scores between content
  3. 🤖 AI discrepancy detection — GPT-4 identifies factual inconsistencies, missing context, hallucinations, and bias with evidence quotes
  4. 📦 Truth Note generation — Structures findings as JSON-LD Knowledge Assets with provenance
  5. 🔗 DKG publishing — Publishes to OriginTrail DKG, anchored to NeuroWeb blockchain
  6. 💳 x402 payments — Self-hosted facilitator enforces HTTP 402 for premium notes with real blockchain settlement
  7. 🏦 Token staking — In-memory ledger tracks TRAC/NEURO stakes, calculates confidence scores
  8. 🎯 Agent access — 14 MCP tools + 13 REST APIs for AI agents to query and stake on verified knowledge

Key Innovation: End-to-end pipeline from comparison → verification → blockchain publishing → economic accountability.


🌟 Key Features

🤖 Agent Layer

  • Wikipedia Fetcher — MediaWiki API integration with full content retrieval
  • Grokipedia Scraper — Puppeteer-based scraping
  • Semantic Embeddings — OpenAI text-embedding-3-small for similarity scoring
  • Media Analysis — Image/video comparison with metadata extraction
  • GPT-4 Discrepancy Detection — Identifies factual errors, missing context, hallucinations, bias with evidence quotes
  • 14 MCP Tools — Full AI agent integration (fetch, compare, publish, query, stake)
  • 13 REST APIs — HTTP endpoints for programmatic access

🧠 Knowledge Layer

  • 8 Curated Topics — Pre-selected high-divergence topics (Quantum computing, Climate change, AI, Bitcoin, Elon Musk, COVID-19, Renewable energy, Machine learning)
  • JSON-LD Truth Notes — Knowledge Assets with structured discrepancies
  • DKG Publishing — OriginTrail DKG integration
  • SPARQL Queries — Query truth notes via semantic graph queries

🔐 Trust Layer

  • Self-Hosted x402 Facilitator — HTTP 402 protocol implementation with viem
  • Real Blockchain Payments — NeuroWeb settlement
  • Token Staking — In-memory TRAC/NEURO stake ledger
  • Confidence Scoring — Algorithm: min(1, totalStakeValue / 300)
  • Premium Truth Notes — Monetization via x402

🏗️ System Architecture

NeriaMind implements a custom DKG pluginpackages/plugin-neriamind-encyclopedia-compare/ following a 3-layer architecture per OriginTrail DKG design principles:

┌─────────────────────────────────────────────────────────────────┐
│                    USER / AI AGENT (MCP Client)                 │
└────────────────────────┬────────────────────────────────────────┘
                         │
                         ▼
┌─────────────────────────────────────────────────────────────────┐
│              AGENT LAYER (14 MCP Tools + 13 REST APIs)          │
│                                                                  │
│  Wikipedia Fetcher  │  Grokipedia Scraper  │  AI Comparator    │
│  (MediaWiki API)    │     (Puppeteer)      │  (GPT-4 + Embed)  │
│                                                                  │
│  Topic Manager  │  SPARQL Queries  │  Truth Note Publisher     │
└─────────────────────────┬───────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│            KNOWLEDGE LAYER (OriginTrail DKG + NeuroWeb)         │
│                                                                  │
│  JSON-LD Truth Notes  │  DKG Engine   │  NeuroWeb Testnet  │
└─────────────────────────┬───────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│             TRUST LAYER (x402 + Staking + Metrics)              │
│                                                                  │
│  x402 Facilitator    │  Staking Ledger    │  Confidence Scores │
│  • HTTP 402 Protocol │  • TRAC/NEURO      │  • Trust metrics   │
│  • NeuroWeb payments │  • Stake tracking  │  • Verification    │
└─────────────────────────────────────────────────────────────────┘

Data Flow:

Topic → Fetch (Wikipedia + Grokipedia) → AI Analysis (GPT-4 + Embeddings)
   → Truth Note (JSON-LD) → DKG Publish → x402/Staking → Agent Query

See ARCHITECTURE.md for detailed system design.


🛠️ Tech Stack

Category Technology
Engine OriginTrail DKG Node
LLM OpenAI v6.9.1
Models gpt-4o-mini, text-embedding-3-small
Web Scraping Puppeteer v24.30.0, MediaWiki REST API
Web3 viem v2.38.4
Payments x402 v0.6.6
Blockchain NeuroWeb Testnet (Polkadot)

🚀 Getting Started

Prerequisites

  • Node.js 22+ with npm 8+
  • macOS or Linux
  • OpenAI API Key (Get one here)
  • NeuroWeb Testnet Tokens (NEURO + TRAC from faucet)

Installation

1. Install DKG CLI

npm install -g dkg-cli

2. Clone & Setup

git clone https://github.com/samueldanso/neriamind.git
cd neriamind

# Setup DKG Node configuration
dkg-cli setup-config --testnet --neuroweb

This generates:

  • .env file with blockchain keys
  • Operational wallet (needs NEURO for gas)
  • Publishing wallet (needs NEURO + TRAC)

3. Fund Wallets

Important: Fund both wallets before proceeding!

4. Install DKG Node

dkg-cli install

5. Configure Agent

cd apps/agent
npm run build:scripts
npm run script:setup

When prompted, enter:

  • OpenAI API Key: Your API key
  • LLM Model: gpt-4o-mini
  • DKG Environment: testnet

Creates admin user: admin@example.com / admin123

6. Add Facilitator Key (x402 Payments)

Generate a new EVM wallet for the x402 facilitator:

# Option A: Use MetaMask (create new account, export private key)

# Option B: Generate with viem
node -e "const { generatePrivateKey } = require('viem/accounts'); console.log(generatePrivateKey())"

Get wallet address:

node -e "const { privateKeyToAccount } = require('viem/accounts'); console.log(privateKeyToAccount('0xYOUR_KEY').address)"

Fund with NEURO: Send 0.1 NEURO to facilitator address from faucet

Add to environment:

# Add to apps/agent/.env
echo "FACILITATOR_PRIVATE_KEY=0xYourGeneratedKeyHere" >> apps/agent/.env

7. Start Development

cd ../..  # Back to root
npm run dev

Access Points

Once running, access:

Verify Installation

Test the system:

# 1. Check facilitator
curl http://localhost:9200/facilitator/supported

# 2. Test x402 (should return 402 Payment Required for premium UAL)
curl http://localhost:9200/truth-note?ual=did:dkg:otp:20430/0x0000000000000000000000000000000000000001/1

# 3. Check trust metrics
curl http://localhost:9200/trust/metrics?ual=test-ual

# 4. Test staking
curl -X POST http://localhost:9200/trust/stake \
  -H "Content-Type: application/json" \
  -d '{"ual":"test","amount":100,"token":"TRAC","staker":"0xTest"}'

✅ If all return JSON responses, you're ready!


🔗 Deployed Assets

Published Knowledge Assets (NeuroWeb Testnet)

All assets are verifiable on the OriginTrail DKG Explorer.

8 Curated Topics (Published & Finalized)

Topic UAL Explorer Link
Quantum Computing did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396831 View on Explorer
Climate Change did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396832 View on Explorer
Artificial Intelligence did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396833 View on Explorer
Bitcoin did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396834 View on Explorer
Elon Musk did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396835 View on Explorer
COVID-19 Pandemic did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396836 View on Explorer
Renewable Energy did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396837 View on Explorer
Machine Learning did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396838 View on Explorer

Truth Notes (Community Notes)

Topic UAL Type
Artificial Intelligence did:dkg:otp:20430/0xcdb28e93ed340ec10a71bba00a31dbfcf1bd5d37/396820 Public

Key Addresses (NeuroWeb Testnet)

Component Address Purpose
Publishing Wallet 0x5918f2E01751C0A4523881268373D5aa31af Knowledge Asset publishing
Management Key 0x04f148d838Bf4833F7a7D75b8bF34dbc63931290f DKG Node management operations
Operational Key 0xD9DbE8d260Ba74187074C0C358958082Ac8663a0 DKG Node operational tasks
x402 Facilitator 0xe062014f6cdd8802654509885229e98878a8a48e Payment settlement wallet

🔥 PLUGIN SYSTEM ARCHITECTURE

Main Plugin Folder: packages/plugin-neriamind-encyclopedia-compare/

This folder contains the core implementation of the NeriaMind plugin:

  • 14 MCP tools (src/index.ts - 1,461 lines)
  • Wikipedia/Grokipedia fetchers (src/fetchers/)
  • AI-powered comparison engine (src/analysis/)
  • x402 payment protocol (src/x402/) - Self-hosted facilitator
  • Trust layer (apps/agent/src/server/facilitatorPlugin.ts) - Staking + metrics
  • 8 curated topics (src/topics/curated-topics.ts)
  • Truth note builders (src/notes/)

Plugin Documentation: Complete Plugin README

Screenshots: Visual proof of system available in screenshots/ folder


🧩 MCP Tools & API Reference

14 MCP Tools

  1. Content Fetching: neriamind-fetch-wikipedia, neriamind-fetch-grokopedia
  2. Analysis: neriamind-compare-encyclopedia
  3. Truth Notes: neriamind-get-truth-note, neriamind-list-truth-notes
  4. Topics: neriamind-publish-designated-topics, neriamind-fetch-designated-topics, neriamind-process-designated-topics, neriamind-fetch-topic-assets
  5. DKG Queries: neriamind-query-dkg, neriamind-search-topics
  6. Trust Layer: neriamind-pay-truth-note, neriamind-stake-truth-note, neriamind-trust-summary

13 REST API Endpoints

Plugin (/neriamind/*):

  • POST /compare, GET /truth-note, POST /designated-topics/publish, GET /designated-topics, POST /payments/x402/pay, GET /payments/x402/status, GET /trust/stakes

Trust Layer (Root):

  • GET /truth-note?ual={ual}, GET /facilitator/supported, POST /facilitator/verify, POST /facilitator/settle, POST /trust/stake, GET /trust/stakes?ual={ual}, GET /trust/metrics?ual={ual}

Complete API documentation: MCP_API_GUIDE.md


🧪 Testing

Quick Test Commands

# Test Wikipedia fetching
curl -X POST http://localhost:9200/neriamind/compare \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"topic":"Quantum_computing","publish":false}'

# Test x402 flow
curl http://localhost:9200/facilitator/supported
curl http://localhost:9200/truth-note?ual=premium-ual

# Test staking
curl -X POST http://localhost:9200/trust/stake \
  -H "Content-Type: application/json" \
  -d '{"ual":"test","amount":100,"token":"TRAC"}'

# Check metrics
curl http://localhost:9200/trust/metrics?ual=test

Manual Testing via UI

  1. Login: http://localhost:9200 (admin@example.com / admin123)
  2. Publish topics: Use neriamind-publish-designated-topics tool
  3. Compare: Use neriamind-compare-encyclopedia tool
  4. Check metrics: Use neriamind-trust-summary tool

🗄️ Database Management

Drizzle Studio (Visual DB Editor)

npm run drizzle:studio
# Opens https://local.drizzle.studio

User Management

# Create new user
cd apps/agent
npm run script:createUser

# Create API token
npm run script:createToken

📦 Package Management

Adding Dependencies

# Add to specific package
cd packages/your-package
npm install --save package-name

# Add to app
cd apps/agent
npm install --save package-name

🚀 Production Deployment

Build

npm run build            # Build all packages
npm run build:web        # Build web app
npm run build:server     # Build server

Run

# Start all DKG services
dkg-cli start

# Start MCP server
cd apps/agent
NODE_ENV=production node dist/index.js

🔧 Troubleshooting

Common Issues

x402 not working?

# Check facilitator key is set
grep FACILITATOR_PRIVATE_KEY apps/agent/.env

# Check facilitator wallet has NEURO
# Use NeuroWeb explorer: https://neuroweb-testnet.subscan.io/

Truth note publishing fails?

# Check publishing wallet has TRAC + NEURO
dkg-cli status

# Check DKG Engine is running
curl http://localhost:8900/info

MCP tools not appearing?

# Rebuild server
cd apps/agent
npm run build:server

# Restart agent
dkg-cli restart dkg-agent

Clean Install

# Full reset (nuclear option)
rm -rf node_modules package-lock.json
rm -rf apps/agent/node_modules
rm -rf packages/*/node_modules
npm install
npm run build
dkg-cli restart

Get Help


📚 Documentation

External Resources

Resource Link
OriginTrail DKG https://docs.origintrail.io
Model Context Protocol https://modelcontextprotocol.io
NeuroWeb https://neuroweb.ai
Polkadot https://polkadot.network
x402 Protocol https://github.com/coinbase/x402

🤝 Contributing

  1. Follow the existing code structure
  2. Use turbo gen for new packages/apps
  3. Run turbo format check-types lint build before committing
  4. Follow the established patterns in existing plugins

📄 License

This project is part of the DKG ecosystem. See individual package licenses for details.


👥 Team

  • Samuel Danso - Full Stack AI/Blockchain Engineer – me.samueldanso@gmail.com

Built for: OriginTrail × Polkadot × Umanitek Global Hackathon 2025

About

A knowledge alignment system for verifiable AI-generated knowledge

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors