---
title: "float16 gives NaN or bad vectors"
lesson_id: "02"
---

# float16 gives NaN or bad vectors

- **Lesson ID:** 02
- **Goal:** Keep NaN and bad-precision vectors out of the index.
- **Human lesson:** [02-number-format-and-nan.html](02-number-format-and-nan.html)

## Prerequisites

- Lesson 01 server running.

## Inputs, outputs, and artifacts

- **Inputs:** Vectors from the embedding runtime.
- **Outputs:** Vectors that pass `check_vectors`, or a clear error.
- **Artifacts:** `index_guard.py`.

## Agent build steps

1. Pick bfloat16 or float32 for any runtime you control. Never float16.
2. Save `index_guard.py` from the lesson.
3. Call `check_vectors` on every batch before storing it.
4. Log and stop on NaN or non-unit vectors.

## Constraints

Keep the language simple, friendly, and literal. No quizzes, no em dashes. Brand Edge FDE only. Use small local models. Do not invent flags, endpoints, or issue numbers. 

## Key concepts

- EmbeddingGemma 2 activations overflow `float16`.
- `float16` gives NaN or quietly worse vectors, not an error.
- `bfloat16` and `float32` are safe.
- A check before storing catches NaN and wrong length.

## Takeaways

- Never run EmbeddingGemma 2 in `float16`.
- Use `bfloat16` where supported, else `float32`.
- Run `check_vectors` before every write to the index.

## Acceptance checks

- The float16 rule cites the model card.
- `check_vectors` raises on NaN and on non-unit vectors.
- The PyTorch path is marked as not run on the test box.
- [ ] Proceed to [lesson 03 brief](03-truncate-and-keep-one-model.llms.md).
