Instructions to use ibm-granite/granitelib-rag-r1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Granite Library
How to use ibm-granite/granitelib-rag-r1.0 with Granite Library:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Hallucination Detection
Model Summary
Hallucination detection This is a RAG-specific adapter fine-tuned for the hallucination detection task. Given a multi-turn conversation between a user and an AI assistant ending with an assistant response, and a set of documents/passages on which the last assistant response is supposed to be based, the adapter generates a faithfulness category and explanation for each sentence in the last assistant response.
We have created LoRA adapters for hallucination generation, trained over granite-4.0-micro, granite-4.1-3b, granite-4.1-8b, granite-4.1-30b, and gpt-oss-20b. This is the model card for the LoRA adapters trained over granite models. The model card for the LoRA adapter trained over gpt-oss-20b can be found here.
- Developer: IBM Research
- HF Collection: Granite Libraries
- GitHub Repository: https://github.com/ibm-granite
- Release Date: May 5th, 2026
- Model type: LoRA adapters for ibm-granite/granite-4.0-micro, ibm-granite/granite-4.1-3b, ibm-granite/granite-4.1-8b, ibm-granite/granite-4.1-30b
- License: Apache 2.0
Intended use
This is a hallucination detection adapter that gives the ability to identify faithfulness for each sentence in the last assistant response in a multi-turn RAG conversation based on a set of provided documents/passages.
Note: While you can invoke the hallucination detection adapter directly, it is strongly recommended to call it through the Mellea framework, which wraps the model with a tailored I/O processor, enabling a friendlier development interface. We next describe the input/output of the hallucination detection adapter when invoked through Mellea.
Adapter input: The hallucination detection adapter takes as input the following:
- Conversation: A list of conversational turns ending with the last user question, encoded as a list of user/assistant messages.
- Assistant response: The assistant response to the last user question, which is also the response for which faithfulness category will be identified.
- Documents: A list of documents from which the faithfulness category should be identified for the sentences in the last assistant response, encoded as a collection of Document objects.
Adapter output: The hallucination detection adapter evaluates faithfulness at the sentence level for the last assistant response in a conversation. Given a set of grounding documents and a multi-turn conversation, the adapter splits the final assistant response into individual sentences and classifies each one by comparing its claims against the provided documents.
The output is a JSON array where each item corresponds to a sentence in the assistant response:
| Field | Type | Description |
|---|---|---|
r |
int |
Sentence index (0-based), corresponding to the sentence markers <r0>, <r1>, etc. in the response |
f |
string |
Faithfulness category (see below) |
e |
string |
Explanation justifying the faithfulness decision |
Faithfulness categories:
faithful— The sentence's claims are fully supported by evidence in the provided documents.unfaithful— The sentence contains claims that contradict or are not supported by the provided documents.partial— Some claims in the sentence are supported by the documents, but others cannot be grounded.NA— The sentence does not contain factual claims that require grounding (e.g., greetings, opinions, or meta-commentary).
Going from input to output: When calling the adapter through Mellea, the framework internally performs multiple steps to transform the adapter input to the corresponding output. While you do not have to explicitly invoke these steps, we next provide a brief overview of this process. Given an input to the hallucination detection adapter, Mellea performs the following tasks:
- Convert user input to the appropriate format expected by the underlying hallucination detection model. This includes, among others, splitting the last assistant response and the documents into sentences and prepending them with sentence IDs as well as introducing an appropriate task-specific instruction.
- Call underlying hallucination detection model for inference. The model generates output using a compact representation consisting of sentence IDs in the last assistant response and documents.
- Convert model output to final output. The low-level raw model output is converted to the final output by, among others, mapping the sentence IDs back to response and document spans. The result is an application-friendly JSON format ready for consumption by downstream applications.
Example
You can find below an example of the input and the corresponding output of the hallucination detection adapter:
Input
Conversation:
Assistant: Hello there, how can I help you?
User: Tell me about some yellow fish.
Assistant response:
Purple bumble fish are yellow. Green bumble fish are also yellow.
Documents:
The only type of fish that is yellow is the purple bumble fish.
Output
[
{
"response_begin": 0,
"response_end": 31,
"response_text": "Purple bumble fish are yellow. ",
"faithfulness": "faithful",
"explanation": "This sentence makes a factual claim about the color of purple bumble fish. The document states 'The only type of fish that is yellow is the purple bumble fish.' This directly supports the claim in the sentence."
},
{
"response_begin": 31,
"response_end": 65,
"response_text": "Green bumble fish are also yellow.",
"faithfulness": "unfaithful",
"explanation": "This sentence makes a factual claim about the color of green bumble fish. However, the document does not mention green bumble fish at all. Therefore, this claim cannot be verified from the provided context."
}
]
Quickstart
The recommended way to call this adapter is through the Mellea framework. For code snippets demonstrating how to use this, please refer to the Mellea example.
import json
from mellea import model_ids, start_backend
from mellea.stdlib.components import Message
from mellea.stdlib.components.intrinsic import rag
ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_1_3B, context_type="chat"
)
# NOTE: This example can also be run with the OpenAIBackend using a GraniteSwitch model. See docs/examples/granite-switch/.
ctx = ctx.add(Message("assistant", "Hello there, how can I help you?")).add(
Message("user", "Tell me about some yellow fish.")
)
assistant_response = "Purple bumble fish are yellow. Green bumble fish are also yellow."
documents = ["The only type of fish that is yellow is the purple bumble fish."]
result = rag.flag_hallucinated_content(assistant_response, documents, ctx, backend)
print(f"Result of hallucination check: {json.dumps(result, indent=2)}")
Evaluation
We evaluated the hallucination detection adapter on the QA portion of the RAGTruth benchmark. We compare the response-level hallucination detection performance between the hallucination detection adapter and the methods reported in the RAGTruth paper.
The chart below shows the average F1 performance of the LoRA adapters and prompt-based baselines using different base models.
Following table shows more detailed results with Precision, Recall and F1 obtained for each prompted baseline and trained LoRA adapter.
| Model | Precision | Recall | F1 |
|---|---|---|---|
| GPT 4o (prompted) | 60.5 | 62.2 | 61.3 |
| GPT-OSS-20b (prompted) | 44.5 | 52.8 | 48.2 |
| GPT-OSS-120b (prompted) | 49.9 | 57.9 | 53.6 |
| Granite 4.0-micro (prompted) | 38.5 | 41.9 | 40.1 |
| Granite 4.1-3b-LoRA (prompted) | 42.7 | 40.9 | 41.8 |
| Granite 4.1-8b-LoRA (prompted) | 45.9 | 43.8 | 44.8 |
| Granite 4.1-30b-LoRA (prompted) | 48.6 | 59.9 | 53.6 |
| Granite 4.0-micro-LoRA (Hallucination detection adapter) | 77.3 | 68.4 | 71.3 |
| Granite 4.1-3b-LoRA (Hallucination detection adapter) | 80.9 | 67.5 | 70.8 |
| Granite 4.1-8b-LoRA (Hallucination detection adapter) | 75.9 | 72.7 | 74.1 |
| Granite 4.1-30b-LoRA (Hallucination detection adapter) | 83.4 | 82.4 | 82.9 |
We observe that the hallucination detection LoRA adapters perform better than not only the corresponding base models (prompted with 2-shot examples), but also the bigger models. For instance, the granite-4.1-3b LoRA outperforms the significantly larger gpt-oss-120b and gpt-4o prompted.
Training Details
The hallucination detection adapter was trained on synthetically-generated datasets. The process of generating the training data consisted of two main steps:
- Multi-turn RAG conversation generation: Starting from publicly available document corpora, we generated a set of multi-turn RAG data, consisting of multi-turn conversations grounded on passages retrieved from the corpora. For details on the RAG conversation generation process please refer to the Granite Technical Report and Lee, Young-Suk, et al.
- Hallucination detection: For creating the faithfulness categories and explanations for the responses, we used a multi-step synthetic data generation pipeline. This process resulted in ~20K data instances, which were used to train the LoRA adapter.
The resulting data instances were used to train the hallucination detection adapter.
Training Data
The following public datasets were used as seed datasets for the multi-turn RAG conversation generation process:
Framework versions
- PEFT 0.19.0
Adapter Details
| Property | granite-4.0-micro LoRA | granite-4.1-3b LoRA | granite-4.1-8b LoRA | granite-4.1-30b LoRA |
|---|---|---|---|---|
| Base Model | ibm-granite/granite-4.0-micro | ibm-granite/granite-4.1-3b | ibm-granite/granite-4.1-8b | ibm-granite/granite-4.1-30b |
| PEFT Type | LORA | LORA | LORA | LORA |
| Rank (r) | 32 | 16 | 16 | 16 |
| Alpha | 64 | 32 | 32 | 32 |
| Learning Rate | 5e-4 | 5e-4 | 2e-5 | 1e-4 |
| LoRA Dropout | 0.1 | 0.1 | 0.1 | 0.1 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, input_linear | all-linear | all-linear | all-linear |
Infrastructure: We trained the hallucination detection LoRA adapters on IBM's Vela cluster using H100 GPUs.
Ethical Considerations & Limitations: The model's outputs are not guaranteed to be factually accurate or complete. All outputs should be independently validated before use in decision-making or downstream applications. The model has been trained and evaluated on English data only.
Resources
- ⭐️ Learn about the latest updates with Granite: https://www.ibm.com/granite
- 📄 Get started with tutorials, best practices, and prompt engineering advice: https://www.ibm.com/granite/docs/
- 💡 Learn about the latest Granite learning resources: https://github.com/ibm-granite/granite-guardian/tree/main/cookbooks
