Skip to main content

A production-ready LLM evaluation framework with intelligent caching and dataset management.

Project description

NexusEval ๐Ÿง 

PyPI version License: MIT Python 3.9+ Tests

The production-ready framework for evaluating RAG pipelines and LLM reliability.

NexusEval helps developers measure the quality of their Large Language Model applications using the "Golden Triad" of evaluation: Faithfulness, Answer Relevance, and Completeness. Built for speed with native asynchronous support, intelligent caching, and comprehensive dataset management.


โœจ Why NexusEval?

Feature Benefit
๐Ÿš€ 60-80% Cost Reduction Smart caching eliminates redundant API calls
โšก 3-5x Faster Async processing + cache = blazing speed
๏ฟฝ Multi-Provider Support 5 LLM providers: OpenAI, Anthropic, Google, Groq, Ollama
๏ฟฝ๐Ÿ“Š Dataset Management Load from JSON/CSV/JSONL - ready in seconds
๐ŸŽฏ Advanced Metrics 8 metrics including bias/toxicity detection
๐Ÿ’ฐ Cost Tracking Monitor every dollar spent on evaluation
๏ฟฝ Production Ready Preset configs for dev, staging, and production
โœ… Comprehensive Tests 67 tests ensure reliability

๐Ÿš€ Quick Start (30 seconds)

# Install
pip install nexuseval

# Set your API key
export OPENAI_API_KEY="sk-..."
from nexuseval import TestCase, Evaluator, Faithfulness, AnswerRelevance

# Create a test case
case = TestCase(
    input_text="What is the capital of France?",
    actual_output="Paris is the capital of France.",
    retrieval_context=["France is a country in Europe.", "Paris is a major city."]
)

# Evaluate with automatic caching
evaluator = Evaluator(metrics=[Faithfulness(), AnswerRelevance()])
results = evaluator.evaluate([case])

print(results)

That's it! Caching is enabled by default, so running this again will be 5x faster and cost 80% less. ๐Ÿ’ธ


๐Ÿ“ฆ Installation

Standard Installation (OpenAI only)

pip install nexuseval

With All Providers

# Install with all LLM provider support
pip install nexuseval[all]

# Or install specific providers
pip install nexuseval[providers]  # All LLM providers
pip install nexuseval[embeddings]  # For SemanticSimilarity metric

Development Installation

git clone https://github.com/ShubhamSalokhe/nexuseval.git
cd nexuseval
pip install -e ".[all]"  # Install with all extras
pip install pytest pytest-asyncio  # For running tests

Requirements

  • Python 3.9+
  • OpenAI API key (set as OPENAI_API_KEY environment variable) - Required
  • Optional API keys for other providers:
    • ANTHROPIC_API_KEY for Claude
    • GOOGLE_API_KEY for Gemini
    • GROQ_API_KEY for Groq
    • Ollama running locally for local models

๐Ÿ†• What's New in v0.5.0

๐Ÿ”Œ Multi-Provider LLM Support

Switch between 5 LLM providers seamlessly:

from nexuseval import LLMClient

# OpenAI (default)
client = LLMClient()  # Uses gpt-4-turbo

# Anthropic Claude
client = LLMClient(provider="anthropic", model="claude-3-5-sonnet-20241022")

# Google Gemini (cheapest!)
client = LLMClient(provider="google", model="gemini-1.5-flash")

# Groq (ultra-fast)
client = LLMClient(provider="groq", model="llama-3.3-70b-versatile")

# Ollama (local, free!)
client = LLMClient(provider="ollama", model="llama3")

Install optional providers:

# All providers
pip install nexuseval[all]

# Or individually
pip install anthropic  # Claude
pip install google-generativeai  # Gemini
pip install groq  # Groq
pip install aiohttp  # Ollama

Cost Comparison (1000 evaluations):

Provider Model Cost
OpenAI gpt-4-turbo ~$15.00
OpenAI gpt-4o-mini ~$0.50
Anthropic claude-3-5-sonnet ~$10.00
Google gemini-1.5-flash ~$0.20 โญ
Groq llama-3.3-70b ~$0.70
Ollama llama3 (local) FREE ๐ŸŽ‰

๐ŸŽฏ Advanced Metrics (5 New)

Beyond the standard triad, now includes:

from nexuseval import (
    ContextRelevance,      # Measures retrieval precision
    SemanticSimilarity,    # Embedding-based comparison
    BiasDetection,         # Detects 6 bias types
    ToxicityDetection,     # Flags harmful content
    FactualConsistency     # Verifies claims against context
)

# Context Relevance - checks retrieval quality
metric = ContextRelevance(threshold=0.7)
result = await metric.measure(test_case)

# Semantic Similarity - compare with expected output
metric = SemanticSimilarity(embedding_provider="openai")

# Bias Detection - automatic safety checks
metric = BiasDetection()

