> ## Documentation Index
> Fetch the complete documentation index at: https://khaos-ml.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Core

> Loading artifacts, the registry, and pipelines.

## `khaos.load`

```python theme={null}
khaos.load(name: str, *, auto_download: bool = True) -> BasePipeline
```

Resolves an artifact and returns its pipeline.

**name** `str` *required*

A registered artifact name such as `pde_darcy_flow_2d`, or the path to a local artifact
directory containing a `manifest.json`.

**auto\_download** `bool` (default: True)

Download the artifact from the Hugging Face Hub when it is not in the local cache.
With `False`, a missing artifact raises `FileNotFoundError`.

| Raises | When |
| - | - |
| `KeyError` | `name` is not a registered artifact |
| `NotImplementedError` | the artifact is known but has no registered pipeline class (none today) |
| `FileNotFoundError` | the artifact is not cached and `auto_download=False`, or a directory has no `manifest.json` |
| `ValueError` | the manifest is missing `name` or `vertical` |

## `khaos.registry`

```python theme={null}
from khaos import registry
```

| Name | Description |
| - | - |
| `ARTIFACTS` | Dict mapping each of the 29 artifact names to its domain subpackage (`"chem_logp": "chem"`). |
| `register(name)` | Class decorator binding a `BasePipeline` subclass to an artifact name. |
| `artifact_dir(name) -> Path` | Local directory of an artifact: `<KHAOS_HOME>/<name>`. |
| `is_downloaded(name) -> bool` | True if that directory contains a `manifest.json`. |
| `download(name, revision=None) -> Path` | Fetch `<HUB_ORG>/khaos-<name>` from the Hugging Face Hub into the cache. |
| `CACHE_DIR` | Cache root. `~/.cache/khaos`, or `KHAOS_HOME` if set. |
| `HUB_ORG` | Hub namespace artifacts are pulled from. Defaults to `fletxcher`; set `KHAOS_HUB_ORG`. |
| `HUB_PREFIX` | Prefix of every repository name, `khaos-`. |

