> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archetypeai.app/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Start with /introduction/getting-started. Use the Direct Query API (POST /query) with the Newton Fusion model (text, image, and video reasoning) or the Newton Omega encoder (time-series embeddings). ATAI_API_ENDPOINT must include the version path: /v0.5 for most APIs, /v0.6 for the Fine-Tuning Service. Pages whose descriptions are marked (Archived) document the legacy Lens runtime — do not use them for new projects.

# Machine State Lens

> (Archived) Legacy Lens-based CLI example: classify machine states from time-series CSV data.

## Prerequisites

The instructions below assume you are following best practices and have downloaded this git repo into a parent directory at: \~/atai.
If you have already installed the [ATAI Python Library](https://github.com/archetypeai/python-client) and cloned the [cookbook repository](https://github.com/archetypeai/archetypeai-cookbook), proceed directly to [Quickstart](#quick-start).

<Note>
  Before proceeding, check the [requirements and correct Python version](https://docs.archetypeai.app/libraries/python#requirements) for the ATAI Python Library. To upgrade your Python client settings, please check our [Python Client library](https://docs.archetypeai.app/libraries/python#upgrade-python-client).
</Note>

#### Install Conda

```
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
bash Anaconda3-2022.05-Linux-x86_64.sh
source ~/.bashrc
```

#### Setup dev environment

```
conda create -n dev_env python=3.10
conda activate dev_env
```

#### Install [ATAI Python Library](https://github.com/archetypeai/python-client)

```bash theme={"system"}
git clone git@github.com:archetypeai/python-client.git
cd python-client
python -m pip install .
```

#### Clone [Cookbook Repository](https://github.com/archetypeai/archetypeai-cookbook)

```bash theme={"system"}
git clone https://github.com/archetypeai/archetypeai-cookbook.git
```

## Quick Start

Analyze time-series sensor data to classify machine states using few-shot learning with example patterns.

### Running the Demo

From the cookbook root directory with your conda environment activated:

```bash theme={"system"}
cd command-line-demos/machine-state
python quickstart.py
```

<Note>
  Sample CSV files are provided in the `sample_files/` directory, including a data file and example focus files for testing the demo.
</Note>

## Interactive Prompts

1. **API Endpoint**: Your ArchetypeAI API endpoint (press Enter to use the default)
2. **Data File**: Path to the CSV file containing sensor data to analyze
3. **Focus Files**: Paths to example CSV files for each state you want to classify. Type `done` when finished adding files.
4. **Window Size**: Number of data points per analysis window (default: 1024)
5. **Step Size**: Number of data points to advance between windows (default: same as window size)

## Example Session

```
=== Machine State Lens ===

Enter your API Endpoint (Press Enter for default):
Enter path to CSV to analyze: /Users/benxtan/Projects/ArchetypeAI/infer_sim5.csv

--- Add Focus Files ---
Provide CSV example(s) for each class (e.g., healthy.csv -> class 'healthy').
Type 'done' when finished.

Focus CSV path (or 'done'): /Users/benxtan/Projects/ArchetypeAI/healthy_sim5.csv
  Added: class 'healthy_sim5' from healthy_sim5.csv
Focus CSV path (or 'done'): done

Window size [default 1024]:
Step size   [default 1024]:

--- Configuration Summary ---
Lens ID:      lns-1d51909182270be2-bc1O8andqxf8b4os
API Endpoint: https://api.u1.archetypeai.app/v0.5
Data file:    /Users/benxtan/Projects/ArchetypeAI/infer_sim5.csv
Classes:      1
  - healthy_sim5: /Users/benxtan/Projects/ArchetypeAI/healthy_sim5.csv

Press Enter to start the analysis...
Session created: lsn-2b03144ecb0f022b5235b32734b308

Streaming...Press Ctrl+C to stop.

[1768401541.39556] -> Predicted class: ['healthy_sim5', {'healthy_sim5': 5}]
[1768401541.397359] -> Predicted class: ['healthy_sim5', {'healthy_sim5': 5}]
[1768401541.398611] -> Predicted class: ['healthy_sim5', {'healthy_sim5': 5}]
...
Stopped.
Session finished.
```

## Sample Data

The demo includes sample files in the `sample_files/` directory:

* `data.csv` - Sensor data to analyze
* `focus/healthy.csv` - Example of healthy machine state
* `focus/broken.csv` - Example of broken machine state

## Classification Tips

### Naming Convention

Class names are automatically derived from focus file names:

* `healthy.csv` creates class "healthy"
* `broken.csv` creates class "broken"
* `normal_operation.csv` creates class "normal\_operation"

## Window Size Configuration

The window size parameter determines how many data points Newton analyzes in each inference cycle. This affects the granularity of state classification.

### Recommended Settings

| Setting                              | Value   | Use Case                                 |
| ------------------------------------ | ------- | ---------------------------------------- |
| Default                              | 1024    | Optimal for most scenarios               |
| High-frequency sensors (above 100Hz) | 256–512 | Finer granularity for fast-sampling data |
| Low-frequency sensors (below 10Hz)   | 64–128  | Appropriate window for slower data       |
| Maximum                              | 1024    | Upper limit for window size              |

### How It Works

Each window represents a time segment of sensor data. The system compares these windows against your focus examples to classify the machine state. Non-overlapping windows (step size = window size) provide independent classifications, while overlapping windows offer smoother state transitions.

### Constraints

* Window size cannot exceed the length of your shortest focus file
* Minimum window size is 16 data points for meaningful analysis