# Use with evaluator
evaluator = Evaluator(metrics=[
    Faithfulness(),
    ContextRelevance(),
    BiasDetection()
])

Install embeddings support:

pip install nexuseval[embeddings]  # For SemanticSimilarity

๐Ÿ“Š Dataset Management

Load evaluation datasets from multiple formats:

from nexuseval import DatasetLoader

# From JSON
dataset = DatasetLoader.from_json("evals.json")

# From CSV with column mapping
dataset = DatasetLoader.from_csv(
    "data.csv",
    column_mapping={
        "question": "input_text",
        "response": "actual_output"
    }
)

# Generate samples for testing
from nexuseval import SampleDataGenerator
dataset = SampleDataGenerator.generate_rag_samples(n=10)

# Split for train/test
train, test = dataset.split(train_ratio=0.8, shuffle=True)

๐Ÿ’พ Smart Caching

Automatically cache LLM responses to reduce costs:

from nexuseval import NexusConfig

# Use preset with optimal caching
config = NexusConfig.preset_development()

# Or configure manually
config = NexusConfig(
    cache=CacheConfig(
        enabled=True,
        backend="file",  # "memory", "file", or "redis"
        max_size=5000
    )
)

Performance:

  • ๐Ÿš€ 60-80% cost reduction via intelligent caching
  • โšก 3-5x faster for repeated evaluations
  • ๐Ÿ“Š Built-in hit rate tracking

๐Ÿ’ฐ Cost Tracking

Monitor API costs in real-time:

from nexuseval import NexusConfig

config = NexusConfig.preset_development()  # Cost tracking enabled

# After evaluation
evaluator = Evaluator(metrics=[Faithfulness()])
results = evaluator.evaluate(dataset.test_cases)

# Check costs
cost_stats = evaluator.metrics[0].llm.get_cost_stats()
print(f"Total cost: ${cost_stats['total_cost_usd']:.4f}")
print(f"Total tokens: {cost_stats['total_tokens']:,}")

๐Ÿ“Š Evaluation Metrics

Standard Metrics (RAG Triad)

Metric What it Measures Use Case
Faithfulness Hallucination detection Ensures answers are grounded in retrieved context
Answer Relevance Response quality Checks if the answer addresses the question
Completeness Coverage Verifies all parts of the query were answered

Advanced Metrics (NEW in v0.5.0)

Metric What it Measures Threshold
Context Relevance Retrieval precision 0.7
Semantic Similarity Answer similarity to expected 0.8
Bias Detection Gender, race, religion, age, disability, nationality 0.0 (no bias)
Toxicity Detection Profanity, threats, hate speech, harassment 0.0 (no toxicity)
Factual Consistency Claims verified against context 0.8

Example: Detecting Incomplete Answers

from nexuseval import Completeness, TestCase, Evaluator

# User asked for TWO things, model gave ONE
case = TestCase(
    input_text="Who is the CEO of Tesla and SpaceX?",
    actual_output="The CEO of Tesla is Elon Musk."  # โŒ Missed SpaceX
)

evaluator = Evaluator(metrics=[Completeness()])
results = evaluator.evaluate([case])

# Result: Low score (~0.5) with reason: "Failed to mention SpaceX"

๐Ÿ› ๏ธ Advanced Features

Preset Configurations

Choose the right mode for your environment:

from nexuseval import NexusConfig

# ๐Ÿ”ง Development: Fast iteration, file cache
config = NexusConfig.preset_development()
# Uses: gpt-4o-mini, file cache, verbose output

# ๐Ÿš€ Production: Best quality, distributed cache
config = NexusConfig.preset_production()
# Uses: gpt-4-turbo, Redis cache, high concurrency

# โšก Fast: Maximum speed
config = NexusConfig.preset_fast()
# Uses: gpt-3.5-turbo, in-memory cache, 30 concurrent requests

Bulk Evaluation with Progress Bar

# Load large dataset
dataset = DatasetLoader.from_json("1000_evals.json")

# Automatic async processing with progress bar
evaluator = Evaluator(metrics=[Faithfulness(), AnswerRelevance()])
results = evaluator.evaluate(dataset.test_cases)

# ๐Ÿš€ NexusEval: Evaluating 1000 cases with 2 metrics...
# 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 1000/1000 [00:45<00:00, 22.1it/s]

Dataset Validation

from nexuseval import DatasetLoader, DatasetValidator

# Load dataset
dataset = DatasetLoader.from_json("evals.json")

# Validate
validator = DatasetValidator()
issues = validator.validate_schema(dataset, require_context=True)

if issues:
    for issue in issues:
        print(f"โš ๏ธ {issue}")

# Check duplicates
duplicates = validator.check_duplicates(dataset)
print(f"Found {len(duplicates)} duplicate test cases")

Custom Model Configuration

from nexuseval import NexusConfig, LLMConfig

