sable-sphynx 0.7.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sable_sphynx-0.7.0.dev0.dist-info/METADATA +152 -0
- sable_sphynx-0.7.0.dev0.dist-info/RECORD +174 -0
- sable_sphynx-0.7.0.dev0.dist-info/WHEEL +5 -0
- sable_sphynx-0.7.0.dev0.dist-info/top_level.txt +1 -0
- sphynx/__init__.py +469 -0
- sphynx/__init__.pyi +376 -0
- sphynx/_analytical_client.py +77 -0
- sphynx/_analytical_values.py +252 -0
- sphynx/_audit_client.py +173 -0
- sphynx/_comparison_adapters.py +113 -0
- sphynx/_componentized_full_rag.py +34 -0
- sphynx/_composed_pipeline.py +109 -0
- sphynx/_full_rag_grading.py +218 -0
- sphynx/_full_rag_trace.py +221 -0
- sphynx/_local_eval.py +268 -0
- sphynx/_pipeline_core.py +243 -0
- sphynx/_pr_client.py +237 -0
- sphynx/_rag_diagnostics_calibration.py +285 -0
- sphynx/_rag_diagnostics_catalog.py +39 -0
- sphynx/_rag_diagnostics_common.py +26 -0
- sphynx/_rag_diagnostics_contracts.py +186 -0
- sphynx/_rag_diagnostics_engine.py +243 -0
- sphynx/_rag_diagnostics_importers.py +242 -0
- sphynx/_rag_diagnostics_ranking.py +81 -0
- sphynx/_rag_diagnostics_semantic.py +325 -0
- sphynx/_rag_ranking.py +149 -0
- sphynx/_speech_benchmark_scoring.py +140 -0
- sphynx/_speech_benchmark_sources.py +275 -0
- sphynx/_speech_complete_scoring.py +218 -0
- sphynx/_speech_complete_source.py +118 -0
- sphynx/_speech_kido.py +294 -0
- sphynx/_speech_scoring.py +77 -0
- sphynx/_track_capture.py +213 -0
- sphynx/analytical_views.py +515 -0
- sphynx/assessment_contracts.py +378 -0
- sphynx/assessment_selection.py +57 -0
- sphynx/audit_access.py +245 -0
- sphynx/audit_contracts.py +204 -0
- sphynx/audit_requests.py +180 -0
- sphynx/authoring.py +188 -0
- sphynx/benchmarks.py +568 -0
- sphynx/candidates.py +62 -0
- sphynx/catalog.py +272 -0
- sphynx/chunking.py +372 -0
- sphynx/clickhouse_reader.py +169 -0
- sphynx/client.py +486 -0
- sphynx/comparison_core.py +149 -0
- sphynx/comparison_views.py +223 -0
- sphynx/components.py +1661 -0
- sphynx/contracts.py +514 -0
- sphynx/customer_rerank.py +299 -0
- sphynx/customer_retrieval.py +146 -0
- sphynx/data/benchmark-releases.v1.json +164 -0
- sphynx/data/public-benchmark-release.v1.json +354 -0
- sphynx/data/rag-diagnostics-synthetic.v1.json +6982 -0
- sphynx/data/rag-paper-references.v1.json +176 -0
- sphynx/data/rag-paper-schemas.v1.json +1069 -0
- sphynx/data/rag-rerank-v1.json +507 -0
- sphynx/dataset_catalog_data.py +1214 -0
- sphynx/dataset_readiness.py +138 -0
- sphynx/dataset_v3.py +999 -0
- sphynx/demo.py +130 -0
- sphynx/demo_candidates/__init__.py +1 -0
- sphynx/demo_candidates/dense.py +11 -0
- sphynx/demo_candidates/lexical.py +21 -0
- sphynx/diagnostics.py +207 -0
- sphynx/documentation.py +737 -0
- sphynx/documentation_candidate.py +939 -0
- sphynx/evals.py +538 -0
- sphynx/evaluation_protocols.py +124 -0
- sphynx/evaluator_bindings.py +370 -0
- sphynx/evidence.py +352 -0
- sphynx/execution_capabilities.py +109 -0
- sphynx/fast_search.py +285 -0
- sphynx/full_rag.py +341 -0
- sphynx/hosted/__init__.py +18 -0
- sphynx/hosted/benchmark_intake.py +218 -0
- sphynx/hosted/contracts.py +361 -0
- sphynx/hosted/model_admission.py +130 -0
- sphynx/hosted/model_artifacts.py +298 -0
- sphynx/hosted/model_contracts.py +63 -0
- sphynx/hosted/model_gcs.py +181 -0
- sphynx/hosted/model_history.py +84 -0
- sphynx/hosted/model_session.py +233 -0
- sphynx/hosted/public_suite.py +74 -0
- sphynx/hosted/registry.py +97 -0
- sphynx/hosted/revisions.py +126 -0
- sphynx/hosted/sandbox.py +105 -0
- sphynx/hosted/submission.py +287 -0
- sphynx/hosted_workflow.py +451 -0
- sphynx/http_transport.py +86 -0
- sphynx/integrated_rag.py +352 -0
- sphynx/integrated_workflow.py +552 -0
- sphynx/integration_contracts.py +474 -0
- sphynx/invocation.py +791 -0
- sphynx/invocation_candidates.py +392 -0
- sphynx/invocation_catalog_data.py +40 -0
- sphynx/learned_catalog_data.py +30 -0
- sphynx/learned_rerank.py +267 -0
- sphynx/legacy_full_rag.py +67 -0
- sphynx/lifecycle.py +885 -0
- sphynx/lifecycle_workflow.py +490 -0
- sphynx/metric_views.py +474 -0
- sphynx/metrics.py +282 -0
- sphynx/model_adapters.py +438 -0
- sphynx/model_catalog_data.py +30 -0
- sphynx/official_benchmarks.py +385 -0
- sphynx/packs.py +258 -0
- sphynx/pipeline.py +313 -0
- sphynx/pipeline_workflow.py +551 -0
- sphynx/pr_evaluations.py +560 -0
- sphynx/progress.py +89 -0
- sphynx/public_bundle.py +173 -0
- sphynx/public_eval.py +62 -0
- sphynx/public_rerank.py +355 -0
- sphynx/py.typed +0 -0
- sphynx/pytest_plugin.py +62 -0
- sphynx/question_robustness.py +437 -0
- sphynx/rag.py +329 -0
- sphynx/rag_diagnostics.py +309 -0
- sphynx/rag_papers/__init__.py +29 -0
- sphynx/rag_papers/__main__.py +45 -0
- sphynx/rag_papers/candidates.py +19 -0
- sphynx/rag_papers/contracts.py +282 -0
- sphynx/rag_papers/datasets.py +291 -0
- sphynx/rag_papers/experiments.py +116 -0
- sphynx/rag_papers/judges.py +308 -0
- sphynx/rag_papers/registry.py +33 -0
- sphynx/rag_papers/runner.py +176 -0
- sphynx/rag_papers/sable.py +135 -0
- sphynx/rag_papers/schemas.py +12 -0
- sphynx/rag_papers/scoring.py +249 -0
- sphynx/rag_papers/semantic.py +288 -0
- sphynx/rag_papers/trec.py +80 -0
- sphynx/recorded_scores.py +352 -0
- sphynx/records.py +124 -0
- sphynx/reflex_traces.py +193 -0
- sphynx/report_rendering.py +71 -0
- sphynx/rerank_family_contracts.py +150 -0
- sphynx/rerank_workflow.py +424 -0
- sphynx/research_candidate.py +190 -0
- sphynx/results.py +852 -0
- sphynx/retrieval.py +750 -0
- sphynx/retrieval_candidates.py +295 -0
- sphynx/retrieval_catalog_data.py +19 -0
- sphynx/retrieval_recordings.py +125 -0
- sphynx/reviewer_audit.py +266 -0
- sphynx/routing_policies.py +375 -0
- sphynx/runner.py +544 -0
- sphynx/sable_rerank.py +489 -0
- sphynx/score_reliability.py +393 -0
- sphynx/speech_benchmarks.py +204 -0
- sphynx/speech_campaigns.py +378 -0
- sphynx/speech_complete.py +236 -0
- sphynx/speech_contracts.py +225 -0
- sphynx/speech_evidence.py +429 -0
- sphynx/speech_listening.py +115 -0
- sphynx/speech_multilingual.py +71 -0
- sphynx/speech_tts.py +479 -0
- sphynx/sql/001_sync_v1.sql +30 -0
- sphynx/stage_contracts.py +199 -0
- sphynx/statistical_catalog_data.py +53 -0
- sphynx/statistical_rerank.py +232 -0
- sphynx/sync.py +797 -0
- sphynx/workbench.py +378 -0
- sphynx/workbench_catalog_data.py +13 -0
- sphynx/workbench_tracks.py +78 -0
- sphynx/workflow_async.py +197 -0
- sphynx/workflow_contracts.py +594 -0
- sphynx/workflow_decisions.py +211 -0
- sphynx/workflow_defaults.py +16 -0
- sphynx/workflow_extensions.py +212 -0
- sphynx/workflow_registry.py +513 -0
- sphynx/workflows.py +792 -0
sphynx/authoring.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Small trusted local callables through the existing lifecycle workflow.
|
|
2
|
+
|
|
3
|
+
No provider SDK, network request, isolation, source attestation, statistical
|
|
4
|
+
reducer or private acceptance rule is supplied by this convenience module.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Callable, Mapping
|
|
9
|
+
from dataclasses import dataclass, field, replace
|
|
10
|
+
import inspect
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from .assessment_contracts import Assessment, CaseView, EvaluatorContext
|
|
14
|
+
from .evaluation_protocols import VersionedIdentity
|
|
15
|
+
from .execution_capabilities import ExecutionPath
|
|
16
|
+
from .lifecycle import AttemptOutput, DriverDescriptor, LifecycleError, RunPolicy
|
|
17
|
+
from .lifecycle_workflow import LifecycleBackend
|
|
18
|
+
from .workflow_contracts import (
|
|
19
|
+
Criterion, Dataset, DatasetDefinition, EvaluatorDefinition, PayloadSchema,
|
|
20
|
+
SuiteDefinition, WorkflowContractError, _object, _text, _thaw, contract_digest,
|
|
21
|
+
)
|
|
22
|
+
from .workflow_registry import WorkflowRegistry
|
|
23
|
+
from .workflows import Suite
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True)
|
|
27
|
+
class CallableCandidate:
|
|
28
|
+
"""A synchronous JSON-object callable with a declared, unattested identity."""
|
|
29
|
+
|
|
30
|
+
identity: VersionedIdentity
|
|
31
|
+
callback: Callable[[Mapping[str, Any]], Mapping[str, Any]] = field(repr=False, compare=False)
|
|
32
|
+
|
|
33
|
+
def __post_init__(self):
|
|
34
|
+
if not isinstance(self.identity, VersionedIdentity) or not callable(self.callback):
|
|
35
|
+
raise WorkflowContractError("CallableCandidate requires VersionedIdentity and a callable")
|
|
36
|
+
if inspect.iscoroutinefunction(self.callback) or inspect.iscoroutinefunction(getattr(self.callback, "__call__", None)):
|
|
37
|
+
raise WorkflowContractError("CallableCandidate is synchronous; use an explicit asynchronous driver")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class _CallableDriver:
|
|
41
|
+
def __init__(self, output_schema, idempotent):
|
|
42
|
+
self.output_schema = output_schema
|
|
43
|
+
self.descriptor = DriverDescriptor("sphynx.authoring.callable.v1",
|
|
44
|
+
"sphynx.authoring.callable.v1:" + contract_digest(output_schema.to_dict()),
|
|
45
|
+
("sphynx.lifecycle.idempotent.v1",) if idempotent else ())
|
|
46
|
+
|
|
47
|
+
def candidate_identity(self, candidate):
|
|
48
|
+
if not isinstance(candidate, CallableCandidate):
|
|
49
|
+
raise WorkflowContractError("this suite needs a CallableCandidate with an explicit method identity")
|
|
50
|
+
return {"identity": candidate.identity.to_dict(), "authority": "caller_declared_not_source_attested"}
|
|
51
|
+
|
|
52
|
+
def execute(self, candidate, case, context):
|
|
53
|
+
self.candidate_identity(candidate)
|
|
54
|
+
output = candidate.callback(_thaw(case.inputs))
|
|
55
|
+
return AttemptOutput(_thaw(self.output_schema.validate(output)))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class _CallableBackend(LifecycleBackend):
|
|
59
|
+
def __init__(self, *args, idempotent=False, **kwargs):
|
|
60
|
+
self.idempotent = idempotent
|
|
61
|
+
super().__init__(*args, **kwargs)
|
|
62
|
+
path = ExecutionPath(self.descriptor.supported_scopes[0], "local",
|
|
63
|
+
capabilities=self.descriptor.capabilities)
|
|
64
|
+
self.descriptor = replace(self.descriptor,
|
|
65
|
+
metadata={**_thaw(self.descriptor.metadata), "execution_paths": [path.to_dict()]})
|
|
66
|
+
|
|
67
|
+
def _options(self, plan):
|
|
68
|
+
run, grading = super()._options(plan)
|
|
69
|
+
if not self.idempotent and (run.trials > 1 or run.candidate_attempts > 1 or plan.parameters.get("resume") is not None):
|
|
70
|
+
raise LifecycleError("repeats, retries and resume require an explicit idempotent declaration or an advanced driver")
|
|
71
|
+
if run.reuse != "never" or plan.parameters.get("reuse") is not None:
|
|
72
|
+
raise LifecycleError("callable authoring does not implement verified reuse; use an explicit driver")
|
|
73
|
+
return run, grading
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _json_object(value):
|
|
77
|
+
_object(value, "authoring JSON object")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _coverage(record):
|
|
81
|
+
rows = [row for row in record["rows"] if row["failure"] is None]
|
|
82
|
+
assessments = [item for row in rows for item in row["output"]["assessments"]]
|
|
83
|
+
planned = len(record["run"]["definition"]["cases"]) * record["run"]["definition"]["policy"]["trials"]
|
|
84
|
+
return {"planned_trials": planned, "observed_trials": len(rows), "missing_trials": planned - len(rows),
|
|
85
|
+
"passing_assertions": sum(item["value"] is True for item in assessments),
|
|
86
|
+
"failed_assertions": sum(item["value"] is False for item in assessments),
|
|
87
|
+
"candidate_attempts": len(record["run"]["attempts"])}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def evaluation_suite(
|
|
91
|
+
suite_id: str, *, version: str, implementation_id: str,
|
|
92
|
+
cases: Mapping[str, Mapping[str, Any]], check: Callable[[EvaluatorContext], bool],
|
|
93
|
+
references: Mapping[str, Mapping[str, Any]] | None = None,
|
|
94
|
+
authorize_references: Callable[[str, Any], bool] | None = None, reference_access: Any = None,
|
|
95
|
+
input_schema: PayloadSchema | None = None, output_schema: PayloadSchema | None = None,
|
|
96
|
+
reference_schema: PayloadSchema | None = None, scope: str = "component",
|
|
97
|
+
run_policy: RunPolicy | None = None, idempotent: bool = False,
|
|
98
|
+
) -> Suite:
|
|
99
|
+
"""Build a versioned local assertion suite without hand-registering its parts.
|
|
100
|
+
|
|
101
|
+
Reference snapshots are caller-supplied private data. Dataset authorization
|
|
102
|
+
still precedes reference loading/validation into a grading context. All
|
|
103
|
+
functions run in the owner's Python process, so use an admitted isolated
|
|
104
|
+
driver for untrusted candidates or protected production references.
|
|
105
|
+
"""
|
|
106
|
+
for name, value in (("suite_id", suite_id), ("version", version), ("implementation_id", implementation_id)):
|
|
107
|
+
_text(value, name)
|
|
108
|
+
if not callable(check) or inspect.iscoroutinefunction(check) or inspect.iscoroutinefunction(getattr(check, "__call__", None)):
|
|
109
|
+
raise WorkflowContractError("check must be a synchronous evaluator-context callable")
|
|
110
|
+
if scope not in ("component", "subsystem", "system") or type(idempotent) is not bool:
|
|
111
|
+
raise WorkflowContractError("declare component/subsystem/system scope and a boolean idempotent flag")
|
|
112
|
+
inputs = _object(cases, "authoring cases")
|
|
113
|
+
if not inputs:
|
|
114
|
+
raise WorkflowContractError("evaluation_suite requires at least one input case")
|
|
115
|
+
if references is None:
|
|
116
|
+
if authorize_references is not None or reference_schema is not None or reference_access is not None:
|
|
117
|
+
raise WorkflowContractError("reference settings require a reference mapping")
|
|
118
|
+
refs = None
|
|
119
|
+
else:
|
|
120
|
+
if not callable(authorize_references):
|
|
121
|
+
raise WorkflowContractError("references require explicit authorize_references; no default grant is supplied")
|
|
122
|
+
refs = _object(references, "private authoring references")
|
|
123
|
+
if any(not isinstance(value, Mapping) for value in refs.values()):
|
|
124
|
+
raise WorkflowContractError("each private reference must be a JSON object")
|
|
125
|
+
if set(refs) != set(inputs):
|
|
126
|
+
raise WorkflowContractError("reference membership must match the complete case set")
|
|
127
|
+
registry = WorkflowRegistry()
|
|
128
|
+
def schema(role, supplied):
|
|
129
|
+
result = supplied or PayloadSchema(suite_id + "." + role + ".v1", version,
|
|
130
|
+
"sphynx.authoring.json-object.v1", _json_object)
|
|
131
|
+
if not isinstance(result, PayloadSchema):
|
|
132
|
+
raise WorkflowContractError(role + " schema must be PayloadSchema")
|
|
133
|
+
return result
|
|
134
|
+
input_schema, output_schema = schema("input", input_schema), schema("output", output_schema)
|
|
135
|
+
reference_schema = None if refs is None else schema("reference", reference_schema)
|
|
136
|
+
projection_schema = schema("report", None)
|
|
137
|
+
schemas = {}
|
|
138
|
+
for value in (input_schema, output_schema, reference_schema, projection_schema):
|
|
139
|
+
if value is None:
|
|
140
|
+
continue
|
|
141
|
+
existing = schemas.get(value.schema_id)
|
|
142
|
+
if existing is not None and (existing.to_dict() != value.to_dict() or existing.validator is not value.validator):
|
|
143
|
+
raise WorkflowContractError("one schema ID cannot name different validators/versions")
|
|
144
|
+
if existing is None:
|
|
145
|
+
registry.register_schema(value); schemas[value.schema_id] = value
|
|
146
|
+
rows = tuple(CaseView.validated(identifier, payload, schema=input_schema) for identifier, payload in inputs.items())
|
|
147
|
+
cohort = contract_digest({"cases": [row.to_dict() for row in rows]})
|
|
148
|
+
dataset = DatasetDefinition(suite_id + ".dataset", version, suite_id + ".provider", input_schema.schema_id,
|
|
149
|
+
None if reference_schema is None else reference_schema.schema_id,
|
|
150
|
+
selection={"membership": "all_declared_cases", "order": [row.case_id for row in rows]},
|
|
151
|
+
identity={"input_digest": cohort, "authority": "caller_owned_local_inputs"})
|
|
152
|
+
registry.register_provider(Dataset(dataset, input_schema, lambda selection: iter(rows),
|
|
153
|
+
reference_schema=reference_schema,
|
|
154
|
+
reference_loader=None if refs is None else lambda identifier: _thaw(refs[identifier]),
|
|
155
|
+
authorize_references=authorize_references))
|
|
156
|
+
criterion_id, evaluator_id = suite_id + ".check", suite_id + ".evaluator"
|
|
157
|
+
registry.register_criterion(Criterion(criterion_id, version, "The declared check returns True"))
|
|
158
|
+
def evaluate(context):
|
|
159
|
+
if context.metadata.get("candidate_failure") is not None:
|
|
160
|
+
raise WorkflowContractError("cannot check a failed candidate attempt; inspect its execution evidence")
|
|
161
|
+
value = check(context)
|
|
162
|
+
if type(value) is not bool:
|
|
163
|
+
raise WorkflowContractError("authoring check must return exactly True or False; use an explicit evaluator for other outputs")
|
|
164
|
+
return (Assessment(criterion_id, evaluator_id, context.case.case_id, "assertion", "available", value,
|
|
165
|
+
evidence_ids=tuple(item.evidence_id for item in context.evidence), run_id=context.run_id,
|
|
166
|
+
grading_id=context.grading_id, trial=context.metadata["trial"], attempt=context.metadata["attempt"]),)
|
|
167
|
+
registry.register_evaluator(EvaluatorDefinition(evaluator_id, version, implementation_id,
|
|
168
|
+
criterion_ids=(criterion_id,)), evaluate)
|
|
169
|
+
registry.register_projection(projection_schema.schema_id, lambda record: {
|
|
170
|
+
"schema_version": "sphynx.authoring.report.v1", "suite_id": suite_id,
|
|
171
|
+
"run_id": record["definition"]["run_id"], "grading_id": record["definition"]["grading_id"],
|
|
172
|
+
"scope": scope, "mode": "local", "candidate": record["run"]["definition"]["candidate_identity"],
|
|
173
|
+
"counts": _coverage(record)}, version="v1", implementation_id="sphynx.authoring.coverage.v1")
|
|
174
|
+
comparison_id = suite_id + ".comparison"
|
|
175
|
+
registry.register_policy(comparison_id, version="v1", implementation_id="sphynx.authoring.no-comparison.v1",
|
|
176
|
+
kind="comparison", callback=lambda left, right: {
|
|
177
|
+
"status": "unavailable", "reason": "No custom comparison policy selected; use the explicit registry path.",
|
|
178
|
+
"baseline_grading_id": left["definition"]["grading_id"], "candidate_grading_id": right["definition"]["grading_id"]})
|
|
179
|
+
definition = SuiteDefinition(suite_id, version, suite_id + ".backend", suite_id,
|
|
180
|
+
configuration={"input_digest": cohort, "output_schema": output_schema.to_dict(),
|
|
181
|
+
"idempotent": idempotent, "scope": scope, "authority": "local_unverified"},
|
|
182
|
+
criterion_ids=(criterion_id,), evaluator_ids=(evaluator_id,), datasets=(dataset,))
|
|
183
|
+
backend = _CallableBackend(registry, definition, driver=_CallableDriver(output_schema, idempotent),
|
|
184
|
+
evaluator_id=evaluator_id, projection_schema_id=projection_schema.schema_id,
|
|
185
|
+
comparison_policy_id=comparison_id, run_policy=run_policy, reference_access=reference_access,
|
|
186
|
+
scopes=(scope,), idempotent=idempotent)
|
|
187
|
+
registry.register_backend(backend); registry.register_suite(definition)
|
|
188
|
+
return Suite.from_registry(suite_id, registry=registry)
|