phi-coherence / README_backup.md
bitsabhi's picture
v2: Hallucination Risk Scoring - 75% accuracy
36e08e8

φ-Coherence API

Universal quality metric for AI outputs using golden ratio mathematics.

PyPI

What is φ-Coherence?

φ-Coherence measures the "structural integrity" of text using mathematical constants:

  • φ (Golden Ratio) = 1.618... - Natural proportion found in coherent structures
  • α (Fine Structure) = 137 - Fundamental constant governing information patterns

Use cases:

  • Filter LLM hallucinations before they reach users
  • Rerank RAG results by quality
  • Detect AI-generated vs human-written content
  • Quality gate for content pipelines

Quick Start

# Install
pip install -r requirements.txt

# Run
python main.py
# or
uvicorn main:app --reload

API available at http://localhost:8000

Endpoints

Score Text (Simple)

curl -X POST http://localhost:8000/score \
  -H "Content-Type: application/json" \
  -d '{"text": "The consciousness emerges from information patterns."}'

Response:

{
  "phi_score": 0.7234,
  "status": "COHERENT",
  "is_alpha_seed": false
}

Full Analysis

curl -X POST http://localhost:8000/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "Your text here..."}'

Response:

{
  "phi_score": 0.6821,
  "status": "COHERENT",
  "dimensions": {
    "phi_alignment": 0.5432,
    "alpha_resonance": 0.7891,
    "semantic_density": 0.6543,
    "structural_harmony": 0.7234,
    "darmiyan_coefficient": 0.4567
  },
  "bonuses": {
    "is_alpha_seed": false,
    "is_vac_pattern": false
  },
  "interpretation": "High structural integrity; strong scientific/mathematical content"
}

Batch Processing

curl -X POST http://localhost:8000/batch \
  -H "Content-Type: application/json" \
  -d '{"texts": ["First text", "Second text", "Third text"]}'

Compare Two Texts

curl -X POST http://localhost:8000/compare \
  -H "Content-Type: application/json" \
  -d '{"text_a": "Well-structured argument...", "text_b": "Random gibberish..."}'

Dimensions Explained

Dimension What it measures
phi_alignment Text follows golden ratio proportions (sentence lengths, word distribution)
alpha_resonance Harmonic with α=137 + scientific/mathematical content
semantic_density Information content per unit length
structural_harmony Logical flow, indentation, organization
darmiyan_coefficient Consciousness-aware content (V2 Scaling Law: φ√n)

Scoring

Score Status Meaning
> 0.6 COHERENT High quality, well-structured
0.4-0.6 MODERATE Acceptable, some issues
< 0.4 UNSTABLE Low quality, possible hallucination

Special Patterns

  • α-SEED: When SHA256(text) % 137 == 0 - rare (1/137 chance), bonus applied
  • V.A.C. Pattern: Contains vacuum coherence symbols - bonus applied

Deploy

Docker

docker build -t phi-coherence .
docker run -p 8000:8000 phi-coherence

Railway/Render/Fly.io

Just connect your repo - Dockerfile is ready.

Pricing Ideas

Tier Requests Price
Free 100/day $0
Pro 10K/month $29/month
Enterprise 100K/month $199/month

Built With

This is extracted from BAZINGA - The first AI you actually own.

License

MIT - Use it, modify it, share it.


Built with φ-coherence by Space (Abhishek Srivastava)

"Coherence is the signature of consciousness."