config = NexusConfig(
    llm=LLMConfig(
        model="gpt-4o-mini",      # Cheaper model
        temperature=0.0,           # Deterministic
        max_tokens=500             # Shorter responses
    )
)

๐Ÿ“ Dataset Formats

JSON Format

{
  "name": "my_evaluations",
  "test_cases": [
    {
      "input_text": "What is Python?",
      "actual_output": "Python is a programming language.",
      "retrieval_context": ["Python is used for AI and web development."],
      "expected_output": "A high-level programming language."
    }
  ]
}

CSV Format

question,answer,context
What is AI?,Artificial Intelligence,AI simulates human intelligence
What is ML?,Machine Learning,ML is a subset of AI

Load with column mapping:

dataset = DatasetLoader.from_csv(
    "data.csv",
    column_mapping={
        "question": "input_text",
        "answer": "actual_output",
        "context": "retrieval_context"
    }
)

๐Ÿ” Examples

Check out the examples/ directory for complete working examples:


๐Ÿงช Running Tests

# Install test dependencies
pip install pytest pytest-asyncio

# Run all tests
pytest tests/ -v

# Run specific test file
pytest tests/test_dataset.py -v

# Run with coverage
pytest tests/ --cov=nexuseval --cov-report=html

Current Status: โœ… 57 tests, 100% pass rate


๐Ÿ—บ๏ธ Roadmap

โœ… v0.4.0 - Core Infrastructure (Released)

  • Dataset management (JSON, CSV, JSONL)
  • Intelligent caching system
  • Cost tracking
  • Configuration presets

๐Ÿ”„ v0.5.0 - Advanced Metrics (Next)

  • Context Relevance (retrieval precision)
  • Bias Detection
  • Toxicity Detection
  • Semantic Similarity
  • Custom metric framework

๐Ÿ“‹ v0.6.0 - Reporting & Analytics

  • HTML/PDF report generation
  • Statistical analysis tools
  • Visualization charts
  • Comparative analysis

๐Ÿค– v0.7.0 - Multi-Model Support

  • Anthropic (Claude)
  • Google (Gemini)
  • Local models (Ollama, vLLM)
  • Unified multi-provider interface

โ“ FAQ

How much does evaluation cost?

With caching enabled (default), costs are typically:

  • First run: $0.01-0.05 per test case (depending on model)
  • Cached runs: $0 (uses cache)
  • Average savings: 60-80% cost reduction

Can I use my own LLM models?

Currently supports OpenAI models. Multi-provider support (Anthropic, Google, local models) is coming in v0.7.0. You can use any OpenAI-compatible endpoint by setting a custom base_url.

How do I disable caching?

config = NexusConfig(
    cache=CacheConfig(enabled=False)
)

Where is the cache stored?

  • Memory cache: RAM (lost on restart)
  • File cache: .nexuseval_cache/ directory (persistent)
  • Redis cache: Your Redis server (distributed)

Is this compatible with existing code?

Yes! All new features are opt-in. Your existing NexusEval code will continue to work without changes.


๐Ÿค Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (pytest tests/ -v)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Please ensure:

  • โœ… All tests pass
  • โœ… Code follows existing style
  • โœ… Add tests for new features
  • โœ… Update documentation

๐Ÿ“ License

MIT License - see LICENSE file for details.


๐Ÿ™ Acknowledgments

Built with โค๏ธ for the AI evaluation community. Special thanks to:

  • The RAG evaluation community for inspiration
  • All contributors and users providing feedback
  • OpenAI for the evaluation LLM infrastructure

๐Ÿ’ฌ Support & Links


๐Ÿ“ˆ Stats

  • Version: 0.4.0
  • Python: 3.9+
  • License: MIT
  • Tests: 57 (100% passing)
  • Code Quality: Type-safe with Pydantic
  • Performance: 60-80% cost reduction, 3-5x speed improvement

Star โญ the repo if you find NexusEval useful!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nexuseval-0.5.0.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexuseval-0.5.0-py3-none-any.whl (46.1 kB view details)

Uploaded Python 3

File details

Details for the file nexuseval-0.5.0.tar.gz.

File metadata

  • Download URL: nexuseval-0.5.0.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nexuseval-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c6fe80416638e4eb9d68e5f90064e47369c1f9138dd71f5dae59015f6e8a2835
MD5 7533e89b3e925f9d413f464527d80c65
BLAKE2b-256 d23b918590e59b42d54042e1a4302fe96bfe95f37de218b104873e6111c0080b

See more details on using hashes here.

File details

Details for the file nexuseval-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: nexuseval-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 46.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nexuseval-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d25226ed4aebdf71d3a4dc4a7848f0d513d2a51cf234d520c898687515a95008
MD5 050b4198f83bb6330ff32049b16ad4d5
BLAKE2b-256 5873063cdac92528ea7950e09fccb0fb9da294e72074379b05b0c083eda1e260

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page