跪拜 Guibai
← Back to the summary

A Decorative DSH Plugin Turns Every AI Prompt Into a Unique, Spinning Nebula

前言

When I was a child, I loved the starry sky. Later, I spent every day talking to AI, and it occurred to me: why not let each sentence grow an extra star in the sky?

And so came SemanticNebula · 语义星云 (package name dsh-spiral), a purely decorative plugin for the DeepSeek Harness (DSH) Web GUI. You type normally in the input box and press Enter, and the deep space at the lower right grows a galaxy belonging to that sentence, with a semantic coordinate falling beside it.

It improves no efficiency, does not summarize, does not retrieve, does not help you rewrite prompts. It simply gives a corner of DSH a slowly rotating deep space.

This post talks about why it was made, what design choices were deliberate, what happens from a sentence to the visual, and finally answers directly two questions that almost every viewer asks: "With over 8000 dimensions, is each dimension a light point in the star map?" and "So is every star map unique?" The answers to these two questions are far more interesting than a simple "yes."

在这里插入图片描述


一、创作背景:想做「真语义」,最后选了「不打扰」

The initial idea was actually quite serious: run a local bge-small-zh-v1.5-int8.onnx, encode prompts into true semantic vectors, and pair that with a precomputed UMAP terrain so that semantically similar sentences land in adjacent star regions. It sounded reasonable and gave a sense of "craftsmanship."

But when I actually started, it became clear that for something that is just a decorative piece in a corner, the cost was too heavy: you need to download model files, host weights, run inference in the browser, handle the white screen on first load, and convince users that "this plugin will not send my conversation content out." Why should a decoration ask users to pay all that?

So I reversed the goals:

The final approach is deterministic local hash embedding + fixed projection geometry: no model files, no network requests, a client bundle of about 130 KB, and zero runtime dependencies. The trade-off is also plain: it is not a semantic model. Hashing can only guarantee that "the same text produces the same shape," not that "similar sentences look similar." I will confess this trade-off honestly in the last section, not hide it in an appendix.

二、它长什么样:一片会转的深空,和一张足迹图

Click the milky floating ball at the lower right, and a 520 × 352 window opens: the nebula on the left, the semantic footprint map on the right.

Left side is a four-arm spiral galaxy: a soft glowing core at the center, four spiral arms slowly unwinding in the direction of rotation, dense dust speckles along the arms, and further out, bokeh blobs and needle-like background stars. The whole field breathes with a period of about 30 seconds and an amplitude of ±1.6%. Each of the four arms has a tiny glowing point slowly moving outward, and on average a meteor streaks diagonally across every ten seconds or so. When the mouse moves over, the entire field shifts slightly toward the pointer, and nearby star points brighten; a light click sends out a ripple that spreads and then dissipates.

Right side is a semantic footprint map: historical submissions are connected into a trajectory by time, and the current sentence falls on a point in the coordinate grid. When collapsed, the floating ball takes on the semantic color of that sentence.

Several details were deliberately refined. Which ones?

  1. A hard privacy boundary: the only capture point is "submit"—SessionSnapshot.pendingSubmissions and user/message events. There is no onInput, no reading of input box content, no handling of streaming tokens. Persistence writes only to local localStorage: the raw prompt, the timestamp, and a 256-segment quantized profile.
  2. Physical consistency: the winding direction of the spiral arms matches the rotation direction; arms always trail behind the rotation. As a density wave, the overall pattern rotates rigidly, while the inner filaments rotate slightly faster and the outer dust slower, reflecting differential rotation. At one point the direction flipped with color scheme, so switching colors instantly reversed the whole galaxy, which looked very fake. That was fixed by making angle the single source of angular velocity.
  3. Appearance: the panel reads the host's CSS design tokens, light mode is white glass, dark mode is dark glass; but the two canvases are always deep space—outside the porthole is space, only the window frame changes paint. Adaptation is done purely with CSS, reading data-ds-dark-theme on <body>, without subscribing to theme events or triggering extra renders.
  4. Respects prefers-reduced-motion: trails, parallax, breathing, meteors, glowing points, and ripples are all disabled, and particles are not stacked; only an extremely slow drift remains, rather than freezing into a static image.
  5. Semantic roaming: click play to walk through the shape changes token by token in submission order; after the model reply is complete, the button becomes "Play reply semantic roam." The window can be dragged, resized, and collapsed back to the floating ball.

In settings, you can disable the entire feature, decide whether to auto-expand, whether to save footprints, and switch between "8192 Ultra / 5120 Smooth" and three color schemes: "Deep Space / Aurora / Corona."

在这里插入图片描述

三、从一句话到 8192 维频谱

All computation happens in the browser, roughly like this:

