The best code explainer ever!

Help me write this essay! to leave a comment on any selection.

Today, using AI means delegating lower-level decisions. Don't get me wrong – I love the extra leverage from delegating and managing – but I mourn the loss of deep understanding, control, fast-feedback loops, and flow state. I dream of AI that empowers us to be more connected than ever to every detail quickly and joyfully.

I've tried and failed to get Astra and Fable to help me understand code. For example, check out this terrible explainer Astra made of how the code behind this essay works. No amount of feedback or skills seemed to make a difference. The problem is that no truly great explainers of code have yet been created. If you know of an excellent code explainer, please let me know by leaving a comment here.

My favorite code explainer is Glen Chiacchieri’s Fuzzyset. Despite it being the best I have yet found, I think we can do even better. In retrospect, it was silly of me to expect AI to one-shot these explainers if we humans haven't yet even produced a single model for it to copy. So let's make Fuzzyset the best explainer of code ever made!

The rest of this essay is that explainer, which will quickly and joyfully teach you everything there is to know about how the 300 lines of Fuzzyset. At the end, there will be a quiz for you to test your understand

What is Fuzzyset

Fuzzyset.js is a ~300 line JavaScript library that performs approximate (aka "fuzzy") full-text search.

Try it out by searching for something in this very document:

TODO - fuzzyset search box that highlights the matches in this document above some threshold with opacity being correlated ot the similiarty score, and some suggestions below or to the right of the box like "flw state" and "undstng" etc.

Why should you care

If you want to live in a world where we can quickly and joyfully understand the details, we should get good at making explainers. Glen made his attempt at explaining Fuzzyset, and this is mine. Any boredom or frustrating on your part is an opportunity for you to contribute to this grand project. I'd appreciate that feedback. Or publish your own better Fuzzyset explainer!

To additionally pique your curiosity: Fuzzyset uses the same math that makes LLM embeddings work. If you’ve been trying to understand LLMs, this explainer will be great place to start.

The structure of this explanation

This explainer is broken up into questions:

  1. What is a fuzzy match?

  2. How do we find for fuzzy matches in a document?

What makes two words a fuzzy match

There are two commonly used algorithms to determine string similarity. Fuzzyset uses both of these algorithms, so we'll cover them both:

  1. Levenshtein distance: the number of edits to turn one string into the other

  2. Cosign similarity: the similarity between two lists of numbers (aka "vectors")

Levenshtein distance

TODO with interactive

Cosign similarity

TODO with interactive

How we find for fuzzy matches in a document

Now we know how to detect the similarity of two strings, but we need to find fuzzy matches across a whole document.

Test your understanding

TODO: an interactive quiz