# Memory Requirements for Needle 2 Inference: A Complete Technical Guide

> Discover Needle 2 inference memory requirements. Deploy on microcontrollers with 28MB RAM and a 14MB binary. Optimize edge devices with minimal memory.

- Repository: [Cactus Compute, Inc./needle](https://github.com/cactus-compute/needle)
- Tags: deep-dive
- Published: 2026-09-11

---

**Needle 2 inference requires approximately 28 MB of RAM during runtime and runs from a 14 MB binary, making it deployable on microcontrollers and edge devices with as little as 30 MB of available memory.**

Needle 2 is an open-source inference engine from the `cactus-compute/needle` repository designed specifically for offline deployment on memory-constrained hardware. Understanding the exact memory requirements for Needle 2 inference is critical for determining hardware compatibility and optimizing edge AI applications. The engine achieves its tiny footprint through a bounded memory design that maintains constant RAM usage regardless of conversation length.

## Engine Size and Binary Footprint

The entire Needle 2 model ships as a single binary file with a compact disk footprint.

- **Binary size:** The `.cact` engine file occupies approximately **14 MB** on disk.
- **Self-contained:** All weights and runtime components are packaged within this single file, eliminating external dependencies that could bloat deployments.

This 14 MB package downloads automatically on first use and contains everything required to initialize the inference engine without additional model files or network calls.

## Runtime Memory Usage

During active inference, Needle 2 maintains a remarkably stable memory profile through architectural constraints that prevent the memory growth typical of standard transformer models.

### Bounded Memory Architecture

The engine implements a **256-token sliding window** with tools pinned as KV-sinks, a design choice described in [`README.md`](https://github.com/cactus-compute/needle/blob/main/README.md) (lines 13-14) that caps memory consumption rather than allowing it to scale with context length. This bounded memory approach ensures that RAM usage remains constant at roughly **28 MB** regardless of how long the conversation continues.

### Peak Memory Consumption

As documented in [`doc/apis.md`](https://github.com/cactus-compute/needle/blob/main/doc/apis.md) (lines 11-13), the engine reports a **peak RAM usage of 28.5 MB** for a typical inference turn. For safe deployment, allocate approximately **30 MB of RAM** plus a small headroom buffer to account for system overhead and transient allocations during model initialization.

## Implementation Details

The constant memory guarantees are enforced through specific architectural components in the `cactus-compute/needle` codebase:

- **[`needle/model/run.py`](https://github.com/cactus-compute/needle/blob/main/needle/model/run.py)**: Implements the core inference loop and loads the `.cact` engine, containing the memory-bounded logic that enforces the sliding window constraints.
- **[`needle/_worker.py`](https://github.com/cactus-compute/needle/blob/main/needle/_worker.py)**: Manages a separate worker process that isolates each inference session, ensuring memory stays confined and preventing leaks between turns.
- **[`README.md`](https://github.com/cactus-compute/needle/blob/main/README.md)** (lines 13-14): Documents the bounded memory design and overall RAM targets.
- **[`doc/apis.md`](https://github.com/cactus-compute/needle/blob/main/doc/apis.md)** (lines 11-13): Records the actual peak memory measurements reported during testing.

These components collectively guarantee that the engine never exceeds its ~28 MB ceiling, even during extended operation.

## Running Inference on Constrained Devices

Needle 2 runs out-of-the-box on devices like the Raspberry Pi or microcontrollers with 64 MB of RAM. The following Python example demonstrates loading the engine and executing a query while staying under the 30 MB threshold:

```python
import needle

# Load the pre-baked 14 MB engine (downloaded automatically on first use)

agent = needle.Needle(weights="cactus-needle-2.cact", tools=[])

# Run a single turn – the engine stays under ~30 MB RAM

response = agent.run("What is the weather in Paris today?")
print(response["results"])

```

This minimal implementation works on constrained devices because the runtime never allocates beyond the established memory bounds, regardless of query complexity or conversation history.

## Summary

- **Disk requirement:** 14 MB for the `.cact` binary file.
- **Runtime RAM:** Approximately 28 MB constant usage through bounded memory design.
- **Peak usage:** 28.5 MB reported per typical inference turn.
- **Hardware minimum:** 30 MB RAM recommended for safe deployment.
- **Key mechanism:** 256-token sliding window with KV-sink tooling prevents memory growth.

## Frequently Asked Questions

### What is the minimum RAM needed to run Needle 2 inference?

Any device that can allocate approximately **30 MB of RAM** can run Needle 2 inference. While the engine typically consumes 28 MB during operation according to the source code in [`doc/apis.md`](https://github.com/cactus-compute/needle/blob/main/doc/apis.md), allowing 30 MB provides necessary headroom for initialization overhead and system processes.

### Does Needle 2 memory usage increase with longer conversations?

No. Needle 2 uses a **bounded memory design** featuring a 256-token sliding window that keeps RAM usage stable at roughly 28 MB regardless of conversation length. Unlike standard transformers that accumulate KV-cache indefinitely, Needle 2 pins tools as KV-sinks and maintains fixed memory allocation as implemented in [`needle/model/run.py`](https://github.com/cactus-compute/needle/blob/main/needle/model/run.py).

### How large is the Needle 2 model file?

The engine ships as a single **14 MB binary** (`.cact` format) as stored in `cactus-needle-2.cact`. This file contains the complete model weights and requires no additional downloads or external model repositories to function.

### Can Needle 2 run on microcontrollers?

Yes. The combination of a 14 MB binary and 28 MB runtime footprint allows Needle 2 to operate on microcontrollers and single-board computers with as little as 64 MB of total system RAM. The separate worker process in [`needle/_worker.py`](https://github.com/cactus-compute/needle/blob/main/needle/_worker.py) isolates memory usage, enabling fully offline inference without network connectivity.