Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Intrinsics are specialized LoRA adapters that add task-specific capabilities (RA
| `rag` | `rewrite_question(question, context, backend)` | Rewrite question into a retrieval query |
| `rag` | `clarify_query(question, documents, context, backend)` | Generate clarification or return "CLEAR" |
| `rag` | `find_citations(response, documents, context, backend)` | Document sentences supporting the response |
| `rag` | `check_context_relevance(question, document, context, backend)` | Whether a document is relevant (0–1) |
| `rag` | `check_context_relevance(question, document, context, backend)` | Whether a document is relevant (0–1); only supported for granite-4.0, not granite-4.1 |
| `rag` | `flag_hallucinated_content(response, documents, context, backend)` | Flag potentially hallucinated sentences |

```python
Expand All @@ -187,7 +187,7 @@ from mellea.stdlib.components import Message
from mellea.stdlib.components.intrinsic import core
from mellea.stdlib.context import ChatContext

backend = LocalHFBackend(model_id="ibm-granite/granite-4.0-micro")
backend = LocalHFBackend(model_id="ibm-granite/granite-4.1-3b")
context = (
ChatContext()
.add(Message("user", "What is the square root of 4?"))
Expand Down Expand Up @@ -223,5 +223,5 @@ https://huggingface.co/ibm-granite/granitelib-rag-r1.0/blob/main/{intrinsic_name

Core and Guardian intrinsics (include model subfolder):
```
https://huggingface.co/ibm-granite/granitelib-{core,guardian}-r1.0/blob/main/{intrinsic_name}/granite-4.0-micro/README.md
https://huggingface.co/ibm-granite/granitelib-{core,guardian,rag}-r1.0/blob/main/{intrinsic_name}/granite-4.1-{3b,8b,30b}/{lora,alora}/README.md
```
2 changes: 1 addition & 1 deletion docs/examples/aLora/example_readme_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if __name__ == "__main__":
generate_readme(
dataset_path="stembolt_failure_dataset.jsonl",
base_model="granite-4.0-micro",
base_model="granite-4.1-3b",
prompt_file=None,
output_path="stembolts_model_readme.md",
name="your-username/stembolts-alora",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/answerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mellea.stdlib.components.intrinsic import rag

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from mellea.stdlib.components.intrinsic import rag

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/context_attribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from mellea.stdlib.components.intrinsic import core

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/context_relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
)
# NOTE: This example can also be run with the OpenAIBackend using a GraniteSwitch model. See docs/examples/granite-switch/.
# NOTE: this example uses Granite 4.0 micro because there is no context_relevance intrinsic for Graniet 4.1

question = "Who is the CEO of Microsoft?"
document = (
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/factuality_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

# Create the backend.
ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/factuality_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Create the backend.
ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/guardian_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from mellea.stdlib.components.intrinsic import guardian

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/hallucination_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from mellea.stdlib.components.intrinsic import rag

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
11 changes: 6 additions & 5 deletions docs/examples/intrinsics/intrinsics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pytest: huggingface, e2e

import mellea.stdlib.functional as mfuncs
from mellea.backends import model_ids
from mellea.backends.adapters.adapter import AdapterType, IntrinsicAdapter
from mellea.backends.huggingface import LocalHFBackend
from mellea.stdlib.components import Intrinsic, Message
Expand All @@ -9,7 +10,7 @@
# This is an example for how you would directly use intrinsics. See `mellea/stdlib/intrinsics/rag.py`
# for helper functions.

backend = LocalHFBackend(model_id="ibm-granite/granite-3.3-8b-instruct")
backend = LocalHFBackend(model_id=model_ids.IBM_GRANITE_4_1_3B)
# --- Alternative: OpenAI backend with Granite Switch (requires vLLM server) ---
# Requires the adapter for this intrinsic to be embedded in the Granite Switch
# model. See docs/examples/granite-switch/ for a full runnable example.
Expand All @@ -28,7 +29,7 @@

# Create the Adapter. IntrinsicAdapter's default to ALORAs.
req_adapter = IntrinsicAdapter(
"requirement_check", base_model_name=backend.base_model_name
"requirement-check", base_model_name=backend.base_model_name
)

# Add the adapter to the backend.
Expand All @@ -42,15 +43,15 @@
# ALORA and then LORA adapters.
out, new_ctx = mfuncs.act(
Intrinsic(
"requirement_check",
"requirement-check",
intrinsic_kwargs={"requirement": "The assistant is helpful."},
),
ctx,
backend,
)

# Print the output. The requirement_check adapter has a specific output format:
print(out) # {"requirement_likelihood": 1.0}
# Print the output. The requirement-check adapter has a specific output format:
print(out) # {"requirement_check": {"score": 0.41272119992000356}}

# The AloraRequirement uses this adapter. It automatically parses that output
# when validating the output.
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/policy_guardrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Create the backend.
ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/query_clarification.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mellea.stdlib.components.intrinsic import rag

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
20 changes: 4 additions & 16 deletions docs/examples/intrinsics/query_rewrite.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# pytest: huggingface, e2e

"""Example usage of the query rewrite intrinsic for RAG applications.

To run this script from the root of the Mellea source tree, use the command:
```
uv run python docs/examples/intrinsics/query_rewrite.py
```
"""

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_MICRO_3B, context_type="chat"
"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_with_question = (
ctx.add(Message("assistant", "Welcome to pet questions!"))
.add(
Message(
Expand All @@ -34,12 +24,10 @@
"probably enjoys her cozy indoor life.",
)
)
.add(Message("user", "But is he more likely to get fleas because of that?"))
)

next_user_turn = "But is he more likely to get fleas because of that?"
ctx_with_question = ctx.add(Message("user", next_user_turn))

print(f"Original user question: {next_user_turn}")
print("Original user question: 'But is he more likely to get fleas because of that?'")

result = rag.rewrite_question(None, ctx_with_question, backend)
print(f"Rewritten user question: {result}")
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/requirement_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
requirement = "Use a professional tone."

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/intrinsics/uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from mellea.stdlib.components.intrinsic import core

ctx, backend = start_backend(
"hf", model_id=model_ids.IBM_GRANITE_4_MICRO_3B, context_type="chat"
"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/.

Expand Down
3 changes: 3 additions & 0 deletions mellea/formatters/granite/intrinsics/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"ibm-granite/granite-3.3-2b-instruct": "granite-3.3-2b-instruct",
"openai/gpt-oss-20b": "gpt-oss-20b",
"ibm-granite/granite-4.0-micro": "granite-4.0-micro",
"ibm-granite/granite-4.1-3b": "granite-4.1-3b",
"ibm-granite/granite-4.1-8b": "granite-4.1-8b",
"ibm-granite/granite-4.1-30b": "granite-4.1-30b",
"granite4:micro": "granite4_micro",
}
"""Base model names that we accept for LoRA/aLoRA adapters in intrinsics libraries.
Expand Down
1 change: 1 addition & 0 deletions test/formatters/granite/test_intrinsics_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def _resolve_yaml(self):

# Base models that are small enough to run locally with transformers
_LOCAL_BASE_MODELS = {
"ibm-granite/granite-4.1-3b",
"ibm-granite/granite-4.0-micro",
"ibm-granite/granite-3.3-2b-instruct",
}
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/components/intrinsic/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"""Location of data files for the tests in this file."""


BASE_MODEL = "ibm-granite/granite-4.0-micro"
BASE_MODEL = "ibm-granite/granite-4.1-3b"


@pytest.fixture(name="backend", scope="module")
Expand Down
Loading