esp32kb
Build an on-device knowledge base for the KB ESP32-P4 demo — a MiniLM-L3 embedding search that runs entirely on the board, with no PC attached at runtime.
Point the tool at a folder of markdown/text documents and it emits everything
the firmware flashes: sentence-aware chunks, INT8 embeddings, the packed
kb.img container (vectors + text + file index + WordPiece vocabulary) and
the tiny generated headers the sketch compiles against.
Install
uvx esp32kb --help # or: pip install esp32kb
# from a checkout:
uv run --project esp32kb esp32kb --help
Usage
# 1. documents -> kb.img + generated headers
esp32kb embed --root path/to/documents --sketch-dir path/to/Arduino/project
# 2. print the arduino-cli command that flashes app + model + kb.img
esp32kb flash --sketch-dir path/to/Arduino/project # then answer "y" to run it
Everything defaults relative to --sketch-dir (the current folder by default),
so the demo ships with its MiniLM-L3 model and one flag is enough.
esp32kb embed
| flag | default | meaning |
|---|---|---|
--root / -r |
required | folder with the documents to index (recursively) |
--output-folder / -o |
<sketch-dir>/model/kb |
where the .bin files and kb.img are written |
--sketch-dir / -s |
current folder | holds KB.ino/VectorSearch.h; kb_config.h and kb_queries.h go here |
--onnx |
<sketch-dir>/model/maskseq.onnx |
float32 MiniLM-L3 the PC embeds with |
--queries / -q |
sampled from the corpus | text file, one demo query per line |
esp32kb flash
| flag | default | meaning |
|---|---|---|
--sketch-dir / -s |
current folder | the sketch to compile |
--model |
<sketch-dir>/model/minilm_l3.espdl |
INT8 model to flash |
--kb |
<sketch-dir>/model/kb/kb.img |
knowledge base to flash |
--port / -p |
$PORT or /dev/ttyUSB0 |
serial port |
--fqbn |
P4 board spec | arduino-cli board spec |
--library |
$ARDUINO_LIBS |
extra Arduino library folder |
--yes / -y |
off | run without asking |
--print-only |
off | print the command and exit |
--port |
$PORT or /dev/ttyUSB0 |
serial port for the printed flash command |
--fqbn |
esp32p4 FQBN | board spec for the printed flash command |
The sequence length and embedding width are read straight from the ONNX model,
so the chunks, the INT8 vectors and the generated kb_config.h the
firmware compiles against can never disagree with the model. No flags to keep
in sync.
Pipeline
documents
-> chunks (<= seq-2 WordPiece tokens each)
-> MiniLM-L3 embeddings (masked mean pool, L2 normalized)
-> symmetric INT8 quantization, one global scale
-> vectors.bin / meta.bin / chunks.bin / files.bin / vocab.txt
-> kb.img single little-endian container with a section table
-> kb_config.h KB_SEQ / KB_DIM / KB_TOPK + container magics (C++ constants)
-> kb_queries.h KB_EXAMPLES[] example query texts for the sketch
The vocabulary travels inside kb.img, so the device tokenizes queries itself.
Additive attention mask
If the ONNX model exposes a second attention_mask input (the variant built
by model/export_onnx_mask.py), esp32kb feeds it the correct per-query
padding bias (0 on real tokens, negative on [PAD]). This preserves retrieval
quality at longer sequence lengths, where the frozen all-ones mask used by the
plain export otherwise collapses query embeddings. With the stock single-input
ONNX the behavior is unchanged.
Outputs
| file | contents |
|---|---|
vectors.bin |
32 B header + N × dim INT8 (16-byte aligned rows) |
meta.bin |
16 B header + N × 16 B records (file id, text offset/length) |
chunks.bin |
16 B header + concatenated UTF-8 chunk text |
files.bin |
16 B header + N × padded filename records |
vocab.txt |
WordPiece vocabulary, one token per line |
kb.img |
container: magic/version/section table + the payloads above |
kb_config.h |
KB_SEQ, KB_DIM, KB_TOPK and the container magics |
kb_queries.h |
KB_EXAMPLES[] example query texts for the sketch |
Metadata
Release files for esp32kb 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| esp32kb-0.1.0.tar.gz | 10.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| esp32kb-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.3 kB
Release files / esp32kb-0.1.0.tar.gz
| Download URL | esp32kb-0.1.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01f2eb8f24cc249b8e593dbc743afe6fe7afa008e1f2fb1dffb29a9959892122
|
|
BLAKE2b-256 checksum How to use checksums |
4ee223c96184a63bbba19cb6a4445a802cb607ce57446720fddb5aeafdbe989a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / esp32kb-0.1.0-py3-none-any.whl
| Download URL | esp32kb-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e992af014eb15496d8a0cb92c5a057e0091afe7d111f32bd377f3c74e00f7ca6
|
|
BLAKE2b-256 checksum How to use checksums |
b07cae401a3b37c518197e4196c8d45f6e5df59dad1921f1692c7671091938d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|