I participated in a local Hack Day at my college, and my project was fzfx.
The idea was simple. Tools like fzf are truly fast, but they work only when you remember the exact syntax. What if you forget the complete syntax but remember its functions? Regular fuzzy logic can't search that.
So I combined fuzzy logic with semantic searching. I chose fastembed, which runs an ONNX runtime of its own. I selected the AllMiniLML6V2 model to embed the list of commands into the model. Then, the query would be matched with the embeddings, and the scores for cosine similarities of every command would be returned. (Please don't tell me to go into extreme details of this implementation within fastembed. Its my first time working with anything remotely close to AI; I had never even heard of ONNX before)
The fuzzy-matcher crate did the fuzzy search part, and returned the scores. fzfx combines both these scores with this formula to calculate the final score:
score = (alpha * vector_score) + ((1 - alpha) * fuzzy_score)
The current value of alpha is 0.7. Some commands are appended with some additional keywords for simpler understanding by the embedding model, like 'remove delete files' for rm. It also ignores sudo in commands starting with it, although plans are to improve this behavior.
The results are definitely not always-correct. There's more tuning and customization left to do. So, I'm certainly not claiming it can replace your current tools or workflow.
However, on the brighter side, it does have some pretty neat features:
- Model and embeddings cache after first run, so same commands take negligible time (~729ns) on cache hits
-c/--copy to copy the selected command, or -x/--exec to execute it directly
-q/--query to provide the query string in the command, otherwise it will ask when running
-C/--clear-cache to remove all embeddings cache, and --clear-all to remove both embeddings and model cache files
- Script and agent friendly with
-r/--raw mode which only outputs the top-scored command to stdout
-k/--top-k to specify the number of matches to show (default = 10)
To see more details, visit the repository, and drop a star if you like it ๐
PS: Got to know that bincode crate had stopped maintaining. Learnt it the hard way. Will replace it with a different crate in the next versions. PPS: I won at the Hack Day and got an Arduino UNO Q, lesgooo ๐