Skip to content

fix(db): vacuum embedding_search at 2% churn so dead rows stop slowing KB search - #10477

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/embedding-search-autovacuum
Nov 28, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/embedding-search-autovacuum

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Set autovacuum_vacuum_scale_factor and autovacuum_vacuum_insert_scale_factor to 0.02 on embedding_search, matching embedding
  • Re-chunking a document deletes and re-inserts its embedding_search rows; at the inherited 20% default, autovacuum rarely triggers on this table, so dead versions accumulate for weeks and embedding_search_kb_idx keeps pointing at them
  • A knowledge base whose documents are re-uploaded often ends up with its filtered vector search visiting tens of times more index entries and heap pages than it has live rows, and retrieval runs past its time budget
  • Reverses 0440's choice to leave this table at the defaults. Going below 2% wouldn't clear dead index entries sooner: vacuum bypasses index cleanup while fewer than 2% of heap pages hold dead items, and each HNSW bulk-delete reads every index page several times, so index cost is fixed per run rather than proportional to dead rows
  • Keeps 0431's cost delay/limit, so each run stays rate-limited
  • ALTER TABLE ... SET takes SHARE UPDATE EXCLUSIVE (reads and writes don't wait on it; a running autovacuum is cancelled for it after deadlock_timeout, well under the runner's lock timeout); sets fixed values, so it's replay-safe after 0475's embedded COMMIT
  • Storage parameters aren't modeled in schema.ts, so the snapshot is unchanged from 0475

Type of Change

  • Bug fix

Testing

  • bun run check:migrations origin/staging passes
  • drizzle-kit generate reports no schema changes after the migration
  • Measured trigger cadence and per-run vacuum cost against current churn before choosing the factor

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 28, 2026 11:38am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Sets both autovacuum scale factors on embedding_search to 0.02 so vacuum can run sooner as rows change.

  • Autovacuum starts cleaning embedding_search after less churn.

Reviews (1) · Last reviewed commit: "fix(db): vacuum embedding_search at 2% c..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 155e03c into staging Nov 28, 2026
74 of 75 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/embedding-search-autovacuum branch November 28, 2026 11:41

This branch was previously deployed

1 inactive deployment
Preview — 42c7ce89 Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant