MLVA CLI Tutorials & Recipes
Learn how to harness offline natural-language semantic retrieval to search complex codebases by intent, locate algorithms, index custom documentation, and inspect code right in your terminal.
1. Searching Machine Learning Repositories by Task Intent
Traditional regex tools (like grep or ripgrep) require you to guess exact variable names (e.g., model.fit(), criterion = nn.CrossEntropyLoss()). If the code uses a custom subclass or an unconventional naming scheme, regex fails. With MLVA, you describe what the code does conceptually in natural language.
Example: Locating Model Training Loops
Find neural network training implementations without remembering whether the script is called train.py, fit_resnet.py, or pipeline_runner.py:
mlva search "train resnet model on custom dataset" --limit 3
Example Terminal Output:
Found 3 matching files:
1. [94%] ml/train_resnet_cifar.py (line 42)
Match: "def train_epoch(model, dataloader, optimizer, criterion):"
Context: PyTorch ResNet training loop with batch gradient descent
2. [89%] ml/pipeline/transfer_learning.py (line 118)
Match: "fine_tune_backbone(resnet50, train_loader, epochs=25)"
Context: Feature extraction and layer fine-tuning logic
3. [82%] scripts/train_vision_classifier.py (line 65)
Match: "trainer = Trainer(model=resnet, data=dataset)"
Example: Locating Custom Loss Functions
# Query for loss formulation
mlva search "cross entropy loss with label smoothing" --lang python
# Query for learning rate scheduling
mlva search "cosine annealing learning rate warmup schedule"
2. Locating Algorithms and Data Structures in Java
In large legacy codebases or monorepos containing thousands of Java classes, finding specific algorithmic logic can be challenging when classes use names like CustomPathEvaluatorImpl.java rather than Dijkstra.java.
Example: Finding Shortest Path Implementations
# Search for graph traversal algorithms
mlva search "dijkstra shortest path algorithm with priority queue" --lang java
# Search for tree traversal
mlva search "lowest common ancestor binary search tree" --lang java
# Search for concurrency patterns
mlva search "thread safe lru cache using reentrant read write lock"
MLVA matches the concept of graph relaxation, min-heaps, and adjacency list manipulation even if the file is titled NetworkRouteOptimizer.java.
3. Indexing Custom Directories and Markdown Documentation
By default, MLVA indexes the active working directory. You can also index external directories such as personal technical documentation, architectural decision records (ADRs), or shared team repositories.
Step-by-Step Directory Indexing
# 1. Index your local engineering study notes
mlva index ~/Documents/EngineeringNotes
# 2. Index a specific backend service repository
mlva index ~/Projects/PaymentService
# 3. Check indexing status and total vector count
mlva stats
# 4. Search across indexed notes
mlva search "how to configure kubernetes ingress with cert-manager letsencrypt"
.gitignore and skips binary files, virtual environments (venv, .conda), node_modules, and build artifacts (target/, dist/) automatically.
4. Terminal Code Inspection and Line Pagination
Once you identify a matching file, you do not need to switch windows to inspect the relevant code. MLVA includes built-in terminal inspection commands with line range pagination.
Using mlva show
# View the full file with terminal line numbers
mlva show ml/train_resnet_cifar.py
# Paginate to view only lines 40 through 85 (the training loop)
mlva show ml/train_resnet_cifar.py --lines 40-85
Seamless Editor & Clipboard Integration
Open Directly in VS Code
Launch your favorite IDE positioned at the matching file immediately:
mlva code ml/train_resnet_cifar.py
Copy Path or Snippet
Copy the absolute file path directly to your OS clipboard for pasting into git or Slack:
mlva copy ml/train_resnet_cifar.py
5. Incremental Re-Indexing & Index Maintenance
As you write new code, modify functions, or pull changes from upstream git branches, you want your local search index to remain up to date.
# Fast incremental refresh (only updates changed files based on mtime/hash)
mlva refresh
# Inspect index health, total files, and vector dimensions
mlva status
# Rebuild index from scratch if directories moved
mlva index . --rebuild
Quick Command Reference
| Goal | Command | Description |
|---|---|---|
| Search by Intent | mlva search "<query>" |
Run semantic retrieval using local 384-d embeddings |
| Filter Language | mlva search "<query>" --lang <py|java> |
Restrict search results to specific programming languages |
| Inspect Code | mlva show <path> --lines <start-end> |
View highlighted lines in terminal without opening editor |
| Open in IDE | mlva code <path> |
Launch file immediately in VS Code |
| Index Folder | mlva index <path> |
Parse files and store embeddings in local SQLite database |
| Fast Sync | mlva refresh |
Perform incremental sync of modified and new files |
Explore More MLVA Resources
- Full Documentation Hub: Complete installation guide, npm package reference, and CLI commands.
- Tool Comparisons: See how MLVA compares with ripgrep, fzf, and grep for code search.
- System Architecture: Deep dive into the 384-d ONNX embedding pipeline, BM25 indexing, and local SQLite store.
- Official NPM Registry (mlva-cli): Verified npm package documentation and release history.