<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Large Language Models on Intellectual Guides</title><link>https://ckw19810413.github.io/en/categories/large-language-models/</link><description>Recent content in Large Language Models on Intellectual Guides</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Tue, 18 Aug 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://ckw19810413.github.io/en/categories/large-language-models/index.xml" rel="self" type="application/rss+xml"/><item><title>Daily Graduate-Concept Fable: Hierarchical Navigable Small World (HNSW)</title><link>https://ckw19810413.github.io/en/blog/obsidian-cellar-hnsw/</link><pubDate>Tue, 18 Aug 2026 00:00:00 +0000</pubDate><guid>https://ckw19810413.github.io/en/blog/obsidian-cellar-hnsw/</guid><description>&lt;p&gt;Good evening! Here is today&amp;rsquo;s &amp;ldquo;Daily Graduate-Concept Fable.&amp;rdquo;&lt;/p&gt;
&lt;h2 id="the-obsidian-cellar-and-the-guide-spiders"&gt;The Obsidian Cellar and the Guide Spiders
&lt;/h2&gt;&lt;p&gt;Deep within the continent of knowledge lies a vast underground library known as the &amp;ldquo;Obsidian Cellar.&amp;rdquo; It holds no paper books; instead, tens of millions of faintly glowing &amp;ldquo;concept stones&amp;rdquo; float within it. Each stone seals away a passage of text or a single idea.&lt;/p&gt;
&lt;p&gt;The cellar has a peculiar rule: the closer in meaning two concept stones are, the closer they sit in space.&lt;/p&gt;
&lt;p&gt;Every day the scholars come to the cellar bearing an &amp;ldquo;unknown stone,&amp;rdquo; trying to find the handful of stones in the cellar most similar to it.&lt;/p&gt;
&lt;p&gt;At first, the scholars used a &amp;ldquo;carpet search.&amp;rdquo; Holding the unknown stone, they would walk to the first concept stone to compare, then the second, then the third… When the number of stones reached the tens of millions, finding a single stone could take the better part of a lifetime, and many scholars dropped dead of exhaustion in the cellar.&lt;/p&gt;
&lt;p&gt;Later, a clever craftsman invented the &amp;ldquo;threading method.&amp;rdquo; Using spider silk, he tied together stones that lay close to one another, forming an enormous three-dimensional spider web.&lt;/p&gt;
&lt;p&gt;Now a scholar had only to pick any stone at random as a starting point, look at its neighbors connected by spider silk, choose the one closest to the target, and walk over to it; then look at the new neighbors, and walk over again. It was like following the vine to find the melon — until there were no closer stones left in the vicinity.&lt;/p&gt;
&lt;p&gt;This method was far faster! But it had two fatal flaws:
First, if the chosen starting point was too far from the target, the scholar would have to crawl across the web for a very, very long time.
Second, the scholar would sometimes walk into a &amp;ldquo;dead end&amp;rdquo; — every stone nearby seemed to be the closest, but the truly perfect answer was actually hidden at the other end of the web, with no spider silk connecting the two.&lt;/p&gt;
&lt;p&gt;Just as the cellar was about to grind to a halt, a blind architect arrived with a group of magical &amp;ldquo;guide spiders.&amp;rdquo; The blind architect did not change the tens of millions of stones at the bottom, but he had the guide spiders build several layers of &amp;ldquo;suspended web&amp;rdquo; above the original cellar.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The top layer (the cloud layer):&lt;/strong&gt; The spiders chose only a tiny fraction of the cellar&amp;rsquo;s stones (roughly one in ten thousand) as &amp;ldquo;intercontinental landmarks,&amp;rdquo; pulled them up to the topmost layer, and connected them with extremely long spider silk.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The middle layer (the city layer):&lt;/strong&gt; One layer down, the spiders chose one percent of the stones as &amp;ldquo;city landmarks&amp;rdquo; and connected them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The bottom layer (the ground layer):&lt;/strong&gt; This kept the original dense network in which all tens of millions of stones were interconnected.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, when a scholar arrives with an unknown stone to search, the treasure hunt becomes exquisitely elegant:&lt;/p&gt;
&lt;p&gt;He takes the elevator straight to the top layer. Here there are only a scant few &amp;ldquo;intercontinental landmarks,&amp;rdquo; and he can tell at a glance which landmark is closest to his target. He takes one giant step and walks onto that landmark.&lt;/p&gt;
&lt;p&gt;Next, he jumps down through the landmark&amp;rsquo;s trapdoor to the layer below — the &amp;ldquo;city layer.&amp;rdquo; Here there are more stones, but he doesn&amp;rsquo;t have to search from scratch, because he has already landed in the correct intercontinental region. Following the city layer&amp;rsquo;s spider silk, he walks a few steps to the nearest city landmark.&lt;/p&gt;
&lt;p&gt;Finally, he descends all the way to the bottom layer. By now he is standing precisely at the doorstep of the target stone&amp;rsquo;s home. He need only take two or three steps across the dense ground layer to find the single most perfect concept stone.&lt;/p&gt;
&lt;p&gt;The blind architect&amp;rsquo;s three-dimensional spider web turned a search that once required ten million comparisons into a flawless journey of just a few dozen light hops across different floors.&lt;/p&gt;
&lt;h2 id="the-reveal-hierarchical-navigable-small-world-hnsw"&gt;The Reveal: Hierarchical Navigable Small World (HNSW)
&lt;/h2&gt;&lt;p&gt;What this story describes is a highly efficient, core graduate-level algorithm from the fields of modern artificial intelligence, vector databases, and large-model retrieval-augmented generation (RAG): the &lt;strong&gt;Hierarchical Navigable Small World (HNSW)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When we build a large knowledge base locally and turn text into high-dimensional vectors (for example, embeddings generated with nomic-embed-text), quickly finding the passages most similar to a user&amp;rsquo;s question among a huge pile of high-dimensional vectors is an enormous challenge.&lt;/p&gt;
&lt;p&gt;Traditional K-Nearest Neighbors (KNN) requires computing the distance to every single vector, giving a time complexity of $O(N)$ — unacceptable when handling data at the million scale. HNSW, by constructing a multi-level graph structure, cleverly combines the idea of the &lt;strong&gt;skip list&lt;/strong&gt; with the properties of the &lt;strong&gt;small-world network&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It lets the algorithm perform large-stride &amp;ldquo;coarse localization&amp;rdquo; early in the search and small-range &amp;ldquo;fine tuning&amp;rdquo; later in the search, successfully compressing the time complexity of high-dimensional vector search down to nearly $O(\log N)$.&lt;/p&gt;
&lt;h2 id="mapping-the-metaphor"&gt;Mapping the Metaphor
&lt;/h2&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Element in the story&lt;/th&gt;
&lt;th&gt;Algorithm &amp;amp; system concept&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;The obsidian cellar and concept stones&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Vector database &amp;amp; text embeddings&lt;/td&gt;
&lt;td&gt;Turning knowledge, documents, or notes into coordinate points in space. The closer in meaning two texts are, the shorter their distance in the multidimensional space.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;The carpet search&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Brute-force Search / Exact KNN&lt;/td&gt;
&lt;td&gt;Computing the distance between the query vector and every vector in the database one by one (e.g., cosine similarity) — extremely time-consuming.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;The flat threading method&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Navigable Small World (NSW) graph&lt;/td&gt;
&lt;td&gt;Connecting adjacent nodes on a single plane only. Prone to getting trapped in a local optimum (a dead end), and inefficient when the starting point is far from the target.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;The floors of the suspended web (cloud, city, ground)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;HNSW&amp;rsquo;s hierarchical layers&lt;/td&gt;
&lt;td&gt;The core of the HNSW algorithm. Layer 0 contains all nodes; the higher the layer, the fewer nodes, decreasing exponentially.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;The intercontinental landmarks at the top&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Entry points in the top layers&lt;/td&gt;
&lt;td&gt;In the sparsest graph layers, they provide long-distance jumping ability, ensuring the algorithm can quickly approach the global region where the target lies.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Descending layer by layer to search&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Greedy search routing&lt;/td&gt;
&lt;td&gt;The algorithm starts at the highest layer; after finding the nearest node in that layer, it passes that node down as the starting point for the next layer, until it reaches layer 0 and finds the final nearest neighbors.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</description></item><item><title>Daily Graduate-Concept Fable: Speculative Decoding</title><link>https://ckw19810413.github.io/en/blog/speculative-decoding-fable/</link><pubDate>Mon, 17 Aug 2026 00:00:00 +0000</pubDate><guid>https://ckw19810413.github.io/en/blog/speculative-decoding-fable/</guid><description>&lt;p&gt;Good evening! Here is today&amp;rsquo;s &amp;ldquo;Daily Graduate-Concept Fable.&amp;rdquo;&lt;/p&gt;
&lt;h2 id="the-clever-apprentice-of-the-royal-scriptorium"&gt;The Clever Apprentice of the Royal Scriptorium
&lt;/h2&gt;&lt;p&gt;At the heart of the empire&amp;rsquo;s capital, the Royal Scriptorium faced a crisis unlike any before.&lt;/p&gt;
&lt;p&gt;The empire&amp;rsquo;s Grand Scholar, &amp;ldquo;Balthazar,&amp;rdquo; was the only person alive with the wisdom to draft the sacred legal code. He had a photographic memory, and his mind held ten million ancient texts. Yet he had one fatal flaw: he wrote far too slowly.&lt;/p&gt;
&lt;p&gt;The scholar&amp;rsquo;s rigor bordered on obsession. For every single word he wrote, he would leaf through countless heavy tomes in the library of his mind, deliberating carefully before slowly setting the word to the page. Having written that word, he would then reconsider everything he had just written to work out the next one. As a result, he could produce only one word per minute. The front lines desperately needed new decrees, yet the scholar could only squeeze them out one word at a time.&lt;/p&gt;
&lt;p&gt;At this point, the scriptorium had a young apprentice named &amp;ldquo;Leo.&amp;rdquo; Leo&amp;rsquo;s learning was nowhere near the scholar&amp;rsquo;s — the books in his head amounted to less than one percent of the scholar&amp;rsquo;s — but he had one strength: he was extremely quick, and he was very good at guessing the scholar&amp;rsquo;s mind.&lt;/p&gt;
&lt;p&gt;After observing for a few days, Leo made a bold proposal to the scholar.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Master, rather than agonizing over every word from scratch, why don&amp;rsquo;t we change how we work?&amp;rdquo; said Leo. &amp;ldquo;Let me be your &amp;lsquo;drafter.&amp;rsquo; In one go, I&amp;rsquo;ll guess the next five words you&amp;rsquo;re likely to write and quickly jot them on a slate. Then you simply look at the slate.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The scholar frowned. &amp;ldquo;Absurd! Your learning is shallow — if the words you write are wrong, they&amp;rsquo;ll ruin the dignity of the code!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Master, you misunderstand,&amp;rdquo; Leo explained with a smile. &amp;ldquo;&lt;strong&gt;Conceiving a word from nothing&lt;/strong&gt; costs you enormous effort hauling tomes through your mind; but &lt;strong&gt;glancing over a few words and judging whether they match your intent&lt;/strong&gt; is effortless and lightning-fast for you. If you find the words I&amp;rsquo;ve written are correct, you simply stamp them with your seal. The moment you spot a single word that differs from what you had in mind, you erase that word and everything after it, write in the correct word yourself, and then I resume guessing from the word you corrected.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Half-doubting, the scholar agreed.&lt;/p&gt;
&lt;p&gt;The work began. Leo swiftly wrote on the slate: &amp;ldquo;The empire / shall / levy / taxes / on the north.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The scholar swept his eyes across it, his mind instantly completing the verification — the five words fit his line of thought perfectly! He immediately stamped his great seal. A sentence that would once have taken five agonizing minutes was now done in seconds.&lt;/p&gt;
&lt;p&gt;Leo then quickly wrote: &amp;ldquo;the tax rate / is / annually / fifty / gold / coins.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The scholar glanced at it, frowned, and pointed to the fourth word: &amp;ldquo;Wrong. Not fifty — &amp;lsquo;one hundred.&amp;rsquo;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;With a sweep of his brush, the scholar erased &amp;ldquo;fifty / gold / coins&amp;rdquo; and wrote in &amp;ldquo;one hundred&amp;rdquo; with his own hand.&lt;/p&gt;
&lt;p&gt;Then, looking at the word &amp;ldquo;one hundred,&amp;rdquo; Leo once more began his rapid guessing and drafting.&lt;/p&gt;
&lt;p&gt;Although Leo sometimes guessed wrong, he hit most ordinary phrasings precisely. Most remarkable of all, the final quality and wording of the code turned out to be &amp;ldquo;exactly identical&amp;rdquo; to what the scholar would have labored over one word at a time — with no compromise whatsoever — yet the overall drafting speed increased several times over.&lt;/p&gt;
&lt;h2 id="the-reveal-speculative-decoding"&gt;The Reveal: Speculative Decoding
&lt;/h2&gt;&lt;p&gt;What this story describes is an exceptionally elegant and pivotal graduate-level algorithm from the field of large-language-model (LLM) inference acceleration: &lt;strong&gt;Speculative Decoding&lt;/strong&gt;. It is also one of the core techniques used by modern high-performance inference engines (such as vLLM) to break through hardware performance bottlenecks.&lt;/p&gt;
&lt;p&gt;In traditional LLM text generation, the model must generate &lt;strong&gt;autoregressively&lt;/strong&gt; — one token after another. For large models with tens of billions of parameters (say, the Qwen 35B class), generating each single token requires hauling tens of gigabytes of weights from GPU memory to the compute cores. This means the bottleneck of large-model inference isn&amp;rsquo;t &lt;strong&gt;compute&lt;/strong&gt; at all, but &lt;strong&gt;memory bandwidth&lt;/strong&gt; — just as, in the story, the scholar has to laboriously haul heavy tomes to write a single word.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speculative decoding&lt;/strong&gt; cleverly breaks this deadlock:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It introduces a tiny, extremely fast &lt;strong&gt;draft model&lt;/strong&gt; (the apprentice, Leo) to quickly generate several consecutive tokens in one go.&lt;/li&gt;
&lt;li&gt;It then hands these generated tokens to the large, precise &lt;strong&gt;target model&lt;/strong&gt; (the scholar) for a single round of &lt;strong&gt;parallel verification&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Because the target model, when &lt;em&gt;verifying&lt;/em&gt; the given tokens, can fully exploit the GPU&amp;rsquo;s massive parallel compute (compute-bound), it can judge in an instant whether these tokens&amp;rsquo; probability distribution matches its own output.&lt;/li&gt;
&lt;li&gt;If accepted, this amounts to generating multiple tokens in a single forward pass; if a token is rejected, the model corrects it at that point, discards the subsequent guesses, and starts over.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The most fascinating mathematical property is this: through a specific verification rejection-sampling algorithm, speculative decoding can guarantee that the final output&amp;rsquo;s probability distribution is mathematically &amp;ldquo;100% equivalent&amp;rdquo; to the distribution the target model would have produced on its own, slow generation — with no loss of generation quality whatsoever.&lt;/p&gt;
&lt;h2 id="mapping-the-metaphor"&gt;Mapping the Metaphor
&lt;/h2&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Element in the story&lt;/th&gt;
&lt;th&gt;LLM inference concept&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Grand Scholar &amp;ldquo;Balthazar&amp;rdquo;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Target Model&lt;/td&gt;
&lt;td&gt;The large, highly accurate language model with a huge parameter count.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Clever apprentice &amp;ldquo;Leo&amp;rdquo;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Draft Model / Proposer&lt;/td&gt;
&lt;td&gt;A tiny, extremely fast small language model (or recent multi-head prediction architectures like MTP / Medusa).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Hauling heavy tomes to write&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Memory-bandwidth bound&lt;/td&gt;
&lt;td&gt;The latency caused by hauling model weights in traditional autoregressive generation.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Glancing over the sentence on the slate&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Parallel Verification&lt;/td&gt;
&lt;td&gt;The target model uses its GPU compute advantage to evaluate multiple tokens&amp;rsquo; probabilities in a single forward pass.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Stamping the seal / erasing and rewriting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Acceptance/Rejection Criterion&lt;/td&gt;
&lt;td&gt;If the draft model&amp;rsquo;s prediction falls within the target model&amp;rsquo;s probability tolerance, it is accepted; otherwise the model rolls back from the erroneous point and the target model supplies the correct token.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Quality unchanged&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Lossless Generation&lt;/td&gt;
&lt;td&gt;Speculative decoding&amp;rsquo;s most important mathematical guarantee: it does not alter the target model&amp;rsquo;s original output probability distribution.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</description></item></channel></rss>