Skip to content
Open
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
2 changes: 1 addition & 1 deletion .claude/conventions/celery.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ many chunk tasks fired at once) and the TTS evaluation tasks (`run_tts_batch_sub
`run_tts_sync_generation` — one long-running task per Sarvam/ElevenLabs model — and
`run_tts_result_processing`, which downloads, converts and uploads a whole Gemini batch) use
`queue="evaluations"`.
Everything else uses `queue="default"`. Don't move other eval-adjacent tasks (e.g. `run_evaluation_batch_submission`,
Everything else uses `queue="default"`. Don't move other eval-adjacent tasks (e.g. `run_prompt_improvement`,
`send_eval_completion_notification`) onto `evaluations` — they're one-shot/fire-and-forget, no
burstiness to isolate.

Expand Down
57 changes: 0 additions & 57 deletions backend/app/api/docs/evaluation/create_evaluation.md

This file was deleted.

18 changes: 1 addition & 17 deletions backend/app/api/docs/evaluation/examples.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
"""Request-body examples for the Evaluation routes (v1 and v2).


"""
"""Request-body examples for the v2 Evaluation routes."""

from app.api.openapi_docs import Examples

EVALUATION_CREATE_EXAMPLES: Examples = {
"fast": (
"Start a fast evaluation run",
{
"dataset_id": 42,
"experiment_name": "faq-bot-gpt-4o-baseline",
"config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"config_version": 1,
"run_mode": "fast",
},
),
}

EVALUATION_V2_CREATE_EXAMPLES: Examples = {
"judged": (
"Start a judged evaluation run",
Expand Down
59 changes: 0 additions & 59 deletions backend/app/api/docs/evaluation/improve_prompt.md

This file was deleted.

4 changes: 3 additions & 1 deletion backend/app/api/docs/evaluation/list_datasets.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
List all datasets for the current organization and project.

Returns a paginated list of datasets ordered by most recent first. Each dataset includes metadata (ID, name, item counts, duplication factor), Langfuse integration details, object store URL, and an `eligible_for_fast` flag that is `true` when the dataset's unique-row count is within `EVAL_FAST_MAX_UNIQUE_ROWS` (and so can be used with `run_mode="fast"` on `POST /evaluations`).
Returns a paginated list of datasets ordered by most recent first. Each dataset includes metadata (ID, name, item counts, duplication factor), Langfuse integration details, object store URL, and an `eligible_for_fast` flag that is `true` when the dataset's unique-row count is within `EVAL_FAST_MAX_UNIQUE_ROWS` (and so can be used with `POST /api/v2/evaluations`).

Datasets are uploaded via `POST /api/v2/evaluations/datasets`; legacy Langfuse-backed datasets uploaded through the removed v1 route still appear here.

## Query parameters

Expand Down
33 changes: 0 additions & 33 deletions backend/app/api/docs/evaluation/upload_dataset.md

This file was deleted.

7 changes: 3 additions & 4 deletions backend/app/api/docs/evaluation/v2/create_evaluation.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Start a v2 evaluation run. Replicates the v1 `POST /api/v1/evaluations` request
body with Kaapi's native LLM-as-Judge built in — v1 is left unchanged.
Start a v2 evaluation run, with Kaapi's native LLM-as-Judge built in. This
replaces the removed v1 `POST /api/v1/evaluations`.

v2 runs are **always fast** and always judged (there is no `run_mode`; batch is
deferred to a later phase). Every scoreable row is automatically judged (no opt-in
v2 runs are **always fast** and always judged (there is no `run_mode`). Every scoreable row is automatically judged (no opt-in
flag) by one combined LLM-judge call scoring each applicable metric on an integer 0–5 scale with
reasoning: **Adherence to Ground Truth** (answer conveys the same correct
information as the golden answer), **Adherence to Prompt** (answer obeys the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Upload a CSV of golden Q&A pairs for evaluation, stored natively by Kaapi with no
Langfuse dataset (v2).

Same multipart shape as the v1 dataset upload (`file`, `dataset_name`,
`description`, `duplication_factor`), but the dataset is stored in object storage
Multipart fields: `file`, `dataset_name`, `description`, `duplication_factor`.
The dataset is stored in object storage
(S3) only: the row is created with `langfuse_dataset_id` null and the CSV holds
exactly the **original** rows — no physical duplication. The `duplication_factor`
is recorded in `dataset_metadata` (with a run-time-duplication marker) and applied
when the run executes, so an 8-row CSV with factor 5 evaluates 40 rows.

**Response:** `APIResponse[DatasetUploadResponse]`, same shape as v1 with
`langfuse_dataset_id` null. `original_items` is the stored row count and
**Response:** `APIResponse[DatasetUploadResponse]` (the shape returned by
`GET /api/v1/evaluations/datasets`) with `langfuse_dataset_id` null. `original_items` is the stored row count and
`total_items` is `original_items × duplication_factor` (the count the run will
produce, not stored rows). `eligible_for_fast` reflects only the unique-row size
cap (`EVAL_FAST_MAX_UNIQUE_ROWS`).
Expand Down
5 changes: 2 additions & 3 deletions backend/app/api/docs/evaluation/v2/improve_prompt.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Enqueue a v2 prompt-recommendation job for the configuration evaluated by a judged run.

Unlike v1 (which reads cosine similarity + correctness), this consumes the native
three-metric judge results — **Adherence to Ground Truth**, **Adherence to Prompt**,
This consumes the native three-metric judge results — **Adherence to Ground Truth**, **Adherence to Prompt**,
and **Adherence to Knowledge Base** — each carrying an integer 0–5 score and the judge's
reasoning. The worker reads both the score and the reasoning per metric, focuses the
rewrite on rows where Adherence to Prompt / Ground Truth are low, and changes only
Expand All @@ -10,7 +9,7 @@ preserved. Low Adherence to Knowledge Base is treated as a retrieval/KB gap rath
than a prompt fault.

The run must be a **judged v2 run** (`is_judge_run = true`), `status = completed`,
and have a `score_trace_url`. The request body is identical to v1 — `callback_url`
and have a `score_trace_url`. The request body is `callback_url`
only. The LLM round-trip runs on a background worker, so this returns `202 Accepted`
with a `job_id` immediately.

Expand Down
54 changes: 5 additions & 49 deletions backend/app/api/routes/evaluations/dataset.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
"""Evaluation dataset API routes."""
"""Evaluation dataset read/delete API routes; uploads live in v2."""

import logging

from fastapi import (
APIRouter,
Depends,
File,
Form,
HTTPException,
Query,
UploadFile,
)

from app.api.deps import AuthContextDep, SessionDep
from app.api.permissions import Permission, require_permission
from app.core.cloud import get_cloud_storage
from app.crud.evaluations import (
get_dataset_by_id,
)
from app.crud.evaluations import (
list_datasets as list_evaluation_datasets,
)
from app.crud.evaluations.dataset import delete_dataset as delete_dataset_crud
from app.models.evaluation import DatasetUploadResponse, EvaluationDataset
from app.services.evaluations import (
is_dataset_fast_eligible,
upload_dataset as upload_evaluation_dataset,
validate_csv_file,
)
from app.services.evaluations import is_dataset_fast_eligible
from app.utils import (
APIResponse,
load_description,
Expand Down Expand Up @@ -55,45 +50,6 @@ def _dataset_to_response(
)


@router.post(
"",
description=load_description("evaluation/upload_dataset.md"),
response_model=APIResponse[DatasetUploadResponse],
dependencies=[Depends(require_permission(Permission.REQUIRE_PROJECT))],
)
async def upload_dataset(
session: SessionDep,
auth_context: AuthContextDep,
file: UploadFile = File(
..., description="CSV file with 'question' and 'answer' columns"
),
dataset_name: str = Form(..., description="Name for the dataset"),
description: str | None = Form(None, description="Optional dataset description"),
duplication_factor: int = Form(
default=1,
ge=1,
le=5,
description="Number of times to duplicate each item (min: 1, max: 5)",
),
) -> APIResponse[DatasetUploadResponse]:
"""Upload an evaluation dataset."""
# Validate and read CSV file
csv_content = await validate_csv_file(file)

# Upload dataset using service
dataset = upload_evaluation_dataset(
session=session,
csv_content=csv_content,
dataset_name=dataset_name,
description=description,
duplication_factor=duplication_factor,
organization_id=auth_context.organization_.id,
project_id=auth_context.project_.id,
)

return APIResponse.success_response(data=_dataset_to_response(dataset))


@router.get(
"",
description=load_description("evaluation/list_datasets.md"),
Expand All @@ -110,7 +66,7 @@ def list_datasets(
eligible_for_fast: bool = Query(
default=False,
description=(
"When true, return only datasets eligible for run_mode='fast' "
"When true, return only datasets eligible for fast (v2) runs "
"(unique-row count within EVAL_FAST_MAX_UNIQUE_ROWS)."
),
),
Expand Down
Loading
Loading