docs.rs failed to build hallucination-detection-0.1.5
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
hallucination-detection-0.1.4
hallucination-detection
A high-performance Rust library for detecting hallucinations in Large Language Model (LLM) outputs using BERT Named Entity Recognition (NER), proper noun analysis, and numerical comparisons.
Features
- Fast and accurate hallucination detection for RAG (Retrieval-Augmented Generation) systems
- Numerical comparison and validation
- Unknown word detection using comprehensive English word dictionary
- Configurable scoring weights and detection options
- Async/await support with Tokio runtime
- Optional ONNX support for improved performance
- Optional BERT-based Named Entity Recognition for proper noun analysis
Installation
Add this to your Cargo.toml
:
[]
= "^0.1.3"
If you want to use NER:
- Download
libtorch
from https://pytorch.org/get-started/locally/. This package requiresv2.4
: if this version is no longer available on the "get started" page, the file should be accessible by modifying the target link, for examplehttps://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.4.0%2Bcpu.zip
for a Linux version with CPU. - Extract the library to a location of your choice
- Set the following environment variables
Linux:
Windows
$Env:LIBTORCH = "X:\path\to\libtorch"
$Env:Path += ";X:\path\to\libtorch\lib"
[]
= { = "^0.1.3", = ["ner"] }
If you want to use ONNX for the NER models, you need to either install the ort runtime or include it in your dependencies:
= { = "^0.1.3", = ["ner", "onnx"] }
= { = "...", = [ "download-binaries" ] }
Quick Start
use ;
async
Configuration
You can customize the detector's behavior using HallucinationOptions
:
use ;
let options = HallucinationOptions ;
let detector = new
.expect;
Output
The detector returns a HallucinationScore
struct containing:
- Scores range from 0.0 (no hallucination) to 1.0 (complete hallucination)
detected_hallucinations
contains specific elements that were flagged
Performance Considerations
- The NER model is loaded once and reused across predictions
- English word dictionary is cached locally for faster subsequent runs
- Async operations allow for non-blocking execution
- ONNX runtime provides optimized model inference
Features Flags
ner
: Enables BERT Named Entity Recognition (default: disabled)onnx
: Uses ONNX runtime for improved performance (default: disabled)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Authors
Devflow Inc. humans@trieve.ai
Acknowledgments
- Uses rust-bert for NER capabilities
- English word list from dwyl/english-words