mgrep-code-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

mgrep Code Search

mgrep代码搜索

Overview

概述

mgrep is a semantic search tool that enables natural language queries across code, text, PDFs, and images. It is particularly effective for exploring larger or complex codebases where traditional pattern matching falls short.
mgrep是一款语义搜索工具,支持对代码、文本、PDF和图片进行自然语言查询。在探索大型或复杂代码库时,它的表现尤为出色,而传统的模式匹配工具在这类场景中往往力有不逮。

When to Use This Skill

何时使用该技能

Use mgrep when:
  • The codebase contains more than 30 non-gitignored files
  • There are nested directory structures
  • Searching for concepts, features, or intent rather than exact strings
  • Exploring an unfamiliar codebase
  • Need to understand "where" or "how" something is implemented
Use traditional grep/ripgrep when:
  • Searching for exact patterns or symbols
  • Regex-based refactoring
  • Tracing specific function or variable names
在以下场景使用mgrep:
  • 代码库包含30个以上未被git忽略的文件
  • 存在嵌套目录结构
  • 搜索概念、功能或意图,而非精确字符串
  • 探索不熟悉的代码库
  • 需要了解某项功能的“实现位置”或“实现方式”
在以下场景使用传统grep/ripgrep:
  • 搜索精确模式或符号
  • 基于正则表达式的重构
  • 追踪特定函数或变量名称

Quick Start

快速开始

Indexing

索引

Before searching, start the watcher to index the repository:
bash
bunx @mixedbread/mgrep watch
The
watch
command indexes the repository and maintains synchronisation with file changes. It respects
.gitignore
and
.mgrepignore
patterns.
搜索前,启动观察器以索引代码库:
bash
bunx @mixedbread/mgrep watch
watch
命令会索引代码库,并与文件变更保持同步。它会遵循
.gitignore
.mgrepignore
中的规则。

Searching

搜索

bash
bunx @mixedbread/mgrep "your natural language query" [path]
bash
bunx @mixedbread/mgrep "你的自然语言查询" [路径]

Search Commands

搜索命令

Basic Search

基础搜索

bash
bunx @mixedbread/mgrep "where is authentication configured?"
bunx @mixedbread/mgrep "how do we handle errors in API calls?" src/
bunx @mixedbread/mgrep "database connection setup" src/lib
bash
bunx @mixedbread/mgrep "认证配置在哪里?"
bunx @mixedbread/mgrep "我们如何处理API调用中的错误?" src/
bunx @mixedbread/mgrep "数据库连接设置" src/lib

Search Options

搜索选项

OptionDescription
-m <count>
Maximum results (default: 10)
-c, --content
Display full result content
-a, --answer
Generate AI-powered synthesis of results
-s, --sync
Update index before searching
--no-rerank
Disable relevance optimisation
选项描述
-m <count>
最大结果数(默认:10)
-c, --content
显示完整结果内容
-a, --answer
生成AI驱动的结果摘要
-s, --sync
搜索前更新索引
--no-rerank
禁用相关性优化

Examples with Options

带选项的示例

bash
undefined
bash
undefined

Get more results

获取更多结果

bunx @mixedbread/mgrep -m 25 "user authentication flow"
bunx @mixedbread/mgrep -m 25 "用户认证流程"

Show full content of matches

显示匹配结果的完整内容

bunx @mixedbread/mgrep -c "error handling patterns"
bunx @mixedbread/mgrep -c "错误处理模式"

Get an AI-synthesised answer

获取AI生成的摘要答案

bunx @mixedbread/mgrep -a "how does the caching layer work?"
bunx @mixedbread/mgrep -a "缓存层如何工作?"

Sync index before searching

搜索前同步索引

bunx @mixedbread/mgrep -s "payment processing" src/services
undefined
bunx @mixedbread/mgrep -s "支付处理" src/services
undefined

Workflow

工作流程

  1. Start watcher (once per session or when files change significantly):
    bash
    bunx @mixedbread/mgrep watch
  2. Search semantically:
    bash
    bunx @mixedbread/mgrep "what you're looking for" [optional/path]
  3. Refine as needed using path constraints or options:
    bash
    bunx @mixedbread/mgrep -m 20 -c "refined query" src/specific/directory
  1. 启动观察器(每次会话启动一次,或在文件大幅变更时启动):
    bash
    bunx @mixedbread/mgrep watch
  2. 进行语义搜索
    bash
    bunx @mixedbread/mgrep "你要查找的内容" [可选/路径]
  3. 根据需要优化:使用路径约束或选项:
    bash
    bunx @mixedbread/mgrep -m 20 -c "优化后的查询" src/specific/directory

Environment Variables

环境变量

Configure defaults via environment variables:
VariablePurpose
MGREP_MAX_COUNT
Default result limit
MGREP_CONTENT
Enable content display (1/true)
MGREP_ANSWER
Enable AI synthesis (1/true)
MGREP_SYNC
Pre-search sync (1/true)
可通过环境变量配置默认值:
变量用途
MGREP_MAX_COUNT
默认结果限制数
MGREP_CONTENT
启用内容显示(1/true)
MGREP_ANSWER
启用AI摘要生成(1/true)
MGREP_SYNC
搜索前同步索引(1/true)

Important Notes

重要说明

  • Always use
    bunx @mixedbread/mgrep
    to run commands (not npm/npx or direct installation)
  • Run
    bunx @mixedbread/mgrep watch
    before searching to ensure the index is current
  • mgrep respects
    .gitignore
    patterns automatically
  • Create
    .mgrepignore
    for additional exclusions
  • 请始终使用
    bunx @mixedbread/mgrep
    运行命令(不要使用npm/npx或直接安装)
  • 搜索前运行
    bunx @mixedbread/mgrep watch
    以确保索引是最新的
  • mgrep会自动遵循
    .gitignore
    规则
  • 可创建
    .mgrepignore
    文件添加额外的排除规则