Expand description
§sqry-nl: Natural Language Translation Layer for sqry
This crate provides translation from natural language queries to sqry commands. It uses a MiniLM-L6-v2-based intent classifier combined with regex-based entity extraction to produce validated, safe sqry commands.
§Architecture
The translation pipeline consists of:
- Preprocessor - Unicode normalization, homoglyph detection, input sanitization
- Entity Extractor - Regex-based slot filling for symbols, languages, etc.
- Intent Classifier - MiniLM-L6-v2 ONNX model for intent classification
- Template Assembler - Maps (intent, entities) to sqry command templates
- Safety Validator - Whitelist validation, metachar rejection, path guards
- Translation Cache - LRU cache for repeated queries
§Example
ⓘ
use sqry_nl::{Translator, TranslatorConfig, TranslationResponse};
let config = TranslatorConfig::default();
let translator = Translator::load(config)?;
match translator.translate("find authentication functions in rust") {
TranslationResponse::Execute { command, confidence, .. } => {
println!("Command: {} (confidence: {:.1}%)", command, confidence * 100.0);
// Execute the command via sqry CLI
}
TranslationResponse::Confirm { command, prompt, .. } => {
println!("{}", prompt);
// Ask user for confirmation
}
TranslationResponse::Disambiguate { options, prompt } => {
println!("{}", prompt);
// Present options to user
}
TranslationResponse::Reject { reason, suggestions } => {
eprintln!("Cannot translate: {}", reason);
// Show suggestions
}
}§Safety
All generated commands are validated against a strict whitelist of allowed command templates. The following are always rejected:
- Shell metacharacters (
;,|,&,$, etc.) - Environment variable expansion (
$HOME,${VAR}) - Path traversal (
.., absolute paths) - Write-mode operations (
--force,repair,prune)
§Feature Flags
classifier(default) - Enable the MiniLM-L6-v2 classifier. Requires ONNX Runtime. Disable for minimal builds that only need rule-based classification.
Re-exports§
pub use cache::CacheConfig;pub use cache::CacheStats;pub use error::NlError;pub use error::NlResult;pub use translator::Translator;pub use translator::TranslatorConfig;pub use types::DisambiguationOption;pub use types::ExtractedEntities;pub use types::Intent;pub use types::OutputFormat;pub use types::SymbolKind;pub use types::TranslationResponse;pub use types::ValidationStatus;
Modules§
- assembler
- Command template assembly.
- cache
- Translation cache for repeated queries.
- classifier
- Intent classification using MiniLM-L6-v2 ONNX model.
- error
- Error types for the sqry-nl crate.
- extractor
- Entity extraction from natural language input.
- preprocess
- Input preprocessing for natural language queries.
- translator
- Main Translator API for natural language to sqry command translation.
- types
- Core types for the sqry-nl crate.
- validator
- Safety validation for generated commands.
Constants§
- VERSION
- Crate version for model compatibility checks