submit event → text normalization → feature extraction (Chinese and English n-gram)
        → sparse hash impulses (8192 buckets) → FFT Gaussian smoothing → L2 normalization
        → folded into a 256-segment brightness profile + 3D semantic direction
        → Canvas 2D: use the profile to modulate a fixed set of particles

3.1 采集:只在「提交」时动手

The controller binds to the host's sessions.binding(sessionId) per session and subscribes to session snapshots and event windows. The earliest reliable signal of a submit is the pending echo accepted by the host; the user/message event serves as a fallback and is used to rebuild history.

// controller.ts (excerpt)
private capture(sessionId: string, rawText: string, options: {...}) {
  if (!this.settingsValue.enabled) return
  const text = normalizeText(rawText)       // remove NUL, collapse whitespace
  if (text.length === 0) return
  const store = this.storeFor(sessionId)
  if (store.hasId(options.id)) return       // count the same message only once
  if (!options.live && this.consumePending(text)) return
  const analysis = analyze(text, this.settingsValue.dims)
  store.add({ id: options.id, text: text.slice(0, 4000), ...analysis })
}

Deduplication uses message id, plus a 15-second window for adjacent duplicates; history keeps at most 72 points. That means typing does not participate in computation at all; only the press of Enter generates a star.

3.2 特征:中英文分开照顾

collectFeatures() first performs NFKC normalization, lowercasing, and whitespace collapsing, then extracts features at different granularities:

Feature Meaning Weight
w: Latin words / numeric words 1.35
t: in-word trigrams 0.42
p: first and last trigram of long words 0.30
c: single Chinese character 1.05
b: Chinese character bigrams 1.65
g:/s: Chinese trigrams / skip bigrams 0.72 / 0.32
x:/y: fingerprints of first 48 / last 32 characters of sentence 0.38 / 0.26

Repeated features are weighted by 1 + ln(count) × 0.55, and after sorting, at most 640 are kept. In mixed Chinese-English text, the Chinese bigram weight is even higher than English words because the information density of Chinese prompts is naturally concentrated in adjacent characters. The head/tail fingerprints are reserved for long texts: relying only on local n-grams, two long different texts might extract similar sets of fragments; the whole-sentence fingerprints pull them apart.

3.3 8192 维:稀疏脉冲 + FFT 高斯平滑

The "8192 dimensions" here are not semantic dimensions like BERT, but hash coordinate buckets. Each feature uses an FNV-1a variant with three rounds of avalanche to compute a 32-bit hash, then scatters 7 signed impulses into 8192 buckets:

// engine.ts (excerpt)
for (const feature of features) {
  const h = hashString(feature.key)
  for (let k = 0; k < 7; k++) {
    const idx = (h + Math.imul(k, 0x9e3779b1)) & (FFT_SIZE - 1)  // FFT_SIZE = 8192
    const sign = (h >>> (k * 3)) & 1 ? 1 : -1
    sparse[idx] += sign * feature.weight / (1 + k * 0.36)
  }
}

The impulses are discrete points; drawing them directly would produce noise. So a circular Gaussian smoothing is applied: precompute the σ = 4.6 Gaussian kernel in FFT, multiply in frequency domain, then inverse transform. Each point spreads into a small bump, and adjacent buckets become correlated, turning discrete impulses into a continuous "spectrum." Then a small amount of the original sparsity is added back (SPARSE_GAIN = 0.075) to preserve detail, plus a low-frequency tilt whose phase is set by the whole-sentence hash to prevent the large-scale shape from degenerating into a regular ring, and finally L2 normalization makes it a unit vector.

A full FFT forward + frequency multiply + inverse transform runs on 8192 points, implemented with handwritten iterative JS. The repo's own scripts/test-engine.mjs runs analyze() 60 times locally, measuring about 0.8 ms per call—that overhead happens at the moment of pressing Enter, and is imperceptible.

3.4 折叠:8192 → 256 段轮廓

8192 numbers cannot directly drive the visuals, and shouldn't. profileOf() groups them in sets of 32 buckets and folds them into a 256-segment brightness profile:

// engine.ts (excerpt)
for (let i = 0; i < dims; i++) {
  const band = Math.floor(i * PROFILE_BANDS / dims)   // PROFILE_BANDS = 256
  sums[band] += v
  squares[band] += v * v
}
// For each segment, take RMS as energy and the mean as the signed component
profile[b] = Math.pow(rms / maxEnergy, 0.72)          // gamma to compress dynamic range
smooth[b] = prev * 0.22 + profile[b] * 0.56 + next * 0.22  // three-point blur

