You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 700302d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: examples/example-offline-evaluations/README.md
+27-25Lines changed: 27 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,33 +6,35 @@ Upload evaluations you have already run, manage reusable scorers and datasets, a
6
6
7
7
Offline evaluations must be enabled for your PostHog project. Use the project's numeric ID and the app host (`https://us.posthog.com`, `https://eu.posthog.com`, or your self-hosted URL).
8
8
9
-
| Operation | Credential and scopes |
9
+
Use a project secret API key for the project ID you pass to the client, or a personal API key. Grant the scopes for the calls your script makes. Personal keys also need the user's resource access, including evaluation editor access for corrections. Dataset exports require a personal API key with `dataset:read`.
10
+
11
+
| Operation | Required scopes |
10
12
| --- | --- |
11
-
| Create experiments, upload results, complete/fail |Personal API key or project secret key with `offline_evaluation_ingestion:write`|
12
-
| Fetch scorers and versions |Personal API key with `llm_analytics:read`|
13
-
| Validate a composite formula without saving |Personal API key with `llm_analytics:read`|
14
-
| Calculate composites using previously stored inputs |Personal API key with ingestion access, `evaluation:read`, and `llm_analytics:read`|
15
-
| Create/update scorers and create versions |Personal API key with `llm_analytics:write`|
16
-
| Fetch datasets, items, and history |Personal API key with `dataset:read`|
17
-
| Create/update/archive/restore datasets and items |Personal API key with `dataset:write`|
18
-
| Read experiment tags |Personal API key with `evaluation:read`|
19
-
| Replace experiment tags |Personal API key with `evaluation:write`|
20
-
| Read an item or result revision |Personal API key with `evaluation:read`. Result reads also require `llm_analytics:read` and access to the scorer. |
21
-
| Update an item or update/delete its payload |Personal API key with `evaluation:write` and evaluation editor access|
22
-
| Delete an item, change/delete a result or its payload |Personal API key with `evaluation:write`, evaluation editor access, `llm_analytics:read`, and access to affected scorers and composite inputs|
23
-
24
-
A personal key can cover both scorer management and uploads. Project secret keys can upload using a known scorer-version UUID without scorer read access. All operations use the explicit project/environment; scorer names are not unique.
25
-
26
-
Dataset operations also require the datasets feature to be enabled. Dataset reads, scorer reads, and experiment uploads use their own scopes; an upload-only credential cannot fetch a dataset. Keep personal keys in server-side scripts or CI secrets.
| Fetch scorers and versions |`llm_analytics:read`|
15
+
| Validate a composite formula without saving |`llm_analytics:read`|
16
+
| Calculate composites using previously stored inputs |`offline_evaluation_ingestion:write`, `evaluation:read`, and `llm_analytics:read`|
17
+
| Create/update scorers and create versions |`llm_analytics:write`|
18
+
| Fetch datasets, items, and history |`dataset:read`|
19
+
| Create/update/archive/restore datasets and items |`dataset:write`|
20
+
| Read experiment tags |`evaluation:read`|
21
+
| Replace experiment tags |`evaluation:write`|
22
+
| Read an item or result revision |`evaluation:read`. Result revision reads also require `llm_analytics:read`. |
23
+
| Update an item or update/delete its payload |`evaluation:write`|
24
+
| Delete an item, change/delete a result or its payload |`evaluation:write` and `llm_analytics:read`|
25
+
26
+
A single key can cover both scorer management and uploads. An ingestion-only key can upload using a known scorer-version UUID without scorer read access. All operations use the explicit project/environment; scorer names are not unique.
27
+
28
+
Dataset operations also require the datasets feature to be enabled. Dataset reads, scorer reads, and experiment uploads use their own scopes; an upload-only credential cannot fetch a dataset. Keep both types of key in server-side scripts or CI secrets.
uv run python examples/example-offline-evaluations/main.py --create-scorer
37
39
38
40
# Use the stable scorer ID printed above; its current version is fetched once.
@@ -101,7 +103,7 @@ The client context manager releases connections. Call `complete()` explicitly af
101
103
102
104
Composite scorers calculate one score per item on the PostHog server from exact reported scorer versions. They can return numeric, boolean, or categorical values. This requires a backend with composite scorer support; ordinary uploads remain compatible with older backends.
103
105
104
-
Provision a composite once, using a personal key with scorer write access. This example assumes `correctness_version_id` identifies a reported boolean scorer and `relevance_version_id` a reported numeric scorer:
106
+
Provision a composite once, using a key with `llm_analytics:write`. This example assumes `correctness_version_id` identifies a reported boolean scorer and `relevance_version_id` a reported numeric scorer:
105
107
106
108
```python
107
109
from posthog.ai.evaluations import ScorerComposition
@@ -149,7 +151,7 @@ experiment.complete()
149
151
150
152
Calculation declarations contain only the item reference, scorer version, and `calculate=True`. Do not supply a value, reasoning, metadata, evaluator trace, or evaluation time. An item may also be referenced by its already accepted UUID.
151
153
152
-
Project secret keys and ingestion-only personal keys must supply **every pinned input result in the same HTTP request**, including on retries. Previously uploaded inputs may be resubmitted with their original values and metadata. Reusing stored inputs without resubmitting them requires both `evaluation:read` and `llm_analytics:read`, in addition to ingestion access. Composite requests and retries also require current access to the composite and its inputs.
154
+
Ingestion-only keys must supply **every pinned input result in the same HTTP request**, including on retries. Previously uploaded inputs may be resubmitted with their original values and metadata. Reusing stored inputs without resubmitting them requires both `evaluation:read` and `llm_analytics:read`, in addition to ingestion access. Composite requests and retries also require current access to the composite and its inputs.
153
155
154
156
The SDK keeps all supplied results for a composite-bearing item together without fetching scorer definitions. It preserves order, so interleaved composite items can form a larger indivisible group. Group each item's results together for large batches. If a group exceeds 1,000 items/results or 5 MiB, the entire call fails locally before any upload. The SDK cannot check that your supplied inputs match the pinned formula without read access; the server validates this. Missing inputs reject the whole HTTP request. Inputs can appear before or after their composite in that request.
155
157
@@ -174,7 +176,7 @@ The state file includes both reported and calculation declarations and the combi
174
176
175
177
Use `evaluations.datasets` to manage PostHog-hosted datasets with the same client configuration as scorers and experiments. Dataset names are unique within a project; keep the returned UUID for subsequent operations.
176
178
177
-
Provision a dataset once with a personal key that has `dataset:write`:
179
+
Provision a dataset once with a key that has `dataset:write`:
178
180
179
181
```python
180
182
dataset = evaluations.datasets.create(
@@ -204,7 +206,7 @@ def capital_answer(question):
204
206
question, "I don't know"
205
207
)
206
208
207
-
with OfflineEvaluations(project_id=123, secret_key=personal_api_key) as evaluations:
209
+
with OfflineEvaluations(project_id=123, secret_key=secret_key) as evaluations:
Reading and writing experiment tags require the personal-key scopes listed above; an upload-only project secret key cannot manage tags. Tag updates do not change the saved `submission`, lifecycle `receipt`, or scorer versions. They are not retried automatically: after a lost acknowledgment, read the current tags before deciding whether to repeat the replacement, since another caller may have edited them.
429
+
Reading and writing experiment tags require `evaluation:read` and `evaluation:write`, respectively; an upload-only project secret key cannot manage tags. Tag updates do not change the saved `submission`, lifecycle `receipt`, or scorer versions. They are not retried automatically: after a lost acknowledgment, read the current tags before deciding whether to repeat the replacement, since another caller may have edited them.
428
430
429
431
The async client exposes the same API: await scorer methods and `experiment.get_tags()` / `experiment.set_tags(...)`.
0 commit comments