You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vitepress-plugin-moss/README.md
+67-23Lines changed: 67 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# vitepress-plugin-moss
2
2
3
-
A [VitePress](https://vitepress.dev) plugin that adds [Moss](https://moss.dev) semantic (AI) search to your docs. At build time it reads your Markdown source, chunks it, and uploads it to the Moss cloud. At runtime the search UI downloads the index once and runs all queries locally in the browser — no round-trips on every keystroke.
3
+
A [VitePress](https://vitepress.dev) plugin that adds [Moss](https://moss.dev) semantic (AI) search to your docs. At build time it reads your Markdown source, chunks it, and uploads it to the Moss cloud. At runtime the search UI uses a **hot-path**: it queries the cloud immediately so search works from the very first keystroke, while the local model and index download in the background. Once ready, all queries automatically switch to sub-10 ms on-device search — no user action needed.
VitePress calls buildEnd hook User presses Ctrl/⌘+K or /
13
13
↓ ↓
14
-
mossIndexerPlugin reads siteConfig @inferedge/moss downloads the index
14
+
mossIndexerPlugin reads siteConfig Phase 1 — SDK imported, client created
15
+
↓ Queries routed to Moss cloud ← hot-path
16
+
@moss-tools/md-indexer reads source .md (instant results from first keystroke)
17
+
using VitePress's own markdown renderer ↓ (parallel)
18
+
(understands includes, extensions, etc.) Phase 2 — model + index download (background)
15
19
↓ ↓
16
-
@moss-tools/md-indexer reads source .md Queries run locally < 10 ms
17
-
using VitePress's own markdown renderer ↓
18
-
(understands includes, extensions, etc.) Results navigate via metadata.navigation
19
-
↓ (pre-computed URL + anchor per chunk)
20
-
Uploads via @inferedge-rest/moss REST client
21
-
(deletes old index, then re-uploads chunks)
22
-
↓
23
-
Index is live on Moss cloud
20
+
Uploads via @inferedge-rest/moss REST client Index ready → queries switch to local < 10 ms
21
+
(deletes old index, then re-uploads chunks) ↓
22
+
↓ Active query re-run with local index
23
+
Index is live on Moss cloud (seamless handoff, no user action needed)
24
24
```
25
25
26
26
Two separate npm packages are involved:
@@ -163,46 +163,90 @@ If indexing fails (network error, bad credentials, etc.) the build **does not fa
163
163
164
164
---
165
165
166
+
## Creating and Loading Indexes
167
+
168
+
### Automatic indexing on build
169
+
170
+
When you run `vitepress build`, the `mossIndexerPlugin` automatically builds and uploads the index to Moss at the end of the build. No extra step is needed — just make sure your credentials are set in environment variables.
171
+
172
+
### Manual indexing with `index:docs`
173
+
174
+
The demo site includes a standalone script for building and uploading the index without running a full VitePress build. This is useful when you update documentation content and want to refresh the index quickly.
175
+
176
+
```bash
177
+
# From demo-site/
178
+
pnpm index:docs # index the documentation/ folder (default)
179
+
pnpm index:docs docs # index the docs/ folder instead
180
+
pnpm index:docs documentation --inspect # preview chunks as JSON, no upload
181
+
```
182
+
183
+
The script:
184
+
185
+
1. Reads all `.md` files and chunks them using `@moss-tools/md-indexer`
186
+
2. Filters out chunks with 3 or fewer words (lone headings, empty sections, nav-only content)
187
+
3. Uploads the remaining chunks to your Moss index
188
+
189
+
The `--inspect` flag writes chunks to `.index-preview.json` and exits without uploading — useful for verifying index quality before committing to an upload.
190
+
191
+
---
192
+
166
193
## Testing Locally (Demo Site)
167
194
168
-
The repository includes a ready-to-use demo site in the `demo-site/` folder. This is the best way to test changes to the plugin.
195
+
The repository includes a demo site in `demo-site/` with two VitePress sites:
196
+
197
+
-**`documentation/`** — full Moss SDK docs with Moss search enabled (recommended for testing)
198
+
-**`docs/`** — minimal site
169
199
170
200
### Step 1 — Build the plugin
171
201
172
-
First, build the plugin from the root directory to generate the `dist` folder.
202
+
From the repository root:
173
203
174
204
```bash
175
205
pnpm install
176
206
pnpm build
177
207
```
178
208
179
-
### Step 2 — Set up the Demo Site
180
-
181
-
Navigate to the demo site directory and install its dependencies.
209
+
### Step 2 — Set up the demo site
182
210
183
211
```bash
184
212
cd demo-site
185
213
pnpm install
186
214
```
187
215
188
-
### Step 3 — Configure and Build
216
+
Create a `.env` file with your Moss credentials:
217
+
218
+
```bash
219
+
# demo-site/.env (never commit this file)
220
+
MOSS_PROJECT_ID=your_project_id
221
+
MOSS_PROJECT_KEY=your_api_key
222
+
MOSS_INDEX_NAME=your_index_name
223
+
```
224
+
225
+
### Step 3 — Populate the index
189
226
190
-
The demo site is already configured to use the local plugin. You just need to add your Moss credentials to `demo-site/docs/.vitepress/config.ts` (or use environment variables).
227
+
Before starting the dev server, upload the documentation to your Moss index:
191
228
192
229
```bash
193
-
# From inside demo-site/
194
-
npx vitepress build docs
230
+
# From demo-site/
231
+
pnpm index:docs
195
232
```
196
233
197
-
### Step 4 — Preview
234
+
You only need to re-run this when you add or change Markdown content.
198
235
199
-
Start the preview server to test the search modal.
236
+
### Step 4 — Start the dev server
200
237
201
238
```bash
202
-
npx vitepress preview docs
239
+
pnpm documentation:dev
203
240
```
204
241
205
-
Open [http://localhost:4173](http://localhost:4173) in your browser and verify the search functionality.
242
+
Open [http://localhost:5173](http://localhost:5173) and use `Ctrl/⌘+K` or `/` to test the search modal.
243
+
244
+
### Production build
245
+
246
+
```bash
247
+
pnpm docs:build # builds docs/ site (also runs pnpm build in plugin root first)
248
+
pnpm docs:preview # preview at http://localhost:4173
0 commit comments