High-performance semantic search and document parsing toolkit...
Semtools is a high-performance CLI toolkit providing semantic search capabilities using AI embeddings and document parsing for unsupported formats. Unlike traditional text search (grep), semtools understands semantic meaning, enabling discovery of conceptually related content even when exact keywords don't match.
Use semtools PROACTIVELY when:
docs/ for relevant guides, architecture docs, or reference materialsconfig/, terraform/, or application directoriesSemtools requires Rust and a LlamaCloud API key for parsing operations.
# Install semtools
cargo install semtools
# Set API key (required for parse command)
export LLAMA_CLOUD_API_KEY=your_api_key
# Add to shell profile for persistence
echo 'export LLAMA_CLOUD_API_KEY=your_api_key' >> ~/.zshrc
The primary workflow when searching documentation or configuration files:
Create a workspace for repeated searches or large file collections:
# Create/activate workspace (recommended for multiple searches)
workspace use cluster-ops-docs
export SEMTOOLS_WORKSPACE=cluster-ops-docs
Skip workspace for one-off quick searches.
Use recommended flags for consistent, high-quality results:
search "vault OIDC authentication" docs/ \
--ignore-case \
--n-lines 30 \
--max-distance 0.3
Flag explanation:
--ignore-case (or -i): Case-insensitive matching (ALWAYS use this)--n-lines 30 (or -n 30): Context lines (default 3 is too small, use 30-50)--max-distance 0.3 (or -m 0.3): Similarity threshold (0.3 is good default)Adjust search parameters based on results:
# Too many results? Tighten similarity threshold
search "query" docs/ -i -n 30 -m 0.2
# Too few results? Loosen similarity threshold
search "query" docs/ -i -n 30 -m 0.4
# Need more context? Increase lines
search "query" docs/ -i -n 50 -m 0.3
For one-off searches without workspace overhead:
search "crossplane composition patterns" docs/ -i -n 30 -m 0.3
For exploring a topic with multiple related searches:
# Setup workspace once
workspace use architecture-research
export SEMTOOLS_WORKSPACE=architecture-research
# Multiple searches (fast after first one)
search "service mesh networking" docs/ -i -n 30 -m 0.3
search "cilium cluster mesh" docs/ -i -n 30 -m 0.3
search "BGP configuration" docs/ -i -n 30 -m 0.3
Search across multiple directories for configuration patterns:
search "external secrets configuration" apps/ argocd/ crossplane/ \
-i -n 40 -m 0.3
Find specific patterns in Kubernetes/Helm manifests:
# Find ingress configurations with authentication
search "ingress with oauth2 proxy" apps/ -i -n 30 -m 0.3
# Find Crossplane resource examples
search "vault kubernetes role composition" crossplane/ -i -n 30 -m 0.3
# Find ArgoCD sync configurations
search "sync waves and hooks" argocd/ -i -n 25 -m 0.3
Combine exact-match filtering with semantic search:
# Find files mentioning "vault", then semantic search within
grep -l "vault" apps/*/values.yaml | \
xargs search "authentication configuration" -i -n 30 -m 0.3
# Pre-filter by section, then semantic search
cat docs/reference/*.md | grep -A 50 "## Authentication" | \
search "OIDC provider setup" -i -n 20 -m 0.3
Parse unsupported file formats (PDF, DOCX, PPTX) into searchable markdown.
workspace use vendor-docs
export SEMTOOLS_WORKSPACE=vendor-docs
# Parse PDFs (results cached to ~/.parse/)
parse docs/vendor/*.pdf
# Parse multiple formats
parse whitepaper.pdf guide.docx presentation.pptx
# Search cached parsed files
search "API authentication" ~/.parse/*.pdf.md -i -n 30 -m 0.3
# Or parse and search in pipeline
parse document.pdf | xargs cat | search "security model" -i -n 40 -m 0.3
Subsequent searches use cached embeddings (very fast):
search "rate limiting" ~/.parse/ -i -n 30 -m 0.3
search "error handling" ~/.parse/ -i -n 30 -m 0.3
Chain Unix tools for powerful document processing:
# Find YAML files, pre-filter with grep, then semantic search
find apps/ argocd/ -name "*.yaml" | \
xargs cat | \
grep -i "ingress" | \
search "TLS certificate management" -i -n 30 -m 0.3
Analyze large PDF collections efficiently:
# Setup dedicated workspace
workspace use research-papers
export SEMTOOLS_WORKSPACE=research-papers
# Parse all PDFs once (cached)
parse papers/*.pdf
# Run multiple semantic queries (fast)
search "kubernetes security" ~/.parse/ -i -n 50 -m 0.2
search "container isolation" ~/.parse/ -i -n 50 -m 0.3
search "network policies" ~/.parse/ -i -n 50 -m 0.3
# Clean up when done
workspace prune
Discover how patterns are implemented across the codebase:
# Find authentication implementations
search "authentication middleware" src/ -i -n 40 -m 0.3
# Find error handling patterns
search "error propagation patterns" src/ lib/ -i -n 30 -m 0.3
# Find similar API endpoint structures
search "REST endpoint with validation" src/api/ -i -n 35 -m 0.3
The --max-distance parameter controls semantic similarity (cosine distance):
| Threshold | Precision | Recall | Use When |
|---|---|---|---|
| 0.2 | Very High | Low | Need only highly relevant, precise matches |
| 0.3 | High | Medium | Recommended default, good balance |
| 0.4 | Medium | High | Exploratory search, broader results |
| 0.5+ | Low | Very High | Very broad search, discovery mode |
General guidance:
For consistent, high-quality results, always use:
search "query" path/ -i -n 30 -m 0.3
Why:
-i: Don't know how terms are capitalized in files-n 30: Default 3 is rarely sufficient context (use 30-50)-m 0.3: Good precision/recall balanceCreate workspace before searching large file collections or running multiple related searches:
workspace use project-name
export SEMTOOLS_WORKSPACE=project-name
# First search generates embeddings (slower)
# Subsequent searches use cache (much faster)
Benefits:
Parse PDFs as a one-time operation, then search cached markdown:
# Parse once
parse documents/*.pdf
# Search many times (fast)
search "topic 1" ~/.parse/ -i -n 30 -m 0.3
search "topic 2" ~/.parse/ -i -n 30 -m 0.3
Combine exact-match filtering with semantic understanding:
# Find files with exact keyword, then semantic search
grep -l "kubernetes" docs/*.md | \
xargs search "authentication patterns" -i -n 30 -m 0.3
Different content types need different context amounts:
# Code/configs: 30-40 lines
search "query" src/ -i -n 35 -m 0.3
# Documentation: 40-50 lines
search "query" docs/ -i -n 45 -m 0.3
# Dense technical docs: 50+ lines
search "query" papers/ -i -n 60 -m 0.3
Don't use semtools when:
Use grep or Grep tool for literal string matching:
# Use grep, not semtools
grep -r "function_name" src/
grep "exact error message" logs/*.txt
Use ast-grep for AST-based code pattern matching:
# Use ast-grep, not semtools
ast-grep --pattern 'async function $NAME($$$)'
Use find or Glob tool for file path patterns:
# Use find/glob, not semtools
find . -name "*.yaml"
glob "apps/**/*.values.yaml"
Semtools requires embedding time; use grep for instant results:
# For instant results, use grep
grep "ERROR" logs/current.log
Use native tools for focused, single-file operations:
# Use grep for single files
grep "keyword" single_file.txt
| Need | Tool | Reason |
|---|---|---|
| Exact string match | grep |
Fast, instant, literal matching |
| Code structure/AST | ast-grep |
Understands syntax, structural patterns |
| File name patterns | find/Glob |
Fast directory traversal |
| Semantic/concept search | semtools | Understands meaning, finds related content |
| Exploring unfamiliar code | semtools | Discovers patterns via semantic similarity |
| Multi-format docs | semtools | Parses PDFs, DOCX, searches semantically |
Increase distance threshold:
search "query" files/ -i -n 30 -m 0.4 # or 0.5
Rephrase query using different terminology
Check file paths exist and are readable:
ls docs/ # verify path
Verify workspace status:
workspace status
Use workspace for repeated searches:
workspace use project
export SEMTOOLS_WORKSPACE=project
Pre-parse PDFs to avoid parsing repeatedly
Reduce scope - search specific directories, not entire repo
Check API key:
echo $LLAMA_CLOUD_API_KEY # should output your key
Verify network connection (LlamaParse requires internet)
Check file format (PDF, DOCX, PPTX supported)
# Remove stale cache entries
workspace prune
# Or create fresh workspace
workspace use new-workspace
export SEMTOOLS_WORKSPACE=new-workspace
Tighten distance threshold:
search "query" files/ -i -n 30 -m 0.2
Use more specific query terms
Pre-filter with grep:
grep -l "exact_term" *.yaml | xargs search "broader query" -i -n 30 -m 0.3
Semtools uses LlamaCloud API for:
Cost optimization strategies:
Example costs:
workspace use my-project
export SEMTOOLS_WORKSPACE=my-project
Add to shell profile for persistence:
echo 'export SEMTOOLS_WORKSPACE=my-project' >> ~/.zshrc
workspace status
# Shows: active workspace, cached files, size, last modified
# Remove stale/missing files from cache
workspace prune
Workspaces stored at: ~/.semtools/workspaces/<workspace-name>/
search "service mesh design" docs/architecture/ -i -n 40 -m 0.3
search "composition with managed resources" crossplane/ -i -n 30 -m 0.3
search "vault kubernetes authentication role" apps/ crossplane/ terraform/ \
-i -n 30 -m 0.3
search "authentik group provisioning" terraform/modules/ -i -n 30 -m 0.3
search "argocd sync waves and hooks" argocd/ -i -n 30 -m 0.3
search "ingress configuration with TLS" apps/*/values.yaml -i -n 35 -m 0.3
# Search guides, reference docs, and architecture docs
search "secret management patterns" docs/ -i -n 40 -m 0.3
# Standard search command
search "<query>" <path> -i -n 30 -m 0.3
workspace use <name>
export SEMTOOLS_WORKSPACE=<name>
parse *.pdf
search "query" ~/.parse/ -i -n 30 -m 0.3
-m 0.2 # High precision (strict)
-m 0.3 # Balanced (default)
-m 0.4 # High recall (broad)
For detailed CLI documentation, see references/cli_reference.md.
External resources: