ripgrep.
rg carries over.
Teams building the highest-performance AI agents have discovered that agent performance degrades
as you give them more tools to select between at each turn. As a result, teams are increasingly moving
away from specialized products like vector databases for context and towards lowest-common denominator
infrastructure like file storage. However, existing file system tools like grep are too slow for
searching across large document sets.
With Archil’s built-in grep APIs, you can effectively search across millions of documents on your
disk using map-reduce inside of Archil.
Each disk.grep() request counts as one serverless tool call, regardless of worker count or runtime.
See Pricing & Billing.
Managing concurrency
Archil’sgrep API works by performing a massively parallel search across the files stored in
the folder that you’re searching. Archil automatically manages the concurrency of each search to
optimize for search latency. If you’d prefer to control this concurrency manually, you can specify
the exact number of workers to use via the concurrency option.
TypeScript
Limiting work
For some kinds of search, you do not need an exhaustive set of results. For example, if you’re trying to find the first occurrence of an error, you only need one result. You can manage the amount of work that Archil’s search performs by specifying either themaxResults or maxDurationSeconds options.
When these options are specified, the search will stop as soon as the result or time limit is reached,
regardless of whether the search was exhaustive. Check stoppedReason in the result: completed means every file was
searched, and anything else means the matches may be partial. When a search stops early, its matches are a sample of
whichever workers reported first, not the first matches in path order.
Filtering files
To search only some files under the directory, passglobs, types, or typesNot.
globsfollow ripgrep’s-grules, matched against paths relative todirectory. A leading!excludes. A glob without a/, like*.log, matches a name at any depth; a glob with a/, likesrc/**/*.ts, matches the whole relative path. Usedir/**for the files under a directory. If you pass any glob without a!, files that match none of them are skipped. When several globs match a path, the last one wins.typessearches only files of the given ripgrep file types, such aspy,ts,go, ormd.typesNotskips them, and takes precedence overtypes.
/ must start with a mount name, like data/src/**, or with **/. Mount names in globs are matched literally:
!logs skips the logs mount, but !l* does not.
Matching options
ignoreCasematches regardless of case, likerg -i.multilinelets a match span lines, likerg -U. A\nin the pattern matches a line break, and.matches one only after(?s). Files with Windows line endings need\r?\n. A multiline match reports its first line aslineand its last asendLine, and itstextholds every line it covers. Matches on adjacent lines come back as one match.
Context lines
PasscontextBefore or contextAfter (0 to 10 lines each) to get the lines around each match, like rg -B and
rg -A. The result then includes groups: runs of consecutive lines from one file, in which each line is marked as a
match or as context. Nearby matches share a group, so every line appears once. matches still lists the matches on
their own.
Result limits
- A search returns at most 32 MiB of match and context text. A search that reaches this limit stops with
stoppedReasonset tomax_results. Context lines count toward the limit, so large context andmaxResultsvalues multiply the response size. - Each line is truncated at 512 KiB.
- Each worker returns at most 4 MiB of output. A batch of files that produces more is cut short, and the search reports
incomplete. Narrow the search withglobsortypesto avoid it.
Next steps
- TypeScript SDK: searching files — the
disk.grepAPI surface - Python SDK: searching files — the
Disk.grepAPI surface - API reference: Search Files — the raw HTTP endpoint
- Serverless execution — run arbitrary commands when you need more than search