> [!NOTE]
>
> The repositories are public and need no token, for example
> [`fletxcher/khaos-chem_logp`](https://huggingface.co/fletxcher/khaos-chem_logp). Each holds
> `model.onnx`, `manifest.json`, the model card and, for text models, a `tokenizer/` folder.

## `khaos.pipeline`

```python theme={null}
from khaos.pipeline import BasePipeline, OnnxPipeline, ModalityProcessor
```

### `BasePipeline`

```python theme={null}
BasePipeline(manifest: Manifest, path: str | Path)
```

A loaded artifact. Call it on raw input to get a result.

| Member | Description |
| - | - |
| `manifest` | The artifact's [`Manifest`](https://khaos-ml.mintlify.site/api/artifacts). |
| `path` | The artifact directory. |
| `name` | `manifest.name`. |
| `parse_request(payload)` | Turns a decoded JSON body into pipeline input. Numeric lists become `float32` arrays; anything else passes through. Override it for other input shapes. |
| `__call__(raw)` | Abstract. Returns the result. |

### `OnnxPipeline`

```python theme={null}
OnnxPipeline(manifest: Manifest, path: str | Path)
```

A `BasePipeline` backed by an ONNX Runtime session.

| Member | Description |
| - | - |
| `providers` | Execution providers, `["CPUExecutionProvider"]` by default. |
| `session` | The `onnxruntime.InferenceSession`, created on first use from `manifest.files["model"]`. |
| `preprocess(raw)` | Abstract. Returns a dict of named input arrays matching the model's inputs. |
| `postprocess(outputs)` | Abstract. Receives the list of output arrays and returns the result. |
| `run(inputs)` | Runs the session and returns the list of outputs. |
| `__call__(raw)` | `postprocess(run(preprocess(raw)))`. |

## Input and result for each artifact

Every artifact is a registered `OnnxPipeline`: call it on the input below. Normalization
is inside the model, so raw physical or sensor values are fine. Over HTTP the same input goes in
the `input` field as JSON, with arrays as nested lists.

| Artifact | Input | Result |
| - | - | - |
| `sec_10k_core`, `sec_8k_events`, `sec_form4_insider`, `sec_s1_ipo` | filing text as a `str`, any length | `Doc(ents, vector)`: `ents` are dicts with `type`, `text`, `start`, `end`; `vector` is the mean window embedding |
| `pde_*` | dict: `x` (channels, 64, 64), plus `params` (n,) and `t` where the model takes them | `FieldResult(prediction)` with shape (output channels, 64, 64) |
| `robo_kinematics_sm` | joint trajectory, array (timesteps, 14), up to 1,024 steps | `TrajectoryEmbedding(vector)`, 128 values |
| `robo_skill_segmentation` | same | `SkillSegments(boundaries, labels)`: first step and skill name of each segment |
| `robo_failure_detection` | same | `FailureReport(score, stalled)`: highest failure probability, and whether 3 steps in a row passed the calibrated threshold |
| `geo_part_classifier` | points, array (N, 3) | `PartClassification(label, scores)` over the 40 ModelNet classes |
| `geo_pointcloud_embedding` | points, array (N, 3) | `ShapeEmbedding(vector)`, unit length, 256 values |
| `geo_mesh_embedding` | points with normals, array (N, 6), or a `trimesh` mesh, or a mesh file path | `ShapeEmbedding(vector)` |
| `tab_column_types` | table: dict of column to values, or a DataFrame | `TableResult(column_types, vector)` |
| `tab_key_matching` | `(left, right)` tables | `KeyMatches(matches)`: `(left column, right column, probability)` above the threshold, best first |
| `tab_entity_dedupe` | list of record dicts, or a DataFrame | `EntityClusters(clusters)`: row indices per entity, every row in one cluster |
| `tab_anomaly_scoring` | numeric table: array (at least 8 rows, up to 64 columns) | `AnomalyScores(scores)`, one per row, higher is more unusual |
| `tele_sensor_vibration` | window of 3,200 samples | `SignalResult(vector, anomaly_score)` |
| `tele_bio_ecg` | window of 2,048 samples | `SignalResult(vector, anomaly_score)` |
| `tele_regime_shift` | array (up to 8 channels, 512 samples) | `RegimeShifts(change_points)`: sample indices |
| `graph_node_embedding` | dict: `x` (nodes, 64) and `edge_index` (2, edges) or `adj` | `GraphEmbedding(vector)` with shape (nodes, 128) |
| `graph_subgraph_embedding` | same | `GraphEmbedding(vector)`, 128 values |
| `graph_fraud_rings` | same, plus optional `threshold` (default 0.5) | `FraudRings(rings, scores)`: connected groups of flagged nodes, best first |
| `graph_link_prediction` | same, plus optional `pairs` (n, 2) | `LinkPredictions(edges)`: `(source, target, probability)`; without `pairs`, all unconnected pairs ranked |
| `chem_mol_embedding` | SMILES string or list of them | `MoleculeEmbedding(vector)`, 256 values |
| `chem_logp`, `chem_solubility` | SMILES string or list | `PropertyPrediction({"logp": ...})` or `({"logS": ...})`, in real units |
| `chem_toxicity` | SMILES string or list | `PropertyPrediction` with 13 probabilities |

A list of SMILES returns a list of results. Input that does not fit raises `ValueError`
(HTTP 422). The chemistry pipelines need `khaos-ml[chem]`, the finance and entity-dedupe ones need
`transformers`, and a mesh file path needs `khaos-ml[3d]`.

```python theme={null}
import khaos

pipe = khaos.load("chem_logp")          # downloads fletxcher/khaos-chem_logp on first use
pipe("CC(=O)Oc1ccccc1C(=O)O")           # PropertyPrediction(properties={'logp': 1.29})
```

## Writing your own pipeline

A custom pipeline looks like this:

```python theme={null}
from khaos.physics.containers import FieldResult
from khaos.pipeline import OnnxPipeline
from khaos.registry import register


@register("pde_darcy_flow_2d")
class DarcyFlow(OnnxPipeline):
    def preprocess(self, raw):
        # raw: (4, 64, 64) channels: permeability, source, dirichlet mask and value
        return {"x": raw.astype("float32")[None]}

    def postprocess(self, outputs):
        return FieldResult(prediction=outputs[0][0])
```

### `ModalityProcessor`

An abstract class with a single `preprocess(raw)` method, for turning raw domain input into
model-ready tensors. Domain adapters implement it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.