grepai-search-tips

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI Search Tips

GrepAI 搜索技巧

This skill provides tips and best practices for writing effective semantic search queries.
此技能提供编写有效语义搜索查询的技巧和最佳实践。

When to Use This Skill

何时使用此技能

  • Improving search result quality
  • Learning semantic search techniques
  • Understanding how to phrase queries
  • Troubleshooting poor search results
  • 提升搜索结果质量
  • 学习语义搜索技术
  • 了解如何表述查询
  • 排查搜索结果不佳的问题

Semantic Search Mindset

语义搜索思维模式

Think differently from text search:
Text Search (grep)Semantic Search (GrepAI)
Search for exact textSearch for meaning/intent
"getUserById""retrieve user from database by ID"
Literal matchConceptual match
与文本搜索的思路不同:
文本搜索(grep)语义搜索(GrepAI)
搜索精确文本搜索含义/意图
"getUserById""通过ID从数据库检索用户"
字面匹配概念匹配

Query Writing Principles

查询编写原则

1. Describe Intent, Not Implementation

1. 描述意图,而非实现细节

Bad:
getUserById
Good:
fetch user record from database using ID
Bad:
handleError
Good:
error handling and response to client
Bad:
validateInput
Good:
check if user input is valid and safe
错误示例:
getUserById
正确示例:
fetch user record from database using ID
错误示例:
handleError
正确示例:
error handling and response to client
错误示例:
validateInput
正确示例:
check if user input is valid and safe

2. Use Descriptive Language

2. 使用描述性语言

Bad:
auth
Good:
user authentication and authorization
Bad:
db
Good:
database connection and queries
Bad:
config
Good:
application configuration loading
错误示例:
auth
正确示例:
user authentication and authorization
错误示例:
db
正确示例:
database connection and queries
错误示例:
config
正确示例:
application configuration loading

3. Be Specific About Context

3. 明确上下文

Bad:
validation
Good:
validate email address format
Bad:
parse
Good:
parse JSON request body
Bad:
send
Good:
send email notification to user
错误示例:
validation
正确示例:
validate email address format
错误示例:
parse
正确示例:
parse JSON request body
错误示例:
send
正确示例:
send email notification to user

4. Use 3-7 Words

4. 使用3-7个单词

LengthExampleQuality
Too short"auth"⚠️ Vague
Good"user authentication middleware"✅ Specific
Too long"the code that handles user authentication and validates JWT tokens in the middleware layer"⚠️ Verbose
长度示例质量
过短"auth"⚠️ 模糊
合适"user authentication middleware"✅ 具体
过长"the code that handles user authentication and validates JWT tokens in the middleware layer"⚠️ 冗长

5. Use English

5. 使用英文

Embedding models are trained primarily on English:
authentification utilisateur
(French) ✅
user authentication
Even if your code comments are in another language, English queries work best.
嵌入模型主要基于英文训练:
authentification utilisateur
(法语) ✅
user authentication
即使你的代码注释是其他语言,英文查询的效果最佳。

Query Patterns

查询模式

Finding Code by Behavior

按行为查找代码

bash
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"
bash
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"

Finding Code by Purpose

按用途查找代码

bash
grepai search "middleware that checks authentication"
grepai search "function that formats dates"
grepai search "service that sends emails"
grepai search "handler for payment processing"
bash
grepai search "middleware that checks authentication"
grepai search "function that formats dates"
grepai search "service that sends emails"
grepai search "handler for payment processing"

Finding Error Handling

查找错误处理代码

bash
grepai search "handle errors from API calls"
grepai search "catch and log exceptions"
grepai search "error response to client"
grepai search "validation error messages"
bash
grepai search "handle errors from API calls"
grepai search "catch and log exceptions"
grepai search "error response to client"
grepai search "validation error messages"

Finding Data Operations

查找数据操作代码

bash
grepai search "save user to database"
grepai search "query products by category"
grepai search "cache frequently accessed data"
grepai search "transform data before storage"
bash
grepai search "save user to database"
grepai search "query products by category"
grepai search "cache frequently accessed data"
grepai search "transform data before storage"

Finding Configuration

查找配置代码

bash
grepai search "load configuration from environment"
grepai search "database connection settings"
grepai search "API keys and secrets management"
grepai search "feature flags and toggles"
bash
grepai search "load configuration from environment"
grepai search "database connection settings"
grepai search "API keys and secrets management"
grepai search "feature flags and toggles"

Finding Security Code

查找安全代码

bash
grepai search "password hashing and verification"
grepai search "input sanitization to prevent injection"
grepai search "rate limiting for API endpoints"
grepai search "CORS configuration"
bash
grepai search "password hashing and verification"
grepai search "input sanitization to prevent injection"
grepai search "rate limiting for API endpoints"
grepai search "CORS configuration"

Iterative Refinement

迭代优化

If results aren't good, iterate:
如果结果不理想,进行迭代:

Start Broad

从宽泛开始

bash
grepai search "authentication"
bash
grepai search "authentication"

Results too varied

结果过于多样

undefined
undefined

