Skip to main content

arrowspace_tuner

CI PyPI Python License

Hyperparameter discovery for ArrowSpace — automatically finds the best eps, k, and tau for your corpus using a query-free spectral objective.

Why

ArrowSpace's retrieval quality depends on three parameters:

Parameter What it controls
eps Neighbourhood radius for graph edges
k Number of nearest neighbours per node
tau Search temperature (query-time, tuned automatically)

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.

Install

# Core (no pandas/plotly)
pip install arrowspace-tuner

# With HTML/CSV reporting
pip install arrowspace-tuner[report]

Quickstart

import numpy as np
import arrowspace_tuner as arrowspace
from arrowspace_tuner import ArrowSpaceBuilder

embeddings = np.load("corpus.npy")   # shape (N, D) float64

# One-liner: auto-discover eps, k, tau — runs in ~15 min on 50k corpus
graph_params = arrowspace.tune(embeddings)
aspace, gl = ArrowSpaceBuilder().build(graph_params, embeddings)

# Search as normal
results = aspace.search(query_embedding, gl, tau=0.8)

[!WARNING] Upgrading from v0.3.x? optuna() is deprecated — use tune(). load_best_params() is deprecated — use load_graph_params(). EpsTuner.fit() now returns dict (graph_params), not (aspace, gl).

Power-user API

from arrowspace_tuner import EpsTuner, ArrowSpaceBuilder

tuner = EpsTuner(
    n_trials  = 15,
    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)
aspace, gl = ArrowSpaceBuilder().build(graph_params, embeddings)

print(tuner.best_params)    # {"eps": 1.615, "k": 38, "top_k": 19, "p": ..., "sigma": ...}
print(tuner.best_tau)       # 0.114  — query-time only, not in best_params
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 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.

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

Optuna + SQLite lets you run multiple workers simultaneously:

# Terminal 1
python -m arrowspace_tuner --storage sqlite:///tune.db --trials 15

# Terminal 2 (simultaneously)
python -m arrowspace_tuner --storage sqlite:///tune.db --trials 15

Requirements

  • Python ≥ 3.12
  • arrowspace >= 0.26.0
  • optuna >= 4.8.0
  • scipy >= 1.17.1
  • numpy >= 2.4.4

License

Apache-2.0 — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arrowspace_tuner-0.4.0.tar.gz (343.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arrowspace_tuner-0.4.0-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file arrowspace_tuner-0.4.0.tar.gz.

File metadata

  • Download URL: arrowspace_tuner-0.4.0.tar.gz
  • Upload date:
  • Size: 343.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","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}

File hashes

Hashes for arrowspace_tuner-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f4dcafcfb29ef250b10fdeffffa73f89f4324d71d4d19ddc4f31eea38b49b8a2
MD5 4b7942d876d1a82baf64418f84bcbce8
BLAKE2b-256 2c6f96c843ce34310932372874afd643fd5c473b1f80676553e89e89d4fb4e89

See more details on using hashes here.

File details

Details for the file arrowspace_tuner-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: arrowspace_tuner-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","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}

File hashes

Hashes for arrowspace_tuner-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8dbf80dc208c8d2aa5da4c60c3cf77e7525506d7706e578d33afe616451b883f
MD5 64ab706fb8bf10a560d70e13083779ba
BLAKE2b-256 baeace17e6d8f07a37332d5b9f71ebff2efa12d753cadcab70e5fa2d973a050e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.2

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page