Skip to main content
Archil disks in AWS regions provide a built-in, high-performance search tool that’s effective for searching across millions of files on your disk, up to 10x faster than tools like ripgrep.
Patterns use ripgrep’s regular expression syntax, and the options below follow ripgrep’s flags, so a search you’d write with 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’s grep 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 the maxResults 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, pass globs, types, or typesNot.
  • globs follow ripgrep’s -g rules, matched against paths relative to directory. A leading ! excludes. A glob without a /, like *.log, matches a name at any depth; a glob with a /, like src/**/*.ts, matches the whole relative path. Use dir/** 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.
  • types searches only files of the given ripgrep file types, such as py, ts, go, or md. typesNot skips them, and takes precedence over types.
A file that a glob matches is searched or skipped by the glob, whatever its type.
When you search a workspace at its root, paths start with the mount name. A glob with a / 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

  • ignoreCase matches regardless of case, like rg -i.
  • multiline lets a match span lines, like rg -U. A \n in 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 as line and its last as endLine, and its text holds every line it covers. Matches on adjacent lines come back as one match.

Context lines

Pass contextBefore 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 stoppedReason set to max_results. Context lines count toward the limit, so large context and maxResults values 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 with globs or types to avoid it.

Next steps