This yields two 256-segment arrays: profile (0..1, the nebula's brightness profile) and signed (-1..1, used only for projection). When persisted, each is quantized to 1 byte per segment and stored as base64 in localStorage, so even 72 history entries take little space.

3.5 语义坐标:三个固定随机基

The coordinates on the right footprint map are the 3D direction obtained by taking dot products of signed with three fixed ±1 random bases (Rademacher vectors, seed 0x5e6b1a7d, centered and normalized). The first two dimensions are multiplied by 1.18 and clamped to ±1:

const axis = normalize(basis.map(b => dot(signed, b)))
mapX = clamp(axis[0] * 1.18, -1, 1)
mapY = clamp(axis[1] * 1.18, -1, 1)

(The above is equivalent pseudocode; the source uses unrolled handwritten loops, Math.hypot, and Math.max/min.) This is a fixed random projection, not UMAP, not PCA. It stably flattens textual differences onto a plane, but offers no "semantic proximity" guarantee. The color scheme also comes from the whole-sentence hash: hashString(text, 0x7c3f91b5) % 6 gives a schemeBase in 0..5, and one of the "Deep Space / Aurora / Corona" palettes maps that to one of 4 color families, ultimately determining the colors of the spiral arms, core, and ambient light.

3.6 Canvas 2D:固定粒子 + 轮廓调制

This is the most easily misunderstood part. When the component mounts, the nebula canvas uses a fixed seed makeRng(0x2f8a1c3d) to generate all particles in one go:

From then on, no new particles are created per frame; only the current 256-segment profile modulates their brightness, size, and radial position:

// NebulaCanvas.tsx (excerpt)
const pv = profile[particle.band]!                    // the profile segment this particle is bound to
const theta = particle.arm * (TAU / 4) + particle.t * WIND
            + pv * WIND_WOBBLE + particle.jitter + angle * 0.8
const r = radius * (0.06 + particle.t * 1.02) * (0.92 + pv * 0.16)
ctx.globalAlpha = (0.024 + pv * 0.09) * fade
ctx.drawImage(sprites.get(color), x - size / 2, y - size / 2, size, size)

The profile value pv affects the spiral arm's pitch (WIND_WOBBLE), radius, particle transparency, and size. In other words: the profile is the score, the particles are the musicians; the prompt determines how the score rises and falls, not how many musicians are on stage.

Drawing uses globalCompositeOperation = 'lighter' for additive blending, along with a SpriteCache that caches each color's 64×64 soft glow sprite as a bitmap—creating a createRadialGradient per particle for thousands of particles would be a performance disaster; after caching it's just drawImage. The spiral arm ridge lines are drawn with 5 layered strokes of decreasing width and radial fading, avoiding the flat clipped ribbon that a wide brush would leave at the outer edge. The core is "a wide dark halo + a small bright core + four diamond-shaped rays narrowing toward the tips," with each layer kept below the saturation threshold of additive blending, so it reads as a star rather than a white disk. Finally, a 128² noise texture is composited with overlay, giving the dark areas a bit of film grain and also suppressing color banding in 8-bit gradients.

These ambient layers are deliberately limited to "at most a few extra draws per frame": one pattern fill for grain, one gradient line for meteors, two arcs for ripples, four sprites for glowing points. Measured at a stable 60 fps on a 520 × 352 canvas. When the window is not visible or the page is hidden, IntersectionObserver and visibilitychange directly stop the requestAnimationFrame.

3.7 工程形态

The plugin has a host half and a client half. The host half's apply() in src/index.ts is empty—its only purpose is to make the bundle listable and let the module loader discover the dsh.client metadata. Two declarations in package.json each handle a segment:

{
  "dsh": {
    "bundle": { "patch": "./cordis.patch.yml" },
    "client": {
      "platform": "web",
      "inject": [
        "@deepseek-ai/dsh-client-ui-sidebar-right",
        "@deepseek-ai/dsh-api-session-controller"
      ]
    }
  }
}

dsh.bundle.patch makes the plugin installable, and dsh.client.inject declares which host services the client borrows (the right sidebar mount point and session controller). What actually makes the host load it is the insert entry in cordis.patch.yml. esbuild bundles the client into a single lib/client.js with no runtime dependencies.

The rotation direction and the spiral arm winding are hard constraints, and the repo includes an offline physics regression: it mounts the real component onto a blank page, back-computes the angular velocity from "whole-circle angular mean correlation," and the winding direction from "the slope of the fourth-order angular harmonic phase versus radius," then asserts they point the same way. No server or token is needed.

四、8192 维,是不是 8192 个光点?

No. This is the most common misunderstanding, and it's understandable—"high-dimensional vector" sounds like it should have many points. But in this implementation, the three things are on completely different levels:

Layer Count What it is Determined by
Hash spectrum 8192 (switchable to 5120) Continuous vector after Gaussian smoothing of sparse impulses; essentially coordinate buckets prompt text
Brightness profile 256 segments Each 32 dimensions folded into one segment RMS, then gamma, blur, normalize 8192-dim vector
Canvas light points ~1100 + decoration layers Static particles generated once at mount, modulated per frame by the profile fixed random seed + profile

Which three points?

First, the dimensions are compressed 32 times. The 8192 buckets are folded into 256 segments of 32 each. Only the energy (RMS) and mean are kept per segment. Then after gamma 0.72 and a three-point blur, on the canvas they're quantized to 1 byte per segment. By then, the dimensions have long become sample points on a continuous curve, not "individually countable things."

Second, the number of light points is constant. 880 arm particles, 140 background stars, and so on are set by a fixed random seed before you submit any sentence. Changing the prompt doesn't add or remove a star; what changes is how much each one is lit, the pitch and radius of the arms, and the overall palette. When there's no submission, the canvas uses an inline, slowly undulating synthetic profile over time, so even the empty panel breathes—that galaxy belongs to no sentence.

Third, the "8192/5120" setting doesn't change geometry. Even the code comments state this explicitly: analyze(text, _dims) ignores the passed dimension and always computes the profile and coordinates with the full 8192-point spectrum; dims only determines particle density at render time:

const density = state.settings.dims === 8192 ? 1 : 0.62
const armCount = Math.floor(arms.length * density)   // 880 → 545

The repo's scripts/test-engine.mjs asserts exactly this: for the same set of Chinese and English prompts, the two settings (8192 and 5120) must produce identical axis, mapX/mapY, schemeBase, and magnitude with tolerance < 1e-9. So "5120 Smooth" reduces particle density for frame rate, not a different galaxy shape.

In one sentence: dimensions are not light points; dimensions are control signals. The 8192 buckets make different texts produce sufficiently distinguishable spectra, the 256-segment profile translates the spectrum into undulations, and the particle field paints those undulations as beautiful light.

五、每张星图都是独一无二的吗?

This question needs to be answered in three layers; simply saying "yes" would not be honest.

5.1 同一句话,一定是同一张图

The algorithm is deterministic: NFKC normalization → fixed-weight features → fixed hash → fixed Gaussian kernel → fixed random bases → fixed palette family. No Math.random() participates in the nebula itself, and no model inference introduces floating-point uncertainty. The same prompt (equivalent after case and whitespace normalization) will produce exactly the same 256-segment profile, the same palette family, and the same footprint coordinate on any machine, in any session. An empty string also has a dedicated empty feature fallback, so it won't fall into a random branch.

That means it is reproducible: the sentence you wrote last week, if you type it again today, the galaxy is still the same galaxy.

5.2 不同句子,几乎不会长出同一片星系

The sources of sensitivity are several:

In test-engine.mjs, four very different prompts are included (colloquial Chinese, an English refactoring request, Rust vector search, a four-character short phrase), and the test asserts that their 3D directions are pairwise distinct, passing with PASS distinct axes 4 / 4: the first sentence lands at axis=[0.342, -0.864, -0.368], while "今天天气不错" (the weather is nice today) lands at axis=[-0.457, 0.454, 0.764], widely separated. The same script also verifies that the first sentence can be split into a 22-frame roaming sequence. In practice, changing a punctuation mark or adding a particle like "吧" makes the nebula's brightness undulation and landing point visibly different.

5.3 但「独一无二」不是数学意义上的

The boundaries need to be made clear, otherwise it's just bragging:

So the accurate statement is:

Every prompt gets a stable, reproducible geometric fingerprint that is visually almost never repeated by another prompt. It is "the trace left by your sentence," not a cryptographic-level unique identifier.

This distinction matters. If one day you truly need "one sentence maps to an absolutely unique identifier," you should use the text hash or message id, not ask a decorative canvas to shoulder that responsibility.

六、坦白:这不是语义模型

The originally envisioned local embedding with bge-small-zh-v1.5-int8.onnx and precomputed UMAP terrain were replaced in the current delivery by deterministic hash embedding and fixed random projection. Therefore:

What you get in return is zero network, zero model files, about 130 KB size, millisecond-level single analysis, and a privacy boundary that can be audited at a glance. For a decoration that "improves no efficiency," I consider this a good trade.

Fortunately, the replacement point is deliberately contained in analyze() in engine.ts: if one day you want to plug in real embeddings, you only need to change that one function; the view layer, particle field, and persistence format all stay untouched.

结语

My favorite moment after finishing is not when it starts spinning, but when I close the panel and only the floating ball remains. The ball and its halo take on the semantic color of the most recent prompt, and a highlight revolves around the ring very slowly.

It truly can't help with anything. But most of the things I say to AI every day wouldn't leave any trace anyway. Now at least they each have a slowly turning star in the sky.

Project address: https://github.com/songzhou666/dsh-spiral , MIT license.

文章标签:DeepSeek Harness DSH 插件 Canvas 2D 数据可视化 前端性能 哈希嵌入 FFT TypeScript