tune-vector-index

tune-vector-index is a command for Claude Code from kumaran-is/claude-code-onboarding. It costs 52 tokens per session (1,123 once invoked), scanned A, original, MIT.

A command that recommends settings for HNSW or IVFFlat indexes in pgvector, a PostgreSQL extension for searching vector data.

In plain words
What is it for?
Use it to generate index SQL, an EXPLAIN ANALYZE template, and query settings from table size and latency requirements.
Why use it?
It helps balance search speed, memory use, and result quality when tuning a vector database index.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/kumaran-is/claude-code-onboarding/tune-vector-index
Clone the repo
git clone --depth 1 https://github.com/kumaran-is/claude-code-onboarding

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for tune-vector-index

README.md
[![agentmods](https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/tune-vector-index.svg)](https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/tune-vector-index)
Your own site
<a href="https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/tune-vector-index"><img src="https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/tune-vector-index.svg" alt="Measured on agentmods" height="20"></a>
Per session 52 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,123 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00052 $0.01123
Opus 5 $0.00026 $0.00562
Sonnet 5 $0.00010 $0.00225
Haiku 4.5 $0.00005 $0.00112

Measured 2d ago against content hash fec015b45c40, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

tune-vector-index scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/tune-vector-index.md · 132 lines

How it starts

The opening of the file, as written. The whole thing — 132 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Tune Vector Index

Recommend and generate an optimized pgvector index configuration.

Input: $ARGUMENTS (e.g., "vendors 250000 50ms IVFFlat")

Steps

  1. Load the vector-database skill — read SKILL.md and references/pgvector-migration-template.md for index parameter guidance.

  2. Gather requirements — Extract from $ARGUMENTS or ask:

    • Table name
    • Current row count (or estimate)
    • Target query latency (e.g., 50ms p95)
    • Current index type (IVFFlat / HNSW / none)
    • Distance metric (cosine / L2 / inner product)
    • Recall requirement (0.95 / 0.99 / best-effort)
  3. Query current index state if project has a database connection:

    SELECT indexname, indexdef, pg_size_pretty(pg_relation_size(indexname::regclass))
    FROM pg_indexes
    WHERE tablename = '{table}' AND indexdef ILIKE '%vector%';
    
  4. Select and tune index based on row count and latency target:

    Decision logic:

    row_count < 100K AND latency_ok_with_IVFFlat → IVFFlat (lower memory)
    row_count >= 100K OR recall >= 0.99 → HNSW
    Production (SLA < 100ms) → HNSW always
    

    HNSW parameter tuning:

    Target m ef_construction ef_search
    Fast (>100ms OK) 8 32 20
    Balanced (50-100ms) 16 64 40
    High recall (<50ms, recall>0.99) 32 128 80

    IVFFlat parameter tuning:

    Row count lists probes
    10K–100K sqrt(row_count) lists/10
    100K–1M row_count/1000 10
  5. Generate SQL:

    -- Drop existing index (if replacing)
    DROP INDEX CONCURRENTLY IF EXISTS {table}_embedding_idx;
    
    -- Create optimized index
    CREATE INDEX CONCURRENTLY {table}_embedding_{type}_idx
      ON {table} USING {hnsw|ivfflat} (embedding {ops_class})
      WITH ({params});
    
    -- Analyze after creation (IVFFlat: also after any bulk insert)
    ANALYZE {table};
    

    Note: CONCURRENTLY avoids table lock in production.

Read the full file on GitHub · 132 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 132 lines · 52 tokens per session scan A fec015b45c40

Subscribe to this mod's changes

tune-vector-index is a command published in the GitHub repository kumaran-is/claude-code-onboarding (35 stars, last pushed 2mo ago), licensed MIT. It adds 52 tokens to every session and 1,123 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.