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
15 changes: 2 additions & 13 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Debug Ragas Distribution -- Remote",
"name": "Debug Ragas Distribution",
"type": "debugpy",
"request": "launch",
"module": "llama_stack.cli.llama",
"args": ["stack", "run", "distribution/run-remote.yaml"],
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env",
"justMyCode": false
},
{
"name": "Debug Ragas Distribution -- Inline",
"type": "debugpy",
"request": "launch",
"module": "llama_stack.cli.llama",
"args": ["stack", "run", "distribution/run-inline.yaml"],
"args": ["stack", "run", "distribution/run.yaml"],
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env",
"justMyCode": false
Expand Down
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This repository implements [Ragas](https://github.com/explodinggradients/ragas)
The goal is to provide all of Ragas' evaluation functionality over Llama Stack's eval API, while leveraging the Llama Stack's built-in APIs for inference (llms and embeddings), datasets, and benchmarks.

There are two versions of the provider:
- `inline`: runs the Ragas evaluation in the same process as the Llama Stack server.
- `remote`: runs the Ragas evaluation in a remote process, using Kubeflow Pipelines.
- `inline`: runs the Ragas evaluation in the same process as the Llama Stack server. This is always available with the base installation.
- `remote`: runs the Ragas evaluation in a remote process, using Kubeflow Pipelines. Only available when remote dependencies are installed with `pip install llama-stack-provider-ragas[remote]`.

## Prerequisites
- Python 3.12
Expand All @@ -41,12 +41,29 @@ There are two versions of the provider:
```
- The sample LS distributions (one for inline and one for remote provider) is a simple LS distribution that uses Ollama for inference and embeddings. See the provider-specific sections below for setup and run commands.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (typo): Grammatical error: 'is' should be 'are' when referring to multiple distributions.

The sentence should use 'are' instead of 'is' to match the plural subject.

Suggested change
- The sample LS distributions (one for inline and one for remote provider) is a simple LS distribution that uses Ollama for inference and embeddings. See the provider-specific sections below for setup and run commands.
- The sample LS distributions (one for inline and one for remote provider) are simple LS distributions that use Ollama for inference and embeddings. See the provider-specific sections below for setup and run commands.


### Remote provider (default)
### Inline provider (default with base installation)

Create a `.env` file with the required environment variable:
```bash
EMBEDDING_MODEL=ollama/all-minilm:l6-v2
```

Run the server:
```bash
dotenv run uv run llama stack run distribution/run.yaml
```

### Remote provider (requires optional dependencies)

First install the remote dependencies:
```bash
uv pip install -e ".[remote]"
```

Create a `.env` file with the following:
```bash
# Required for both inline and remote
EMBEDDING_MODEL=all-MiniLM-L6-v2
EMBEDDING_MODEL=ollama/all-minilm:l6-v2

# Required for remote provider
KUBEFLOW_LLAMA_STACK_URL=<your-llama-stack-url>
Expand Down Expand Up @@ -75,22 +92,9 @@ Where:

Run the server:
```bash
dotenv run uv run llama stack run distribution/run-remote.yaml
```

### Inline provider (need to specify `.inline` in the module name)

Create a `.env` file with the required environment variable:
```bash
EMBEDDING_MODEL=all-MiniLM-L6-v2
```

Run the server:
```bash
dotenv run uv run llama stack run distribution/run-inline.yaml
dotenv run uv run llama stack run distribution/run.yaml
```

You will notice that `run-inline.yaml` file has the module name as `llama_stack_provider_ragas.inline`, in order to specify the inline provider.

## Usage
See the demos in the `demos` directory.
826 changes: 550 additions & 276 deletions demos/remote_demo.ipynb → demos/basic_demo.ipynb

Large diffs are not rendered by default.

880 changes: 0 additions & 880 deletions demos/inline_demo.ipynb

This file was deleted.

61 changes: 0 additions & 61 deletions distribution/run-inline.yaml

This file was deleted.

9 changes: 7 additions & 2 deletions distribution/run-remote.yaml → distribution/run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ apis:
- datasetio
providers:
eval:
- provider_id: trustyai_ragas
- provider_id: ${env.KUBEFLOW_LLAMA_STACK_URL:+trustyai_ragas_remote}
provider_type: remote::trustyai_ragas
module: llama_stack_provider_ragas
module: llama_stack_provider_ragas.remote
config:
embedding_model: ${env.EMBEDDING_MODEL}
kubeflow_config:
Expand All @@ -22,6 +22,11 @@ providers:
llama_stack_url: ${env.KUBEFLOW_LLAMA_STACK_URL}
base_image: ${env.KUBEFLOW_BASE_IMAGE}
pipelines_api_token: ${env.KUBEFLOW_PIPELINES_TOKEN:=}
- provider_id: ${env.EMBEDDING_MODEL:+trustyai_ragas_inline}
provider_type: inline::trustyai_ragas
module: llama_stack_provider_ragas.inline
config:
embedding_model: ${env.EMBEDDING_MODEL}
datasetio:
- provider_id: localfs
provider_type: inline::localfs
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ The goal is to provide all of Ragas' evaluation functionality over Llama Stack's

There are two versions of the provider:

* `remote`: runs the Ragas evaluation in a remote process, using Kubeflow Pipelines. This is the *default* when using the module-based import.
* `inline`: runs the Ragas evaluation in the same process as the Llama Stack server.
* `inline`: runs the Ragas evaluation in the same process as the Llama Stack server. This is always available with the base installation.
* `remote`: runs the Ragas evaluation in a remote process, using Kubeflow Pipelines. Only available when remote dependencies are installed with `pip install llama-stack-provider-ragas[remote]`.

== Getting Started

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/inline-provider.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The inline provider is setup in the following lines of the `run-inline.yaml`:
[,yaml]
----
eval:
- provider_id: trustyai_ragas
- provider_id: trustyai_ragas_inline
provider_type: inline::trustyai_ragas
module: llama_stack_provider_ragas.inline
config:
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/remote-provider.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ The remote provider is setup in the following lines of the `run-remote.yaml`:
[,yaml]
----
eval:
- provider_id: trustyai_ragas
- provider_id: trustyai_ragas_remote
provider_type: remote::trustyai_ragas
module: llama_stack_provider_ragas.remote # can also just be llama_stack_provider_ragas and it will default to remote
module: llama_stack_provider_ragas.remote
config:
embedding_model: ${env.EMBEDDING_MODEL}
kubeflow_config:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "llama-stack-provider-ragas"
version = "0.4.0"
version = "0.4.1"
description = "Ragas evaluation as an out-of-tree Llama Stack provider"
readme = "README.md"
requires-python = ">=3.12"
Expand Down
5 changes: 4 additions & 1 deletion src/llama_stack_provider_ragas/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
faithfulness,
)

PROVIDER_TYPE = "trustyai_ragas"
PROVIDER_ID_INLINE = "trustyai_ragas_inline"
PROVIDER_ID_REMOTE = "trustyai_ragas_remote"

METRIC_MAPPING = {
metric_func.name: metric_func
for metric_func in [
Expand All @@ -20,7 +24,6 @@
# "rouge_score": RougeScore(),
]
}

AVAILABLE_METRICS = list(METRIC_MAPPING.keys())

# Kubeflow ConfigMap keys and defaults for base image resolution
Expand Down
4 changes: 3 additions & 1 deletion src/llama_stack_provider_ragas/inline/provider.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from llama_stack.providers.datatypes import Api, InlineProviderSpec, ProviderSpec

from ..constants import PROVIDER_TYPE


def get_provider_spec() -> ProviderSpec:
return InlineProviderSpec(
api=Api.eval,
provider_type="inline::trustyai_ragas",
provider_type=f"inline::{PROVIDER_TYPE}",
pip_packages=["ragas==0.3.0"],
config_class="llama_stack_provider_ragas.config.RagasProviderInlineConfig",
module="llama_stack_provider_ragas.inline",
Expand Down
40 changes: 36 additions & 4 deletions src/llama_stack_provider_ragas/provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# remote is the default provider
from .remote import get_adapter_impl
from .remote.provider import get_provider_spec
import logging

__all__ = ["get_provider_spec", "get_adapter_impl"]
from .inline.provider import get_provider_spec as get_inline_provider_spec

logger = logging.getLogger(__name__)


def _has_remote_dependencies() -> bool:
"""Check if remote dependencies are available."""
try:
import kfp # noqa: F401
import kubernetes # noqa: F401
import s3fs # noqa: F401
from kfp import kubernetes as kfp_kubernetes # noqa: F401

return True
except ImportError:
return False


def get_provider_spec():
providers = [get_inline_provider_spec()]

if _has_remote_dependencies():
from .remote.provider import get_provider_spec as get_remote_provider_spec

providers.append(get_remote_provider_spec())
else:
logger.info(
"Remote provider dependencies not found, returning inline provider only. "
"Enable remote evaluation with 'pip install llama-stack-provider-ragas[remote]'."
)

return providers


__all__ = ["get_provider_spec"]
6 changes: 4 additions & 2 deletions src/llama_stack_provider_ragas/remote/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
RemoteProviderSpec,
)

from ..constants import PROVIDER_TYPE


def get_provider_spec() -> ProviderSpec:
return RemoteProviderSpec(
api=Api.eval,
provider_type="remote::trustyai_ragas",
adapter_type="trustyai_ragas",
provider_type=f"remote::{PROVIDER_TYPE}",
adapter_type=PROVIDER_TYPE,
module="llama_stack_provider_ragas.remote",
pip_packages=[
"ragas==0.3.0",
Expand Down
4 changes: 3 additions & 1 deletion tests/test_inline_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pytest
from ragas.metrics import answer_relevancy

from llama_stack_provider_ragas.constants import PROVIDER_ID_INLINE

# mark as integration, see tool.pytest.ini_options in pyproject.toml
pytestmark = pytest.mark.integration_test

Expand Down Expand Up @@ -34,7 +36,7 @@ def test_single_metric_evaluation(
benchmark_id=benchmark_id,
dataset_id=dataset_id,
scoring_functions=[metric_to_test.name],
provider_id="trustyai_ragas",
provider_id=PROVIDER_ID_INLINE,
)

job = lls_client.eval.run_eval(
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.