Skip to content

kliewerdaniel/SynthInt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 Dynamic Persona Mixture-of-Experts RAG System

[Synthetic Intelligence (Synth-Int) Framework] - A revolutionary, air-gapped Local-First Dynamic Persona Intelligence System that transforms large, heterogeneous corpuses into grounded, attributable, and conversationally explorable intelligence using deterministic generative models.

πŸš€ The Future of AI is Here: Synthetic Intelligence

We are at a paradigm shift in artificial intelligence. Traditional "AI" systems are probabilistic, cloud-dependent, and prone to hallucination. Synthetic Intelligence represents a new engineering discipline - the construction of deterministic, local-first systems where intelligence is not a black box, but an explicit, adjustable, and evolving Persona Lens.

This system implements a Dynamic Persona Mixture-of-Experts Retrieval-Augmented Generation (MoE RAG) architecture that:

  • Separates Intelligence from Identity: Uses quantified persona vectors that constrain model output to specific psychological and methodological profiles
  • Operates Fully Offline: Designed for air-gapped security with zero external API dependencies
  • Maintains Deterministic Outputs: Produces identical results given identical inputs and persona state
  • Features Evolving Personas: Personas adapt through controlled, auditable feedback loops
  • Provides Grounded Intelligence: Minimizes hallucinations through structural constraints and explicit provenance

πŸ“‹ Table of Contents

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Input Query   │───▢│ Entity Constructor│───▢│ Dynamic Graph   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Persona Store  │◀───│ MoE Orchestrator │◀───│ Graph Traversal β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Ollama LLM     │◀───│ Evaluation &     │◀───│ Graph Snapshots β”‚
β”‚  (Local)        β”‚    β”‚ Scoring          β”‚    β”‚ & Persistence   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  1. Entity Constructor Agent: Extracts entities and relationships from input text using NLP and regex patterns
  2. Dynamic Knowledge Graph: Query-scoped graph built on-demand using NetworkX with explicit semantic relationships
  3. Persona Store: Manages persona lifecycle with JSON-based storage and validation
  4. MoE Orchestrator: Coordinates the mixture-of-experts inference cycle with expansion, evaluation, and pruning phases
  5. Persona Traversal: Implements different cognitive strategies (Analytical, Creative, Pragmatic)
  6. Evaluation & Scoring: Multi-criteria scoring system with relevance, consistency, novelty, and grounding
  7. Ollama Interface: Local LLM inference with deterministic configuration
  8. Graph Snapshots: Persistent storage and analysis of graph states

✨ Key Features

🎭 Dynamic Persona System

  • Weighted Persona Lenses: Quantified trait vectors (0.0-1.0) that constrain model behavior
  • Persona Evolution: Bounded update functions with explicit audit trails
  • Lifecycle Management: Active β†’ Stable β†’ Experimental β†’ Pruned progression
  • Multi-Expert Collaboration: Different personas provide diverse perspectives

πŸ”’ Air-Gapped Security

  • Local-First Design: No external API calls or cloud dependencies
  • Deterministic Operation: Reproducible results with fixed seeds
  • Data Sovereignty: All processing occurs on local hardware
  • Model Agnostic: Works with any locally available LLM

🧠 Intelligent Reasoning

  • Graph-Based Knowledge: Explicit relationships between entities
  • Contextual Traversal: Persona-guided navigation through knowledge graphs
  • Multi-Perspective Analysis: Synthesis of diverse expert viewpoints
  • Hallucination Control: Structural constraints and provenance tracking

πŸ“Š Comprehensive Evaluation

  • Multi-Criteria Scoring: Relevance, consistency, novelty, and grounding metrics
  • Performance Tracking: Historical persona performance with success rates
  • Automated Pruning: Threshold-based persona management
  • Quality Assurance: Rigorous validation and scoring frameworks

πŸ“¦ Installation

Prerequisites

  • Python 3.8+
  • Ollama (for local LLM inference)
  • Git

Quick Setup

  1. Clone the repository:

    git clone https://github.com/kliewerdaniel/SynthInt.git
    cd synthint
  2. Run the setup script:

    python setup.py
  3. Start Ollama and pull a model:

    # Start Ollama (in a separate terminal)
    ollama serve
    
    # Pull a model
    ollama pull llama3.2

Manual Installation

  1. Install Python dependencies:

    pip install -r requirements.txt
  2. Install spaCy model (optional, for enhanced entity extraction):

    python -m spacy download en_core_web_sm
  3. Create necessary directories:

    mkdir -p data/personas/{active,stable,experimental,pruned}
    mkdir -p data/graph_snapshots data/results logs

