CursorVicent MartiExplainer
Fast regex search: indexing text for agent tools
Summary
Agentic coding has revived grep as a critical way to gather source-code context, but ripgrep can stall on large monorepos because it scans every file. The proposed remedy is a local inverted index of overlapping character trigrams, with regular expressions parsed into required and alternative trigram constraints that narrow candidate files before exact matching. The index stores posting lists in one disk file and a sorted hash-to-offset lookup table in another, memory-mapping only the table for binary-search lookups; hash collisions can broaden results but cannot produce incorrect ones. Freshness is prioritized because agents often search for text they have just written, and the client index layers user and agent changes over a Git commit. The reported conclusion is that instant local search creates qualitative workflow improvements, especially for bug investigation and large Enterprise repositories.
Context
Agentic coding frequently relies on regular-expression searches, while ripgrep latency grows with repository size because it must inspect all files. The excerpt says large monorepos can produce searches taking more than 15 seconds, stalling workflows, particularly for large Enterprise repositories.
Approach / What changed
Create a fresh, client-side inverted index built from overlapping character trigrams. Parse regular expressions into trigram constraints, use posting lists to narrow candidate files, and store postings separately from a sorted hash-to-offset lookup table that is memory-mapped for binary-search queries. Base the index on a Git commit and layer user and agent changes on top for efficient synchronization.
Takeaways
Trigrams are used as inverted-index tokens because bigrams create very large posting lists, while quadgrams create billions of possible keys; trigrams provide a middle ground.
Hashing n-grams in the lookup table saves space: a collision may broaden a posting list, but the excerpt states it cannot produce incorrect results.
Fresh local indexing matters more for regex search than semantic indexing because failing to find text that an agent just wrote can trigger wasted tokens and a misleading investigation.
Source and freshness
- Source
- cursor.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.