English · 한국어
vecscope
Embedding space evidence for agents.
Before an agent trusts a vector index, let it see the space it is searching.
Quick start · What it measures · Use with an agent · Use in CI · Usage · FAQ · Documentation
pip install vecscope
Agents build RAG pipelines, semantic search and recommendation retrieval, but cannot see the embedding space they search. Retrieval failures rarely look like bugs. They look like:
- "the same three chunks come back for everything"
- "every score is 0.8-something"
- "top-k is full of copies"
- "brute force finds it and HNSW does not"
Each has a known, deterministic diagnostic. vecscope turns them into one command and one
JSON: measurements, ok / warn / fail verdicts, and an explanation an agent can act on.
It runs locally on NumPy, with no model or network, and reports the same numbers every time.
vecscope diagnoses the vector search implementation: the model's geometry, corpus
hygiene, the distance metric, the index and the query pipeline. It does not measure
relevance, which needs labeled queries: a clean audit shows search is not sabotaging
retrieval, not that retrieval is good.
Quick start
1. Install
pip install vecscope
2. Get a file of embeddings
vecscope reads one embedding per row: the (n, dim) array a model's encode returns, saved as .npy, .parquet, .jsonl, .json or .csv
(all formats).
import numpy as np
embeddings = model.encode(texts) # shape (n, dim), e.g. (3000, 128)
np.save("embeddings.npy", embeddings)
No embeddings at hand? Generate three synthetic matrices (healthy, anisotropic, collapsed):
python -c "import urllib.request as u; u.urlretrieve('https://raw.githubusercontent.com/076923/vecscope/main/examples/make_examples.py', 'make_examples.py')"
python make_examples.py
3. Run the audit
vecscope audit embeddings.npy
vecscope x.y.z n=3000 dim=128 k=10 verdict=FAIL
[ok ] hubness skewness=1.1661 (ok < 2, warn >= 2, fail >= 4)
k-occurrence skewness 1.17; top 1% of items take 3.9% of all neighbor slots (max N_k=51, expected 10).
[WARN] antihubs antihub_excess=0.0523 (ok < 0.05, warn >= 0.05, fail >= 0.2)
5.2% of items are never anyone's neighbor (random data at k=10 would give 0.0%); the excess is unreachable through k-NN retrieval.
try: inspect a sample of never-retrieved items; drop empty inputs, then apply the hubness fix
[FAIL] anisotropy mean_random_cosine=0.8732 (ok < 0.5, warn >= 0.5, fail >= 0.85)
random pairs have mean cosine 0.873 (isotropic ~0); mean unit vector has norm 0.93; centering would bring the cosine to -0.000.
try: subtract the corpus mean vector and re-normalize, applying the same transform to queries; details.mean_random_cosine_after_centering shows the expected result
[ok ] effective_rank effective_rank_ratio=0.5407 (ok >= 0.1, warn < 0.1, fail < 0.05)
effective rank 69.2 of 128 attainable (128 dims; 54.1%); low values mean most dimensions carry nothing.
[ok ] collapse near_duplicate_ratio=0.0000 (ok < 0.02, warn >= 0.02, fail >= 0.1)
0.0% of items have a neighbor with cosine >= 0.99 or an exact copy (exact duplicates 0.0%); no row has a near-duplicate.
[ok ] rogue_dimensions top1_dim_variance_ratio=1.3070 (ok < 10, warn >= 10, fail >= 50)
dimension 94 alone holds 1.0% of variance, 1.3x the uniform share of 0.78%; top 3 dims hold 3.0%. Rogue dimensions dominate cosine.
[ok ] norms norm_cv=0.0000 (ok < 0.1, warn >= 0.1, fail >= 0.3)
vector norms vary with CV 0.000 (median 1.000, range 1.000-1.000); 0.00% are zero vectors. Unequal norms bias inner-product search toward long vectors.
[ok ] metric_mismatch topk_overlap=1.0000 (ok >= 0.9, warn < 0.9, fail < 0.7)
cosine and inner-product top-10 share 100.0% of neighbors; 100.0% of items get identical lists. Low overlap means the index metric changes the results.
[ok ] distance_concentration contrast_over_noise=2.2784 (ok >= 1.4, warn < 1.4, fail < 1.1)
on 3000 rows a random item is 3.27x farther than the nearest neighbor (random distance 0.127); isotropic noise at 128-d and the same rows would give 1.44x, so the contrast is 2.28x that of noise. On all rows the contrast is 3.27x (median NN distance 0.039). Near 1.0 means distances carry no signal.
[ok ] outliers outlier_ratio=0.0030 (ok < 0.01, warn >= 0.01, fail >= 0.05)
0.30% of items have no neighbor within cosine distance 0.050 (median 0.039); see details.sample_ids. Typically junk, empty or foreign-language content.
[ok ] connectivity island_ratio=0.0000 (ok < 0.01, warn >= 0.01, fail >= 0.1)
0.00% of items sit in 0 small island(s) of the k-NN graph (fewer than 15 items; 60 components in total). Graph-based ANN (HNSW) attaches islands to the wrong region or never reaches them.
4. Read the result
- The first line gives the overall
verdict: the worst among the findings. - Each finding shows the measured value, the
okrange, and what the number means for retrieval. Findings that are notokadd atry:line with the smallest change to test first. - The exit code is
1onFAIL, so the command works as a CI gate. --jsonprints the same evidence as JSON for an agent or a script.
What vecscope measures
| Finding | Metric | ok | warn | fail | What it means when it fails |
|---|---|---|---|---|---|
hubness |
skewness of the k-occurrence distribution | < 2.0 | 2.0 to 4.0 | ≥ 4.0 | a few items appear in everyone's k-NN list and will top every query |
antihubs |
share of items never retrieved as a neighbor, above the random baseline e^-k | < 5% | 5 to 20% | ≥ 20% | part of the corpus is unreachable through k-NN |
anisotropy |
mean cosine of random pairs | < 0.85 | 0.85 to 0.95 | ≥ 0.95 | vectors crowd into a narrow cone and scores compress into a band; good retrievers sit well below this without losing nDCG, so only extreme values are flagged |
effective_rank |
participation ratio of the covariance spectrum / attainable rank (dim, or rows − 1 when rows do not exceed dims) | ≥ 0.10 | 0.05 to 0.10 | < 0.05 | most dimensions carry nothing |
collapse |
share of rows with a neighbor at cosine ≥ 0.99 or an exact copy (zero vectors included); details give the duplicate groups and sample pairs | < 2% | 2 to 10% | ≥ 10% | top-k is spent on copies of the same item |
ann_recall |
recall@k of ANN neighbors vs exact k-NN, counted by distance so exact ties (duplicates) are interchangeable; tie slack 1e-6 + 2e-6 x distance, two to three times float32 rounding | ≥ 0.95 | 0.85 to 0.95 | < 0.85 | the index, not the model, is losing results |
rogue_dimensions |
variance of the largest dimension as a multiple of the uniform 1/dim share | < 10x | 10 to 50x | ≥ 50x | a few coordinates decide every cosine score |
norms |
coefficient of variation of vector norms | < 0.10 | 0.10 to 0.30 | ≥ 0.30 | inner-product search favors long vectors; zero vectors are reported too |
metric_mismatch |
top-k overlap between cosine and inner product | ≥ 0.90 | 0.70 to 0.90 | < 0.70 | the index metric changes which results come back |
distance_concentration |
relative contrast (random distance / nearest-neighbor distance) divided by that of isotropic noise at the same dimension and row count | ≥ 1.4 | 1.1 to 1.4 | < 1.1 | the nearest neighbor is barely closer than a random item; 1.0 is pure noise |
outliers |
share of items with an abnormally far nearest neighbor | < 1% | 1 to 5% | ≥ 5% | junk, empty or foreign items; ids are listed in details |
connectivity |
share of items in small k-NN graph islands | < 1% | 1 to 10% | ≥ 10% | self-contained groups too small to be clusters; HNSW attaches them badly or never reaches them |
query_gap |
median query-to-corpus nearest distance divided by the median corpus-to-corpus nearest distance | < 2.6 | 2.6 to 3.0 | ≥ 3.0 | queries and corpus do not share a space, typically queries embedded by a different model (5 to 10). Pipelines reproducing published nDCG@10 sit at 0.94 to 2.52; a missing query prefix does not reliably move it |
query_shift |
share of queries farther from the corpus than the median + 3 MAD of a reference query set (needs a baseline) | < 20% | 20 to 30% | ≥ 30% | the query pipeline moved since the reference: another model or version, or traffic on topics the corpus does not cover. Healthy query sets score 0 to 9% |
ood_queries |
deprecated, read query_gap: share of queries farther from the corpus than 99% of corpus items are from each other |
< 50% | 50 to 80% | ≥ 80% | same question as query_gap, but it also counts the normal distance between short queries and long passages (good models score 0 to 65% on BEIR) and false-alarms on 4 of 18 reproduced pipelines |
query_hubness |
skewness of corpus k-occurrence over query results | < 4.0 | 4.0 to 10.0 | ≥ 10.0 | the same few items answer most queries; tracks nDCG@10 across models (Spearman −0.5 to −0.9), wrong-language models score 11 to 30. Few queries over a large corpus raise it with no hub: a hub-free index scores (1−2p)/√(queries·p(1−p)), p = k/documents (details.null_skewness), and a level chance alone reaches is not judged (details.not_judged, with the queries needed) |
Every finding in the JSON carries healthy_range, warn_at, fail_at and a details block
with the raw numbers. For anisotropy it includes the cosine after centering, which shows
whether centering alone fixes the problem.
Some findings appear only when you pass their inputs:
ann_recall: an ANN neighbor file with--annquery_gap,query_hubnessandood_queries: query embeddings with--queriesquery_shift: query embeddings, plus--baselinepointing at an audit run with queries
Each finding also carries likely_causes, suggested_action and verify_by: hypotheses, not
prescriptions. Apply the smallest change to a copy, re-audit the copy with the original as
baseline, and adopt it only when baseline_diff.change_decision says adopt (labeled
retrieval did not drop and something improved). Without labels the decision is
needs_review, and a person decides. The
agent skill spells out
that loop.
Thresholds
The thresholds are defaults:
- calibrated on seven public models
- re-checked against 19 models on nine labeled datasets in two languages (verification)
- measured, unchanged, on 19 held-out public datasets with 14 models and on six injected
faults (held-out validation): 54 of 67 bad
pipelines end at
fail, but so do 26 of 114 good ones, mostly on text under 200 characters. The baseline diff catches faults the absolute verdict misses, so gate on the baseline and on retrieval tolerances
They are a starting point for diagnosis, not a universal quality bar: spaces differ by model,
language, domain and dimensionality, so a warn on a good model is normal.
On short or templated texts and narrow domains, pass the same rows embedded by a second good
public model as --reference: findings that model also reaches are attributed to the rows and
read ok (reference model).
With queries, a hub finding still at fail drops to warn when the reference returns at
least 40% of the pipeline's top results for the same queries; any other fail is the model's
own, and labeled queries decide its cost. On preregistered held-out data these rules cleared
15 of 21 good pipelines at fail and kept all 66 bad ones at fail.
Override any pair per run, or derive them from your data with
vecscope calibrate:
vecscope audit vectors.npy --thresholds my_thresholds.json
# my_thresholds.json: {"anisotropy.mean_random_cosine": [0.4, 0.7], "hubness.skewness": [2.5, 5]}
The keys are in src/vecscope/evidence.py (THRESHOLDS) and echoed in every JSON result
under thresholds.
Use with an agent
vecscope ships an MCP server with four read-only tools: audit_embeddings, sweep_index,
compare_embeddings and describe_findings. Register it with any MCP client:
pip install vecscope
claude mcp add vecscope -- vecscope-mcp --allow-dir /data/embeddings # Claude Code
Then ask:
Audit the embeddings in data/chunks.npy before we tune the retriever, and tell me
which finding to fix first.
The server reads only the directories named with --allow-dir (without it, the directory it
was started in). Use with an agent covers Cursor, Codex
and VS Code setup, the tools and tested clients. The agent skill tells the agent what to do about each verdict.
Use in CI
vecscope audit exits 1 on FAIL. Commit a reviewed --json run as the baseline, and the
build fails only when a finding gets worse:
vecscope audit embeddings.npy --json > baseline.json # once, reviewed and committed
vecscope audit embeddings.npy --baseline baseline.json # on every rebuild
Findings cannot see every break: a reindex that loses the id mapping leaves them unchanged. With labeled queries, also gate on retrieval quality so an nDCG drop fails the build:
vecscope audit embeddings.npy --queries q.npy --qrels qrels.json --baseline baseline.json \
--retrieval-tolerance ndcg_at_k=0.01
About 100 labeled queries catch nearly every injected fault that costs more than two nDCG points. Three more gates (CI):
--retrieval-confidence 0.95judges a labeled drop against the noise of the labeled queries: fail, pass or inconclusive.--result-sample 500 --result-tolerance 0gates a pipeline that must return the same results (a re-index, a refactor) on the results themselves. It measures change, not harm.--reference-tolerance 0.03needs no labels: with a reference model on the baseline, it flags a change whose net drop (lost minus gained) of the top hits the pipeline and the reference agreed on exceeds 0.03. On a preregistered unseen set it flagged 89% of injected faults costing more than 0.02 nDCG@10 and none of 81 harmless ones;reference_review(above 0.015) lists smaller drops. A flag means "check with labels"; no flag is no proof.
To change the embedding model, decide with labeled queries: without labels, 12 of 13 small losses between multilingual models of similar quality went unflagged (Changing the embedding model). How each rule was tested: Verification.
On GitHub the same gate is an Action:
- uses: 076923/vecscope@v0
with:
path: embeddings.npy
baseline: baseline.json
sample: "0"
Use in CI covers drift tolerances, the retrieval and result gates, which rule failed a run, and the Action's inputs and outputs.
FAQ
Does it send my vectors anywhere?
No. Everything runs with NumPy on your machine; it never loads a model or opens a network connection.
How large a matrix can it handle?
Exact k-NN is quadratic in the number of rows, so by default an input larger than 100,000 rows
is audited on a seeded random sample of that size, and the output says so (sampled: true,
n_total). A sample can miss rare clusters, small islands and a handful of outliers. Row ids
in details (sample_ids, sample_pairs, the cluster report) always refer to rows of the
input file. --sample 0 audits everything; see
performance for the cost.
--sample-repeats 3 (MCP: sample_repeats) audits three independent seeded samples, adds
value_range (minimum to maximum across samples) and verdict_stable to every finding, and
lists unstable_findings at the top level. Read a verdict that flips between samples as
borderline, not as a property of the corpus. The cost is three audits. value_range is the
spread between samples, not an interval that contains the full-corpus value: even a very
stable finding can sit a little outside it.
Findings also mean different things on a sample: hubness is understated (a lower bound on
every sample), outliers overcounted, islands mostly invisible. The
performance table says what each
finding can stand for and which verdicts a sampled audit marks inconclusive.
My production model fails the anisotropy check. Is the model broken?
Not necessarily. Many popular text embedding models are strongly anisotropic by construction.
The finding says raw cosine scores are compressed into a narrow band; centering, whitening or
re-ranking usually restores discrimination, and details reports the cosine after centering.
The verdict is evidence for the agent, not a grade for the model.
Which agents can use it?
Any agent that supports local MCP servers or can run a shell command and read JSON. The skill file describes both paths.
Documentation
- Documentation site: this README and the pages below, searchable
- Usage: queries and clusters, the index sweep, comparing two embeddings, vector stores, incremental audits, the library, CLI options and input formats
- Use with an agent: MCP setup per client, tools and responses, what the server may read, tested clients
- Use in CI: baselines, tolerances, the gate and the GitHub Action
- Retrieval quality and thresholds: the fix order, real embeddings, whether the findings predict nDCG, calibrating thresholds to your domain
- Performance: audit time and memory, sampled audits, how vecscope works
- Agent skill: when to run the audit and what to do with each verdict
- Retrieval-quality tables: every finding against nDCG@10 on labeled data
- Verification: exactness, recall scoring, the sampling claims, the query findings, interventions, agent integration, and 19 models on 9 labeled datasets
- Held-out validation: false positives and misses on 19 public datasets by language, document length, corpus size and domain, and what catches six injected faults
- Agent cases: an agent finding and fixing two ingestion faults, and a mis-tuned IVF index, over MCP, with the tool calls and numbers
- Examples: synthetic matrices, the calibration script and the retrieval-quality study
- Changelog
Contributing
Issues and pull requests are welcome. CONTRIBUTING.md covers running the tests and what a good change looks like; security reports go through SECURITY.md.
License
Metadata
Release files for vecscope 0.14.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 | Provenance | Actions |
|---|---|---|---|---|
| vecscope-0.14.0.tar.gz | 620.2 kB | With provenance | Details for vecscope-0.14.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vecscope-0.14.0-py3-none-any.whl | Python 3 | none | any | Details for vecscope-0.14.0-py3-none-any.whl |
Total release size: 745.8 kB
Release files / vecscope-0.14.0.tar.gz
| Download URL | vecscope-0.14.0.tar.gz |
|---|---|
| Size | 620.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ce4c1ca588fc4d1fe9b39dd6c647f137c29eb37feb3dc517b93db7390683894
|
|
BLAKE2b-256 checksum How to use checksums |
040e320c86cd518800aa6126a526f884875384bfafc3f34c03338227c13100ec
|
| 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 27, 2026.
Transparency logRelease files / vecscope-0.14.0-py3-none-any.whl
| Download URL | vecscope-0.14.0-py3-none-any.whl |
|---|---|
| Size | 125.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1ff15707bf1330a34836aa0c7abfe58e498afe903f404617ff0c62afbced307
|
|
BLAKE2b-256 checksum How to use checksums |
1a10d3a28fa5b6535cc0bb18e08bdca959fd752c8abdd56d833fd5f13f95e6a4
|
| 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 27, 2026.
Transparency logSecurity for vecscope 0.14.0
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 vecscope-0.14.0.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 27, 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.