πŸš€ Quick Start

Basic Usage

  1. Create a sample input file:

    {
      "text": "Analyze the impact of renewable energy on global economic systems."
    }
  2. Run the pipeline:

    python scripts/run_pipeline.py --input sample_input.json --create-sample-personas
  3. View results: The system will output detailed results including:

    • Entity extraction results
    • Persona expansion outputs
    • Evaluation scores
    • Final synthesized response

Command Line Options

python scripts/run_pipeline.py --help

Usage: run_pipeline.py [OPTIONS]

Options:
  --input TEXT                    Input text or path to input file
  --config PATH                   Path to configuration directory
  --log-level [DEBUG|INFO|WARNING|ERROR]
                                  Log level
  --log-file PATH                 Path to log file
  --create-sample-personas        Create sample personas for testing
  --dry-run                       Perform a dry run without actual inference
  --help                          Show this message and exit.

πŸ“– Usage Examples

Example 1: Simple Query Analysis

# Create input file
echo '{"text": "What are the ethical implications of AI in healthcare?"}' > healthcare_query.json

# Run with sample personas
python scripts/run_pipeline.py --input healthcare_query.json --create-sample-personas

Example 2: File Input

# Create a text file
echo "Analyze the future of quantum computing and its potential applications." > quantum_query.txt

# Process the file
python scripts/run_pipeline.py --input quantum_query.txt

Example 3: Custom Configuration

# Use custom configuration
python scripts/run_pipeline.py --input query.json --config custom_configs/

Example 4: Dry Run (Testing)

# Test without actual LLM calls
python scripts/run_pipeline.py --input query.json --dry-run

βš™οΈ Configuration

System Configuration (configs/system.yaml)

# Global system parameters
max_iterations: 10              # Maximum iterations for pipeline
batch_size: 32                  # Batch size for processing
log_level: "INFO"              # Logging level
enable_caching: true           # Enable caching
persona_evolution_enabled: true # Enable persona evolution
deterministic_mode: true       # Ensure deterministic outputs
air_gapped_mode: true          # Operate in air-gapped mode

Thresholds Configuration (configs/thresholds.yaml)

# Pruning and promotion thresholds
pruning_threshold: 0.3          # Threshold for pruning personas
promotion_threshold: 0.8        # Threshold for promoting personas
demotion_threshold: 0.5         # Threshold for demoting personas
activation_threshold: 0.6       # Threshold for activating personas

# Performance evaluation weights
relevance_weight: 0.4
consistency_weight: 0.3
novelty_weight: 0.2
grounding_weight: 0.1

# Evolution parameters
max_persona_count: 20
min_persona_count: 5
evolution_rate: 0.1

Ollama Configuration (configs/ollama.yaml)

# Local model configuration
model_name: "llama3.2"
temperature: 0.1
max_tokens: 2000
api_endpoint: "http://localhost:11434"
seed: 42
top_p: 0.9
frequency_penalty: 0.0
presence_penalty: 0.0

# Model selection for different tasks
reasoning_model: "llama3.2"
generation_model: "llama3.2"
evaluation_model: "llama3.2"

🧩 System Components

Persona Schema

Personas are defined using a strict JSON schema with the following structure:

{
  "persona_id": "unique_identifier",
  "name": "Human-readable name",
  "description": "Brief description of persona characteristics",
  "traits": {
    "analytical_rigor": 0.8,
    "creativity": 0.6,
    "practicality": 0.7
  },
  "expertise": ["domain1", "domain2"],
  "activation_cost": 0.3,
  "historical_performance": {
    "total_queries": 0,
    "average_score": 0.0,
    "last_used": null,
    "success_rate": 0.0
  },
  "metadata": {
    "created_at": "2026-01-25T10:00:00Z",
    "updated_at": "2026-01-25T10:00:00Z",
    "version": "1.0",
    "status": "active"
  }
}

Persona Lifecycle

  1. Experimental: Newly created or modified personas being tested
  2. Active: Proven performers participating in inference
  3. Stable: Reliable performers, quick to activate
  4. Pruned: Underperforming personas, archived for potential recovery

Traversal Strategies

The system implements three main traversal strategies:

  1. Analytical: Focuses on logical connections and evidence-based reasoning
  2. Creative: Emphasizes novel connections and lateral thinking
  3. Pragmatic: Prioritizes efficiency and practical outcomes

