Skip to content

fix(db): index the keyword projection by document, and drop the unread binary ANN indexes - #8105

Merged
waleedlatif1 merged 3 commits into
stagingfrom
chore/drop-binary-search-indexes
Sep 21, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
chore/drop-binary-search-indexes

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Missing index (the fix): the document ACL trigger from the projection source/ACL rollout fans a document's source and ACL out to embedding_keyword_tin by document_id, and that projection had no index on the column. Every document ACL or source change scanned the whole projection; on a large deployment that is seconds per document update, thousands of times a day, and it slows every connector sync and the projection backfill with it. Adds embedding_keyword_tin_document_idx concurrently, mirroring the index the GIN keyword projection already has
  • Unread indexes (the cleanup): drops the five binary-quantized HNSW indexes on embedding_search. Ranking walks the half-precision graphs and no code path orders by a hamming distance on this projection, so they were maintained on every chunk write for nothing; the populated one doubles the per-row cost of the projection backfill. Drops run CONCURRENTLY with the COMMIT breakpoint and lock-timeout handling the earlier index-drop migration uses
  • The binary columns stay: the projection sync trigger still writes them. Their contract-pending marker in the schema now says so

Type of Change

  • Bug fix

Testing

  • bun run check:migrations origin/staging passes (backward-compatible)
  • bun run lint and bun run check:audits pass
  • Grepped the search layer and schema for readers of the binary columns or indexes: none outside an integration test that asserts they are not used

Checklist

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

Ranking walks the half-precision graphs; nothing has ordered by a hamming distance on the projection since half-precision search shipped, so the five binary-quantized HNSW indexes were maintained on every chunk write for nothing, and the populated one doubled the per-row cost of filling the projection's source and ACL columns. Dropped concurrently; the binary columns stay until the sync trigger stops writing them.
@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Sep 21, 2026 4:30pm 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 4 files

Confidence score: 5/5

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

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the active half-precision search path remains indexed and the migration metadata is consistent.

Summary

This PR removes five unused binary-quantized HNSW indexes from the embedding_search projection while retaining the trigger-maintained binary columns.

  • Drops each index concurrently and replay-safely after leaving the migration transaction.
  • Removes the corresponding Drizzle schema declarations.
  • Adds matching migration journal and snapshot metadata.
  • Keeps the active half-precision cosine indexes and search path unchanged.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Source[Source embedding writes] --> Trigger[Projection sync trigger]
    Trigger --> Projection[embedding_search]
    Projection --> Binary[Binary columns retained]
    Projection --> Half[Half-precision vector columns]
    Binary -. five unused HNSW indexes dropped .-> Removed[Reduced index maintenance]
    Half --> Cosine[Cosine HNSW indexes retained]
    Cosine --> Search[Active ranking path]
Loading

Reviews (1) · Last reviewed commit: "chore(db): drop the unread binary ANN in..."

… trigger

The document ACL trigger updates the keyword projection by document id; the projection had no index on that column, so every document ACL or source change scanned the whole projection. Adds the index concurrently.
@waleedlatif1 waleedlatif1 changed the title chore(db): drop the unread binary ANN indexes on the search projection fix(db): index the keyword projection by document, and drop the unread binary ANN indexes Sep 21, 2026
@waleedlatif1
waleedlatif1 merged commit 6151605 into staging Sep 21, 2026
32 checks passed
@waleedlatif1
waleedlatif1 deleted the chore/drop-binary-search-indexes branch September 21, 2026 16:47

This branch was successfully deployed

1 active deployment
Preview 515a1c4a Deployed Sep 21, 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