arrowspace_tuner
Hyperparameter discovery for ArrowSpace — automatically finds eps and k for your corpus using a query-free spectral objective, with optional quality-first low-k refinement.
Version 0.30.1 targets the 0.30.x compatibility line of ArrowSpace
(>=0.30.0,<0.31). Major/minor numbers track ArrowSpace compatibility; tuner
patch revisions are independent. This is compatibility-aligned versioning, not
a promise of API compatibility between tuner patches. See
0.30.1 release notes for the breaking tau removal.
Why
The tuner searches two graph-building parameters:
| Parameter | What it controls |
|---|---|
eps |
Neighbourhood radius for graph edges |
k |
Number of nearest neighbours per node |
Setting these by hand is tedious and corpus-dependent. arrowspace_tuner uses Optuna and a label-free spectral MRR proxy to find them automatically in minutes.
Retrieval scoring uses a fixed internal temperature. Query-time temperature remains the caller's choice; it is not optimized or returned.
Install
# Core (no pandas/plotly)
pip install arrowspace-tuner
# With HTML/CSV reporting
pip install arrowspace-tuner[report]
# With the local stdio MCP server for LLM clients
pip install "arrowspace-tuner[mcp]"
Quickstart
Executable versions of these snippets live in
examples/quickstart.py and
examples/power_user.py, and are run on every
CI build.
import numpy as np
import arrowspace_tuner
from arrowspace import ArrowSpaceBuilder # builder comes from `arrowspace`
embeddings = np.load("corpus.npy") # shape (N, D) float64
# One-liner: auto-discover eps and k — runs in ~15 min on 50k corpus
graph_params = arrowspace_tuner.tune(embeddings)
# The caller owns the build step
aspace, gl = ArrowSpaceBuilder().build(graph_params, embeddings)
# Search as normal — tau is a query-time parameter
results = aspace.search(query_embedding, gl, tau=0.8)
Graph parameters
graph_params:
Build-time parameters only.
Expected native ArrowSpace keys:
eps, k, topk, p, sigma.
Every public result dictionary — from tune(), EpsTuner.fit(),
EpsTuner.graph_params, and load_graph_params() — uses the bindings-native
topk key and can be passed verbatim to ArrowSpaceBuilder().build().
Only eps and k are optimized. Retrieval scoring uses fixed internal tau=0.5;
no optimized search temperature is returned.
Prefer smaller graphs
graph_params = arrowspace_tuner.tune(
embeddings,
n_trials=15,
selection_policy="lowest_k",
refinement_trials=8, # extra attempts beyond n_trials
score_tolerance=0.0,
)
The extra phase explicitly explores smaller k and higher eps, including
k_low at eps_high, plus full-range eps exploration. This is a heuristic,
not an assumed inverse eps/k relationship. Select the smallest evaluated k
whose composite score is at least the best score minus score_tolerance.
Zero means exact score ties; positive tolerance is an absolute score difference,
not a percentage. There is no global minimum-k guarantee. If the main winner
already has k_low, refinement is skipped.
best_score remains the default policy (no refinement or tolerance).
lowest_k requires a positive explicit refinement_trials budget.
tuner.selection and structured CLI/MCP results describe the selected trial,
raw-score winner, gap, and requested/actual refinement attempts.
Optuna's study.best_trial still means the raw-score winner.
Migration: tau bounds and the separate best_tau result have been removed. Use a new study for old tau-optimized runs; incompatible evaluation contracts are rejected before adding trials. Existing saved graph parameters remain loadable.
Power-user API
Executable version: examples/power_user.py.
from arrowspace import ArrowSpaceBuilder
from arrowspace_tuner import EpsTuner
tuner = EpsTuner(
n_trials = 15,
seed = 42,
sample_n = 50_000,
eps_low = 0.8,
eps_high = 10,
k_low = 15,
k_high = 40,
n_probe = 50,
storage = "sqlite:///tune.db", # resume interrupted runs
)
graph_params = tuner.fit(embeddings)
# The caller owns the build step
aspace, gl = ArrowSpaceBuilder().build(graph_params, embeddings)
print(graph_params) # {"eps": 1.615, "k": 38, "topk": 19, "p": ..., "sigma": ...}
print(tuner.best_score) # 2.138
print(tuner.best_fiedler) # 0.718 — graph connectivity health
print(tuner.best_mrr_proxy) # 2.896 — retrieval coherence proxy
# Access graph params without file I/O
print(tuner.graph_params) # same dict as best_params, raises RuntimeError before .fit()
# Save CSV + HTML plots (requires [report] extra)
tuner.save_report(out_dir="results")
The final build after the study always uses the full corpus.
CLI
The arrowspace-tuner command (also available as python -m arrowspace_tuner)
runs the same tuning engine against local embedding files:
pip install "arrowspace-tuner[mcp]"
arrowspace-tuner tune corpus_embeddings.npy \
--trials 15 \
--selection-policy lowest_k \
--refinement-trials 8 \
--format json \
--output tuning_result.json
Validate the input first — invalid matrices fail before tuning with exit code 3:
arrowspace-tuner validate corpus_embeddings.npy --format json
Other commands: inspect RESULT.json (re-read a written TuneResult),
version, and mcp. Run arrowspace-tuner --help for every option.
Exit codes: 0 ok · 2 CLI usage error · 3 invalid input · 4 tuning
failed (all trials pruned) · 5 requested output or report could not be
written · 6 interrupted · 7 unexpected internal error.
Reports
--save-report requires --report-dir.
If report generation fails, the command returns exit code 5 and, in JSON
mode, returns status: "output_error". No successful tuning result is emitted
for a requested report that could not be persisted.
Small corpora
The valid upper bound for k is n_items - 1.
- If
k_highexceeds that value, the CLI clips it and returns a warning. - If
k_lowexceeds that value, the CLI rejects the request before tuning.
Build with the result:
import json
import numpy as np
from arrowspace import ArrowSpaceBuilder
embeddings = np.load("corpus_embeddings.npy")
result = json.load(open("tuning_result.json"))
aspace, gl = ArrowSpaceBuilder().build(
result["graph_params"],
embeddings,
)
hits = aspace.search(
query_embedding,
gl,
tau=0.5, # caller-selected query-time setting
)
JSON output for automation
In JSON mode, stdout always contains exactly one JSON result object, whether the operation succeeds or fails. stderr contains logs and optional human-readable diagnostics only; it never contains a second JSON envelope.
--format json prints exactly one JSON document on stdout; logs, warnings,
and progress go to stderr only, so the stream is safe to pipe. The schema
(schema_version: "1.0") is stable:
{
"schema_version": "1.0",
"status": "ok",
"graph_params": {"eps": 1.615376, "k": 38, "topk": 19, "p": 2.0, "sigma": null},
"best_score": 2.138421,
"n_trials_complete": 12,
"n_trials_pruned": 3,
"elapsed_seconds": 84.27,
"input_info": {"path": "corpus_embeddings.npy", "sha256": "9d4b…"},
"error_code": null,
"error_message": null
}
Guarantees: graph_params uses the native topk key (never top_k) and
never contains tau; no best_tau field is returned; failures
also print valid JSON (status: "validation_error" | "tuning_error" | "output_error", with error_code and error_message) and exit non-zero;
a declared output failure never carries a partial graph configuration.
--output writes the same document atomically (temp file + fsync + atomic
replace).
MCP server
arrowspace-tuner mcp starts a local stdio MCP server for LLM clients
(requires the mcp extra). It calls the same shared service as the CLI —
never a subprocess — and exposes exactly four tools:
inspect_embeddings, tune_graph, build_instruction, and
get_tuner_info.
{
"mcpServers": {
"arrowspace-tuner": {
"command": "arrowspace-tuner",
"args": ["mcp"],
"env": {
"ARROWSPACE_TUNER_ALLOWED_ROOTS": "/workspace:/data"
}
}
}
}
See examples/mcp_usage.md and
examples/mcp_config.json.
Security model for MCP
- The server runs locally over stdio; it makes no network requests and accepts no remote URLs.
- Embeddings are read only from
.npy/.npzfiles under explicitly configured roots (ARROWSPACE_TUNER_ALLOWED_ROOTS, mandatory — the server refuses to start without it). Symlinks escaping a root, relative paths, pickle/object arrays, and files aboveARROWSPACE_TUNER_MAX_INPUT_BYTES(default 2 GiB) are rejected. ARROWSPACE_TUNER_MAX_TRIALS(default 100) andARROWSPACE_TUNER_MAX_N_JOBS(default 4) cap tuning requests before Optuna starts. All MCP environment limits must be positive integers. Zero and negative values are invalid server configuration.- No embedding data is uploaded; reports are written only when explicitly requested, beneath an allowed root, and never overwrite an existing report directory.
Objective
The objective is a weighted composite of three spectral signals — no ground-truth labels required:
score = 0.70 * mrr_top0_spectral # retrieval coherence
+ 0.20 * log1p(fiedler) # graph connectivity health
+ 0.10 * log1p(var_lambda) # spectral richness
Parallel runs
Use in-process workers for parallel trial evaluation:
tuner = EpsTuner(n_trials=30, n_jobs=4)
graph_params = tuner.fit(embeddings)
Use n_jobs=1 for reproducible trial scheduling. Concurrent processes must not
share a study during phase orchestration; unfinished studies are rejected on
resume. Compatible completed studies can be resumed sequentially.
Requirements
- Python ≥ 3.12
arrowspace >= 0.30.0, < 0.31— tested with 0.30.0optuna >= 4.8.0scipy >= 1.17.1numpy >= 2.4.4
License
Apache-2.0 — see LICENSE.
Metadata
Release files for arrowspace-tuner 0.30.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| arrowspace_tuner-0.30.1.tar.gz | 369.5 kB | With provenance | Details for arrowspace_tuner-0.30.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| arrowspace_tuner-0.30.1-py3-none-any.whl | Python 3 | none | any | Details for arrowspace_tuner-0.30.1-py3-none-any.whl |
Total release size: 420.1 kB
Release files / arrowspace_tuner-0.30.1.tar.gz
| Download URL | arrowspace_tuner-0.30.1.tar.gz |
|---|---|
| Size | 369.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f98c07aad872a319411c6bf49447ab7eed9aa5ff560d2612391650eb1e43c2e
|
|
BLAKE2b-256 checksum How to use checksums |
0dafba25b1f0266f5ac97cc770053b0b1e5378bce8f51b72831f96adc5ae169e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / arrowspace_tuner-0.30.1-py3-none-any.whl
| Download URL | arrowspace_tuner-0.30.1-py3-none-any.whl |
|---|---|
| Size | 50.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9858365eada9b41214e3dd693ef32cb09bd5bdbf96360b9a9671b3c65f5d96e
|
|
BLAKE2b-256 checksum How to use checksums |
26287e0ec6453975d505165b3c11266b71370c4fa65617f13a2241f2c74b891e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for arrowspace-tuner 0.30.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for arrowspace_tuner-0.30.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.