πŸ§ͺ Testing

Run All Tests

python test_system.py

Test Individual Components

# Test specific components
python -c "from test_system import test_entity_constructor; test_entity_constructor()"
python -c "from test_system import test_persona_store; test_persona_store()"
python -c "from test_system import test_ollama_interface; test_ollama_interface()"

Create Test Report

The test script generates a detailed test_report.json file with system status and component availability.

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes with appropriate tests
  4. Run the test suite: python test_system.py
  5. Commit your changes: git commit -am 'Add feature'
  6. Push to the branch: git push origin feature-name
  7. Create a Pull Request

Development Guidelines

  • Follow PEP 8 style guidelines
  • Include comprehensive docstrings
  • Add tests for new functionality
  • Update documentation for significant changes
  • Ensure backward compatibility

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Ollama for providing excellent local LLM inference
  • NetworkX for robust graph operations
  • spaCy for advanced natural language processing
  • PyYAML and jsonschema for configuration management

πŸ”— Related Work

πŸ“ž Support

For support and questions:

  • Issues: GitHub Issues
  • Documentation: This README and inline code documentation
  • Testing: Run python test_system.py for system validation

🌟 Why This System is Revolutionary

1. Persona as Constraints, Not Prompts

Traditional systems treat personas as text prompts that are concatenated to the input. Our system implements personas as weighted constraint vectors that deterministically shape model behavior:

def _build_persona_prompt(self, persona: Dict[str, Any], query: str, context: str) -> str:
    traits = persona.get('traits', {})
    system_prompt = f"You are a {persona.get('name', 'specialist')} with the following traits: "
    trait_descriptions = []

    for trait_name, trait_value in traits.items():
        trait_descriptions.append(f"{trait_name} ({trait_value:.2f})")

    system_prompt += ", ".join(trait_descriptions) + ". "
    system_prompt += persona.get('description', 'You are an expert in your field.')

    user_prompt = f"Context: {context}\n\nQuery: {query}\n\nPlease provide a response based on the context and your expertise."

    return f"{system_prompt}\n\n{user_prompt}"

2. Query-Scoped Graphs

Unlike persistent knowledge graphs that accumulate noise and become unwieldy, our system builds query-scoped graphs that are constructed fresh for each query. This ensures:

  • Relevance: Only entities and relationships relevant to the current query are included
  • Performance: Graphs remain manageable in size
  • Accuracy: No state pollution from unrelated queries
  • Security: No persistent storage of sensitive relationships

3. Auditable Persona Evolution

Persona evolution follows bounded update functions with explicit audit trails:

def update_persona_performance(self, persona_id: str, score: float) -> bool:
    # Load current persona data
    persona_data = self.load_persona_from_file(persona_file)

    # Update performance metrics
    performance = persona_data['historical_performance']
    performance['total_queries'] += 1
    performance['last_used'] = datetime.utcnow().isoformat() + 'Z'

    # Calculate new average score
    old_avg = performance['average_score']
    total_queries = performance['total_queries']
    new_avg = ((old_avg * (total_queries - 1)) + score) / total_queries
    performance['average_score'] = new_avg

    # Update metadata timestamp
    persona_data['metadata']['updated_at'] = datetime.utcnow().isoformat() + 'Z'

    # Save updated persona
    return self.save_persona_to_file(persona_data, persona_file)

4. Multi-Strategy Cognitive Processing

The system implements different cognitive strategies that personas use to process information:

  • Analytical: Logical, evidence-based reasoning
  • Creative: Novel connections and lateral thinking
  • Pragmatic: Efficiency and practical outcomes

This multi-strategy approach ensures comprehensive analysis from multiple perspectives, similar to how human experts with different backgrounds would approach the same problem.

5. Hallucination Control

The system implements multiple layers of hallucination control:

  1. Structural Constraints: Explicit entity grounding requirements
  2. Provenance Tracking: Every output is traceable to specific graph nodes
  3. Multi-Criteria Evaluation: Grounding is explicitly scored
  4. Contextual Validation: Outputs are validated against provided context

Built with ❀️ for the future of local, sovereign AI systems

Repository: GitHub - Dynamic Persona MoE RAG

Author: Daniel Kliewer

License: MIT License

Contact: daniel.kliewer@gmail.com

About

A revolutionary, air-gapped Local-First Dynamic Persona Intelligence System that transforms large, heterogeneous corpuses into grounded, attributable, and conversationally explorable intelligence using deterministic generative models.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages