Grepai Search Basics

yoanbernabeu/grepai-skills/skills/search/grepai-search-basics

作者 yoanbernabeu382d40261c0d41109c6e11872574ba0be9b064d0无许可证收录于 2026年10月9日更新于 2026年10月9日

Basic semantic code search with GrepAI. Use this skill to learn fundamental search commands and concepts.

AI 生成的概览

讲解 GrepAI 语义代码搜索的基础知识,包括命令、结果解读和查询技巧。

功能
该技能说明如何使用 GrepAI 的语义代码搜索,涵盖基本搜索命令、结果格式和分数解读。它介绍如何限制结果数量、检查索引状态,以及将语义搜索与传统 grep 进行比较。它还提供编写有效自然语言查询和排查常见搜索问题的指导。
适用场景
适合在学习 GrepAI 搜索、执行基本代码搜索,或想理解语义搜索与文本搜索区别时使用。也适合用于解读搜索结果和优化查询。
运行要求
需要已初始化 GrepAI、已创建索引,并运行 Ollama 等嵌入提供程序。该技能不附带脚本,仅为说明文档。

GrepAI Search Basics

This skill covers the fundamentals of semantic code search with GrepAI.

When to Use This Skill

  • Learning GrepAI search
  • Performing basic code searches
  • Understanding semantic vs. text search
  • Interpreting search results

Prerequisites

  1. GrepAI initialized (grepai init)
  2. Index created (grepai watch)
  3. Embedding provider running (Ollama, etc.)

What is Semantic Search?

Unlike traditional text search (grep, ripgrep), GrepAI searches by meaning:

TypeHow it WorksExample
Text searchExact string match"login" → finds "login"
Semantic searchMeaning similarity"authenticate user" → finds login, auth, signin code

Basic Search Command

bash
grepai search "your query here"

Example

bash
grepai search "user authentication flow"

Output:

Score: 0.89 | src/auth/middleware.go:15-45──────────────────────────────────────────func AuthMiddleware() gin.HandlerFunc {    return func(c *gin.Context) {        token := c.GetHeader("Authorization")        if token == "" {            c.AbortWithStatus(401)            return        }        claims, err := ValidateToken(token)        if err != nil {            c.AbortWithStatus(401)            return        }        c.Set("user", claims.UserID)        c.Next()    }}
Score: 0.82 | src/auth/jwt.go:23-55──────────────────────────────────────────func ValidateToken(tokenString string) (*Claims, error) {    token, err := jwt.Parse(tokenString, func(t *jwt.Token) (interface{}, error) {        return []byte(secretKey), nil    })    if err != nil {        return nil, err    }    if claims, ok := token.Claims.(*Claims); ok && token.Valid {        return claims, nil    }    return nil, errors.New("invalid token")}
Score: 0.76 | src/handlers/login.go:10-35──────────────────────────────────────────func HandleLogin(c *gin.Context) {    var req LoginRequest    if err := c.ShouldBindJSON(&req); err != nil {        c.JSON(400, gin.H{"error": "invalid request"})        return    }    user, err := userService.Authenticate(req.Email, req.Password)    // ...}

Understanding Results

Result Format

Score: 0.89 | src/auth/middleware.go:15-45──────────────────────────────────────────[code content]
ComponentMeaning
ScoreSimilarity (0.0 to 1.0, higher = more relevant)
File pathLocation of the code
Line numbersStart-end lines of the chunk
ContentThe actual code

Score Interpretation

ScoreMeaning
0.90+Excellent match
0.80-0.89Good match
0.70-0.79Related
0.60-0.69Loosely related
<0.60Weak match

Limiting Results

By default, GrepAI returns 10 results. Adjust with --limit:

bash
# Get only top 3 resultsgrepai search "database queries" --limit 3
# Get more resultsgrepai search "error handling" --limit 20

Checking Index Status

Before searching, verify your index:

bash
grepai status

Output:

✅ GrepAI Status
   Index:   - Files: 245   - Chunks: 1,234   - Last updated: 2 minutes ago
   Ready for search.

Search vs Grep Comparison

Traditional grep

bash
grep -r "authenticate" .
  • Finds exact text "authenticate"
  • Misses synonyms (login, signin, auth)
  • Returns all matches, unranked

GrepAI search

bash
grepai search "authenticate user credentials"
  • Finds semantically similar code
  • Includes related concepts
  • Results ranked by relevance

What Makes a Good Query

Good Queries ✅

Describe the intent or behavior:

bash
grepai search "validate user credentials"grepai search "handle HTTP request errors"grepai search "connect to the database"grepai search "send email notification"grepai search "parse JSON configuration"

Less Effective Queries ❌

Too short or generic:

bash
grepai search "auth"           # Too vaguegrepai search "function"       # Too genericgrepai search "getUserById"    # Exact name (use grep)

Natural Language Queries

GrepAI understands natural language:

bash
# Ask questionsgrepai search "how are users authenticated"grepai search "where is the database connection configured"
# Describe behaviorgrepai search "code that sends emails to users"grepai search "functions that validate input data"

Multiple Words vs Phrases

Both work, but phrases often get better results:

bash
# Multiple words (OR-like behavior)grepai search "login password validation"
# Phrase (describes specific intent)grepai search "validate user login credentials"

Quick Tips

  1. Use English: Models are trained on English
  2. Be specific: "JWT token validation" vs "validation"
  3. Describe intent: What the code DOES, not what it's called
  4. Use 3-7 words: Enough context, not too verbose
  5. Iterate: Refine query based on results

Common Search Patterns

Finding Entry Points

bash
grepai search "main entry point"grepai search "application startup"grepai search "HTTP server initialization"

Finding Error Handling

bash
grepai search "error handling and logging"grepai search "exception handling"grepai search "error response to client"

Finding Data Access

bash
grepai search "database query execution"grepai search "fetch user from database"grepai search "save data to storage"

Finding Business Logic

bash
grepai search "calculate order total"grepai search "process payment transaction"grepai search "validate business rules"

Troubleshooting

❌ Problem: No results ✅ Solutions:

  • Check index exists: grepai status
  • Run grepai watch if index is empty
  • Simplify query

❌ Problem: Irrelevant results ✅ Solutions:

  • Be more specific
  • Use different words
  • Check if code exists in the codebase

❌ Problem: Missing expected code ✅ Solutions:

  • Check if file is ignored in config
  • Ensure file extension is supported
  • Re-index: rm .grepai/index.gob && grepai watch

Output Format

Successful basic search:

Query: "user authentication flow"Results: 5 matches
Score: 0.89 | src/auth/middleware.go:15-45──────────────────────────────────────────[relevant code...]
Score: 0.82 | src/auth/jwt.go:23-55──────────────────────────────────────────[relevant code...]
[additional results...]
Tip: Use --limit to adjust number of results     Use --json for machine-readable output

来源与署名

来源:yoanbernabeu/grepai-skills位于skills/search/grepai-search-basics提交382d402

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架