From Cosine to the Edge: Semantic Search in Production
por Frank de Alcantara em 19/07/2026
This article is also available in Portuguese.
1. A Confession and a Project
Over thirteen articles, this series has built mathematical machinery: vectors that represent words, matrix products that transform them, attention mechanisms that contextualize them. All with the implicit promise that this mathematics is good for something. This article keeps that promise. We are going to build, from the inner product to deployment, the semantic search running at this very moment in this blog’s menu, which the attentive reader can question at /busca/ before, during, and after reading. For the first time in the series, this article’s complete application is in production. The laboratories appear beside the mathematics they make manipulable: cosine in Section 4, InfoNCE in Section 7, and approximate search in Section 9.
This article was translated into English using the Claude Fable 5 Model on July 19, 2026
First, the confession. Until recently, this blog’s search was powered by a JavaScript library called lunr.js, running entirely in the browser. Because a static site has no server to process queries, client-side search must carry the indexable documents to the client to build the index. The inherited mechanism serialized in full the pages and articles marked access: open; for all other articles, it carried the first 80 words. In the current build of that old implementation, the generated file is about 70 kB, plus approximately 85 kB for the Lunr library, both measured before HTTP compression. They were not megabytes, nor the full contents of every article. The engineering flaw was elsewhere: every visitor paid for transferring and building an index whose size grew with the collection, even if they never made a single query.
The poor author discovered this while auditing his own site, in the classic circumstance in which such things are discovered: while looking for another problem. We must forgive the innocent man. He inherited the template from another project and had never worried about its structure or chosen technology.
There were, therefore, two flaws to correct, one of engineering and one of quality. We have just described the engineering flaw.
The full article contains practical strategies and exclusive data reserved for our registered members.
Continue with Google Instant free access for registered readers(Updated: )