# Build
cargo build --release
# Run with Lunaris API (default)
dop-ensemble "Your prompt here"
# Run with OpenAI API
set OPENAI_API_KEY=your-key
dop-ensemble "Your prompt here" --api openai📖 Full Documentation: See USAGE.md for detailed instructions on installation, configuration, and API setup.
DOP-Ensemble (Divergent–Originality–Precision Ensemble Framework) is a mathematical-algorithmic system designed to enhance creativity and precision in generative language models. Instead of relying solely on prompts, DOP-Ensemble implements a multi-stage pipeline that combines:
- Divergent Generation: Producing multiple candidate responses with controlled stochasticity
- Originality Scoring: Measuring uniqueness against generic patterns
- Precision Enhancement: Applying RAG, fact-checking, and structured output enforcement
The system uses a composite creativity score to select the optimal output:
S = α·D + β·O + γ·P
Where:
- D = Diversity (inter-response dissimilarity)
- O = Originality (distance from generic templates)
- P = Precision (factual accuracy + relevance)
- α, β, γ = Weighted coefficients (configurable)
Based on "A Mathematical Model to Enhance Creativity in Generative AI Systems", creativity is modeled as a multi-dimensional optimization problem:
Measures how distinct candidate responses are from each other:
D = (1 / N²) Σᵢ Σⱼ dist(embedding(rᵢ), embedding(rⱼ))
Where dist can be cosine distance, Euclidean distance, or BLEU score.
Measures distance from "generic" response patterns:
O = 1 - similarity(rᵢ, generic_patterns)
Computed via embedding comparison against a corpus of baseline responses.
Combines factual accuracy and task relevance:
P = w₁·accuracy + w₂·relevance + w₃·coherence
Where each component comes from:
- Accuracy: Fact-checking against knowledge bases
- Relevance: RAG-based context matching
- Coherence: Logical flow evaluation
Following "Harnessing Multiple Large Language Models: A Survey on LLM Ensemble":
- Ensemble-during-inference: Multiple models generate in parallel
- Ensemble-after-inference: Multiple candidates generated, then fused/selected
DOP-Ensemble implements ensemble-after-inference with scoring-based selection.
Inspired by "Ensembling Language Models with Sequential Monte Carlo", the framework can sample from an "ensemble distribution" combining uncertainty from multiple generation paths:
P(ensemble) ∝ Σᵢ wᵢ · P(response | model_i)
┌─────────────────────────────────────────────────────────────────┐
│ USER INPUT │
└─────────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ DIVERGENT GENERATOR │
│ • Temperature-controlled sampling (T > 0) │
│ • Context perturbation for variety │
│ • Explicit diversity constraints │
│ Output: N candidate responses {r₁, r₂, ..., r_N} │
└─────────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ METRIC COMPUTATION │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ DIVERSITY │ │ ORIGINALITY │ │ PRECISION │ │
│ │ ANALYZER │ │ SCORER │ │ ENGINE │ │
│ │ │ │ │ │ │ │
│ │ Embedding │ │ vs Generic │ │ +RAG │ │
│ │ distances │ │ patterns │ │ +Fact Check │ │
│ │ Inter-sample│ │ Novelty │ │ +Structure │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └────────────┬────┴────────────────┘ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ CREATIVITY SCORE │ │
│ │ S = αD + βO + γP │ │
│ └─────────┬───────────┘ │
└───────────────────┼─────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ SELECTOR / ENSEMBLE │
│ • Rank candidates by S │
│ • Apply threshold filtering │
│ • Optional: merge top-K fragments │
└─────────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ FINAL OUTPUT │
│ Selected response with highest creativity score │
└─────────────────────────────────────────────────────────────────┘
Purpose: Explore the "idea space" by generating diverse candidates
Techniques:
- Stochastic Sampling: Use
temperature > 0andtop_p > 0to avoid mode collapse - Context Perturbation: Vary prompt framing per candidate
- Diversity Constraints: Explicit instructions to avoid similar names/roles
Mathematical View: Sampling from a wider probability distribution:
P(sample) ∝ P(token | context)^(1/T)
Where T > 1 broadens the distribution.
Purpose: Quantify inter-response differences
Implementation:
- Compute embeddings for all candidates
- Calculate pairwise distances
- Average or max-pool to get D score
Purpose: Penalize "generic" responses
Implementation:
- Maintain a baseline corpus of typical responses
- Compute similarity between each candidate and baseline
- O = 1 - max(similarity) or O = mean(1 - similarity)
Components:
- Search knowledge base for relevant context
- Inject context before generation
- Ensures grounded, specific outputs
- Validate claims against trusted sources
- Flag inconsistencies
- Constrain output to JSON/schema format
- Force specific fields (name, role, responsibilities)
- Reduces vagueness
Strategies:
- Greedy: Return candidate with max S
- Threshold: Return all where S > threshold
- Merge: Combine best fragments from top-K
use dop_ensemble::{DOPEngine, Config, Schema};
let config = Config {
alpha: 0.4,
beta: 0.3,
gamma: 0.3,
n_candidates: 5,
temperature: 0.8,
};
let engine = DOPEngine::new(config);
let result = engine.generate(prompt, context, schema).await;
println!("Score: {}", result.score);# Basic usage
dop-ensemble "Create a team of AI agents for marketing"
# With custom weights
dop-ensemble "Marketing agent system" \
--alpha 0.5 --beta 0.3 --gamma 0.2 \
--candidates 10
# With LLM merge strategy
dop-ensemble "Creative marketing campaign" --strategy llm-merge💡 Tip: Use the CLI for quick experimentation. For programmatic access, use the Rust API.
| Parameter | Type | Default | Description |
|---|---|---|---|
alpha |
f32 | 0.33 | Diversity weight |
beta |
f32 | 0.33 | Originality weight |
gamma |
f32 | 0.34 | Precision weight |
n_candidates |
usize | 5 | Number of generated candidates |
temperature |
f32 | 0.7 | Sampling temperature |
top_p |
f32 | 0.9 | Nucleus sampling parameter |
threshold |
f32 | 0.5 | Minimum score to return |
api_type |
ApiType | Lunaris | API backend (lunaris or openai) |
-
"A Mathematical Model to Enhance Creativity in Generative AI Systems"
- Introduces creativity score combining divergence + convergence
- Models diversity, originality, and utility
-
"Harnessing Multiple Large Language Models: A Survey on LLM Ensemble"
- Taxonomy: ensemble-before/during/after inference
- Voting, scoring, and merging strategies
-
"Ensembling Language Models with Sequential Monte Carlo"
- SMC sampling for combining model uncertainties
- Better uncertainty quantification
-
"Variance Reduction in Output from Generative AI"
- Techniques to avoid "regression to generic"
- Targeted variance injection
-
"Creativity in LLM-based Multi-Agent Systems: A Survey"
- Multi-agent creativity mechanisms
- Divergent exploration + convergent selection
- RAG: Retrieval-Augmented Generation for grounding
- Constrained Decoding: Schema-based output enforcement
- PEFT: Parameter-efficient fine-tuning for specific domains
⚠️ Note: The Python package is planned for a future release. Currently, only the Rust core library is available.
cargo add dop-ensemble# pip install dop-ensemble # Coming soon!DOP-Ensemble supports two API backends:
The system is compatible with Lunaris AI API, a custom provider system.
Environment Variables:
# Lunaris API endpoint (default: http://127.0.0.1:8789)
AI_API_BASE_URL=http://127.0.0.1:8789CLI Usage:
# Using Lunaris API (default)
dop-ensemble "Your prompt" --api lunarisThe system is also compatible with any OpenAI API-compatible endpoint (OpenAI, Azure OpenAI, local models, etc.).
Environment Variables:
# OpenAI API base URL (default: https://api.openai.com/v1)
OPENAI_API_BASE_URL=https://api.openai.com/v1
# OpenAI API key
OPENAI_API_KEY=your_api_key_hereCLI Usage:
# Using OpenAI API compatible
dop-ensemble "Your prompt" --api openaiConfiguration Example:
use dop_ensemble::{Config, ApiType};
let config = Config {
api_type: ApiType::OpenAI,
// ... other config options
};# Generate with default settings (uses Lunaris API)
dop-ensemble generate "Create a team of AI agents for e-commerce"
# Using OpenAI API compatible
dop-ensemble generate "Marketing agent system" --api openai
# Custom weights
dop-ensemble generate "Marketing agent system" \
--alpha 0.5 --beta 0.3 --gamma 0.2 \
--candidates 10
# With RAG context
dop-ensemble generate "Customer support agents" \
--context-file knowledge.json \
--schema agents.schema.json
# LLM Merge strategy (fusion ensemble)
dop-ensemble "Creative campaign" --strategy llm-mergeThe system can enforce structured output:
{
"agents": [
{
"name": "MarketingStrategist",
"role": "Senior Marketing Strategist",
"responsibilities": [
"Develop comprehensive marketing strategies",
"Analyze market trends and competitor positioning"
],
"interactions": ["ContentCreator", "DataAnalyst"]
}
],
"metadata": {
"score": 0.87,
"diversity": 0.82,
"originality": 0.79,
"precision": 0.91
}
}Train weights (α, β, γ) via RL to learn user preferences:
# Pseudo-code
rewards = []
for episode in range(episodes):
response = engine.generate(prompt)
reward = user_feedback(response) # Thumbs up/down
rewards.append(reward)
# Update weights via policy gradient
alpha, beta, gamma = update_weights(rewards)Extend to multiple underlying LLMs:
models = ["gpt-4", "claude-3", "gemini-pro"]
candidates = []
for model in models:
candidates.extend(generate(model, prompt, n=3))Apache License 2.0 - See LICENSE file for details.
@misc{dop-ensemble,
title = {DOP-Ensemble: Divergent–Originality–Precision Ensemble Framework},
author = {DOP-Ensemble Authors},
year = {2024},
note = {Combining mathematical creativity scoring with multi-agent LLM ensembles},
url = {https://github.com/Solar2004/dop-ensemble}
}- Wankhade et al. "A Mathematical Model to Enhance Creativity in Generative AI Systems"
- "Harnessing Multiple Large Language Models: A Survey on LLM Ensemble"
- "Ensembling Language Models with Sequential Monte Carlo"
- "LLM Responses: How To Change, Control, And Improve"
- "Variance Reduction in Output from Generative AI"
- "Creativity in LLM-based Multi-Agent Systems: A Survey"