Add Context

添加上下文

bash
grepai search "JWT authentication"
bash
grepai search "JWT authentication"

Better, but still broad

有所改善,但仍宽泛

undefined
undefined

Be Specific

变得具体

bash
grepai search "JWT token validation middleware"
bash
grepai search "JWT token validation middleware"

Precise results

精确结果

undefined
undefined

Using Synonyms

使用同义词

Semantic search understands synonyms. Try different phrasings:
bash
undefined
语义搜索能理解同义词。尝试不同表述:
bash
undefined

These may return similar results:

这些可能返回相似结果:

grepai search "user authentication" grepai search "user login verification" grepai search "credential validation" grepai search "identity verification"
undefined
grepai search "user authentication" grepai search "user login verification" grepai search "credential validation" grepai search "identity verification"
undefined

Domain-Specific Terms

领域特定术语

Use your domain vocabulary:
bash
undefined
使用你的领域词汇:
bash
undefined

E-commerce

电商领域

grepai search "shopping cart checkout process" grepai search "inventory stock management"
grepai search "shopping cart checkout process" grepai search "inventory stock management"

Finance

金融领域

grepai search "transaction processing" grepai search "payment reconciliation"
grepai search "transaction processing" grepai search "payment reconciliation"

Healthcare

医疗领域

grepai search "patient record retrieval" grepai search "appointment scheduling"
undefined
grepai search "patient record retrieval" grepai search "appointment scheduling"
undefined

Question-Style Queries

问句形式的查询

Natural questions work well:
bash
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"
自然问句的效果很好:
bash
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"

Avoiding Common Mistakes

避免常见错误

❌ Don't Use Exact Function Names

❌ 不要使用精确函数名

If you know the exact name, use grep:
bash
grep -r "getUserById" .  # Text search
GrepAI is for when you don't know the exact name:
bash
grepai search "retrieve user from database"  # Semantic search
如果你知道精确名称,使用grep:
bash
grep -r "getUserById" .  # 文本搜索
GrepAI适用于你不知道精确名称的场景:
bash
grepai search "retrieve user from database"  # 语义搜索

❌ Don't Be Too Abstract

❌ 不要过于抽象

bash
undefined
bash
undefined

Too abstract

过于抽象

grepai search "business logic"
grepai search "business logic"

More concrete

更具体

grepai search "calculate order total with tax"
undefined
grepai search "calculate order total with tax"
undefined

❌ Don't Use Code Syntax

❌ 不要使用代码语法

bash
undefined
bash
undefined

Don't do this

不要这样做

grepai search "function() { return }"
grepai search "function() { return }"

Do this

应该这样做

grepai search "function that returns early"
undefined
grepai search "function that returns early"
undefined

❌ Don't Over-Specify

❌ 不要过度指定

bash
undefined
bash
undefined

Over-specified (mentions irrelevant details)

过度指定(提及无关细节)

grepai search "async function in TypeScript file that uses axios to fetch"
grepai search "async function in TypeScript file that uses axios to fetch"

Better

更好的写法

grepai search "fetch data from external API"
undefined
grepai search "fetch data from external API"
undefined

Interpreting Results

解读结果

High Scores (0.85+)

高分(0.85+)

Strong match. The code likely does what you described.
匹配度高。代码很可能实现了你描述的功能。

Medium Scores (0.70-0.84)

中分(0.70-0.84)

Related code. May be what you want, or adjacent functionality.
相关代码。可能是你需要的,或是邻近功能。

Low Scores (0.60-0.69)

低分(0.60-0.69)

Loosely related. Consider refining your query.
关联松散。考虑优化你的查询。

Very Low Scores (<0.60)

极低分(<0.60)

Weak match. The concept may not exist in the codebase, or query needs rework.
匹配度弱。代码库中可能不存在该概念,或需要重新调整查询。

When GrepAI Doesn't Find Results

快速参考卡

  1. Check the index:
    grepai status
  2. Verify files are indexed: Not in ignore patterns?
  3. Try simpler query: Remove specificity
  4. Try different words: Use synonyms
  5. Check if code exists: Maybe it doesn't yet!
场景查询风格
了解行为"验证邮箱格式"
了解领域"支付处理流程"
探索代码"错误如何处理"
查找入口点"主应用启动逻辑"
查找依赖"数据库连接位置"

Quick Reference Card

输出格式

SituationQuery Style
Know the behavior"validates email format"
Know the domain"payment processing flow"
Exploring"how errors are handled"
Finding entry points"main application startup"
Finding dependencies"where database is connected"
技巧总结:
📝 GrepAI 搜索技巧

✅ 建议:
- 描述意图,而非实现细节
- 使用3-7个描述性单词
- 使用英文查询
- 迭代优化

❌ 避免:
- 使用精确函数名(改用grep)
- 过短的查询(如"auth")
- 过长的查询
- 在查询中使用代码语法

示例转换:
  "auth"            → "user authentication and login"
  "getUserById"     → "fetch user by ID from database"
  "handleError"     → "error handling and logging"

Output Format

Tips summary:
📝 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"