关于 grepai-search-tips
grepai-search-tips 介绍如何为 GrepAI 编写语义搜索查询,帮助开发者按行为或意图查找代码、逐步优化结果,并区分语义搜索与精确文本搜索。
主要功能
- 01围绕意图组织查询
- 02为搜索补充描述性上下文
- 03逐步优化查询
- 04使用同义词和问句式查询
- 05理解结果相关性分数
适用场景
- 01不知道函数名时查找代码
- 02定位验证或错误处理等行为
- 03改善宽泛或较差的搜索结果
- 04按领域或用途探索代码
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yoanbernabeu/ grepai-skills --skill grepai-search-tips安装后在 Claude Code 中输入/grepai-search-tips确认已加载。
详细介绍
GrepAI 搜索技巧
本技能提供编写高效语义搜索查询的技巧和最佳实践。
何时使用此技能
- 提升搜索结果质量
- 学习语义搜索技巧
- 了解如何组织查询措辞
- 排查搜索结果不理想的问题
语义搜索思维方式
与文本搜索的思路不同:
| 文本搜索(grep) | 语义搜索(GrepAI) |
|---|---|
| 搜索精确文本 | 搜索含义/意图 |
| "getUserById" | "通过 ID 从数据库检索用户" |
| 字面匹配 | 概念匹配 |
查询编写原则
1. 描述意图,而非实现方式
❌ 不佳: getUserById
✅ 良好: 使用 ID 从数据库获取用户记录
❌ 不佳: handleError
✅ 良好: 错误处理和向客户端响应
❌ 不佳: validateInput
✅ 良好: 检查用户输入是否有效且安全
2. 使用描述性语言
❌ 不佳: auth
✅ 良好: 用户身份验证和授权
❌ 不佳: db
✅ 良好: 数据库连接和查询
❌ 不佳: config
✅ 良好: 应用配置加载
3. 明确说明上下文
❌ 不佳: validation
✅ 良好: 验证电子邮件地址格式
❌ 不佳: parse
✅ 良好: 解析 JSON 请求正文
❌ 不佳: send
✅ 良好: 向用户发送电子邮件通知
4. 使用 3-7 个词
| 长度 | 示例 | 质量 |
|---|---|---|
| 太短 | "auth" | ⚠️ 含义模糊 |
| 合适 | "用户身份验证中间件" | ✅ 具体 |
| 太长 | "处理用户身份验证并在中间件层验证 JWT 令牌的代码" | ⚠️ 冗长 |
5. 使用英语
嵌入模型主要使用英语训练:
❌ authentification utilisateur(法语)
✅ user authentication
即使代码注释使用其他语言,英语查询的效果也最好。
查询模式
按行为查找代码
grepai search "validate user credentials before login"
grepai search "send notification when order is placed"
grepai search "calculate total price with discounts"
grepai search "retry failed HTTP requests"
按用途查找代码
grepai search "middleware that checks authentication"
grepai search "function that formats dates"
grepai search "service that sends emails"
grepai search "handler for payment processing"
查找错误处理
grepai search "handle errors from API calls"
grepai search "catch and log exceptions"
grepai search "error response to client"
grepai search "validation error messages"
查找数据操作
grepai search "save user to database"
grepai search "query products by category"
grepai search "cache frequently accessed data"
grepai search "transform data before storage"
查找配置
grepai search "load configuration from environment"
grepai search "database connection settings"
grepai search "API keys and secrets management"
grepai search "feature flags and toggles"
查找安全代码
grepai search "password hashing and verification"
grepai search "input sanitization to prevent injection"
grepai search "rate limiting for API endpoints"
grepai search "CORS configuration"
迭代优化
如果结果不理想,可以逐步优化:
从宽泛查询开始
grepai search "authentication"
# Results too varied
添加上下文
grepai search "JWT authentication"
# Better, but still broad
明确具体内容
grepai search "JWT token validation middleware"
# Precise results
使用同义词
语义搜索能够理解同义词。尝试不同的措辞:
# These may return similar results:
grepai search "user authentication"
grepai search "user login verification"
grepai search "credential validation"
grepai search "identity verification"
特定领域术语
使用所在领域的词汇:
# E-commerce
grepai search "shopping cart checkout process"
grepai search "inventory stock management"
# Finance
grepai search "transaction processing"
grepai search "payment reconciliation"
# Healthcare
grepai search "patient record retrieval"
grepai search "appointment scheduling"
问句式查询
自然语言问句效果很好:
grepai search "how are users authenticated"
grepai search "where is the database connection configured"
grepai search "what happens when a request fails"
grepai search "how are errors logged"
避免常见错误
❌ 不要使用精确的函数名
如果知道精确名称,请使用 grep:
grep -r "getUserById" . # Text search
GrepAI 适用于不知道精确名称的情况:
grepai search "retrieve user from database" # Semantic search
❌ 不要过于抽象
# Too abstract
grepai search "business logic"
# More concrete
grepai search "calculate order total with tax"
❌ 不要使用代码语法
# Don't do this
grepai search "function() { return }"
# Do this
grepai search "function that returns early"
❌ 不要描述得过于详细
# Over-specified (mentions irrelevant details)
grepai search "async function in TypeScript file that uses axios to fetch"
# Better
grepai search "fetch data from external API"
解读结果
高分(0.85+)
匹配度高。代码很可能能实现你描述的功能。
中等分数(0.70-0.84)
相关代码。可能就是你要找的,也可能是相邻功能。
低分(0.60-0.69)
关联较弱。可以考虑优化查询。
极低分(<0.60)
匹配度低。代码库中可能不存在相关概念,也可能需要重写查询。
GrepAI 未找到结果时
- 检查索引:
grepai status - 确认文件已编入索引: 文件是否匹配忽略规则?
- 尝试更简单的查询: 删除具体限定
- 尝试其他词语: 使用同义词
- 检查代码是否存在: 也许还没有!
速查表
| 情况 | 查询风格 |
|---|---|
| 了解行为 | "验证电子邮件格式" |
| 了解领域 | "支付处理流程" |
| 探索代码 | "如何处理错误" |
| 查找入口点 | "应用主启动流程" |
| 查找依赖项 | "数据库在哪里连接" |
输出格式
技巧摘要:
📝 GrepAI Search Tips
✅ DO:
- Describe intent, not implementation
- Use 3-7 descriptive words
- Use English queries
- Iterate and refine
❌ DON'T:
- Use exact function names (use grep)
- Write too short queries ("auth")
- Write too long queries
- Use code syntax in queries
Example transformations:
"auth" → "user authentication and login"
"getUserById" → "fetch user by ID from database"
"handleError" → "error handling and logging"
评论
支持 Markdown