leann-search
npx machina-cli add skill parcadei/Continuous-Claude-v3/leann-search --openclawFiles (1)
SKILL.md
1.8 KB
LEANN Semantic Search
Use LEANN for meaning-based code search instead of grep.
When to Use
- Conceptual queries: "how does authentication work", "where are errors handled"
- Understanding patterns: "streaming implementation", "provider architecture"
- Finding related code: code that's semantically similar but uses different terms
When NOT to Use
- Exact matches: Use Grep for
class Foo,def bar, specific identifiers - Regex patterns: Use Grep for
error.*handling,import.*from - File paths: Use Glob for
*.test.ts,src/**/*.py
Commands
# Search the current project's index
leann search <index-name> "<query>" --top-k 5
# List available indexes
leann list
# Example
leann search rigg "how do providers handle streaming" --top-k 5
MCP Tool (in Claude Code)
leann_search(index_name="rigg", query="your semantic query", top_k=5)
Rebuilding the Index
When codebase changes significantly:
cd /path/to/project
leann build <project-name> --docs src tests scripts \
--file-types '.ts,.py,.md,.json' \
--no-recompute --no-compact \
--embedding-mode sentence-transformers \
--embedding-model all-MiniLM-L6-v2
How It Works
- LEANN uses sentence embeddings to understand meaning
- Searches find conceptually similar code, not just text matches
- Results ranked by semantic similarity score (0-1)
Grep vs LEANN Decision
| Query Type | Tool | Example |
|---|---|---|
| Natural language | LEANN | "how does caching work" |
| Class/function name | Grep | "class CacheManager" |
| Pattern matching | Grep | error|warning |
| Find implementations | LEANN | "rate limiting logic" |
Source
git clone https://github.com/parcadei/Continuous-Claude-v3/blob/main/.claude/skills/archive/leann-search/SKILL.mdView on GitHub Overview
Leann-search enables meaning-based code search by using LEANN embeddings to locate semantically similar code, not just literal words. This matters for understanding patterns, architectural decisions, and finding related implementations across a project.
How This Skill Works
LEANN converts code into sentence embeddings that capture meaning. The search retrieves conceptually similar code by comparing embeddings and ranks results by semantic similarity. Users typically build an index and run leann search <index-name> "<query>" --top-k 5 to get relevant results.
When to Use It
- Conceptual queries such as 'how does authentication work' or 'where are errors handled'
- Understanding patterns like 'streaming implementation' or 'provider architecture'
- Finding related code that is semantically similar but uses different terms
- When you need concept-based discovery across modules or languages
- When you want to compare implementations of a feature beyond surface text
Quick Start
- Step 1: Build or update the LEANN index for your project using leann build <project-name> --docs src tests scripts --file-types '.ts,.py,.md,.json'
- Step 2: Run a semantic search with a natural-language query, e.g. leann search <index-name> "how does authentication work" --top-k 5
- Step 3: Review results, adjust the query or top-k, and rerun; rebuild the index after major code changes
Best Practices
- Phrase queries in terms of concepts and behavior rather than specific identifiers
- Keep the codebase index fresh by rebuilding after significant changes with leann build
- Use a small top-k to start and broaden if you need more coverage
- Inspect results for true semantic similarity rather than surface text matches
- Use leann search for patterns and architecture exploration in early design discussions
Example Use Cases
- Find how authentication is implemented across modules
- Identify error-handling patterns in a microservice
- Locate provider architecture usage in streaming code
- Discover rate-limiting implementations with similar semantics
- Find related code that achieves a concept with different naming
Frequently Asked Questions
Add this skill to your agents