r/programming • u/mr_gnusi • Aug 05 '26
How fuzzy search works in a search engine: Levenshtein automata and n-gram similarity
https://blog.serenedb.com/fuzzy-search-deep-dive
113
Upvotes
r/programming • u/mr_gnusi • Aug 05 '26
8
u/mr_gnusi Aug 05 '26 edited Aug 05 '26
For context: this is a rewrite of a post I wrote for the ArangoDB blog about six years ago. The original isn't reachable anymore and the code has moved since, but I personally find the Schulz–Mihov paper quite elegant, so I decided to it's worth writing up again.
For info, Lucene
LevenshteinAutomata implements the same approach, but caps at edit distance 2. Tantivy gets it via thelevenshtein_automata crate.SereneDB goes to 4 (3 with transpositions), which is really a question of how much parametric transition table you're willing to hold.
Code is Apache 2.0, star us if you'd like to support the project:
https://github.com/serenedb/serenedb/
13
u/pokeybill Aug 05 '26
Its remarkable to me how effective bigram/trigram analysis can be, especially given the computational cost compared to something like semantic embedding and mcp.
I was working with some interns recently on an NLP problem to do with identifying tokens in URI paths to dedeuplicate URLs and at the end of the day it was levenshtein who saved us.
4
u/sephirostoy Aug 06 '26
I hate fuzzy search from the bottom of my heart. Wherever it is implemented it brings 98% of noise results, making them almost useless.
I prefer the heuristic where I search for words that can be matched exactly each in any order. Results are much more accurate and predictable. I don't know if it has a name. This is what Visual Assist X use.
2
u/NoDistrict991 Aug 08 '26
The "old" algorithms end up being the right tool. You don't always need embeddings when a bit of Levenshtein or n-gram matching gets the job done faster and more predictably.
1
u/[deleted] Aug 07 '26
[removed] — view removed comment