promptgraph-mcp 2.8.1 → 2.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -205
- package/ann.js +33 -33
- package/api.js +202 -202
- package/bundle-counts.js +111 -111
- package/chunker.js +28 -28
- package/cli.js +115 -115
- package/commands/bundle.js +150 -150
- package/commands/doctor.js +15 -15
- package/commands/import.js +7 -7
- package/commands/init.js +37 -37
- package/commands/marketplace.js +146 -146
- package/commands/reindex.js +10 -10
- package/commands/search.js +55 -55
- package/commands/setup.js +19 -19
- package/commands/status.js +110 -110
- package/commands/train.js +18 -18
- package/commands/update.js +49 -49
- package/commands/validate.js +63 -63
- package/config.js +72 -72
- package/db.js +157 -157
- package/doctor.js +48 -48
- package/embedder.js +54 -54
- package/github-import.js +750 -745
- package/indexer.js +310 -310
- package/package.json +61 -61
- package/parser.js +69 -69
- package/pg-hook.js +70 -70
- package/platform.js +120 -120
- package/search.js +216 -216
- package/src/filter/classifier.js +88 -88
- package/src/filter/hard-filter.js +62 -62
- package/src/filter/train.js +66 -66
- package/src/reranker/reranker.js +92 -92
- package/src/store/flat-store.js +61 -61
- package/src/store/hnsw-store.js +187 -187
- package/src/store/index.js +19 -19
- package/src/store/vector-store.js +9 -9
- package/src/utils/rate-limiter.js +33 -33
- package/tui.js +418 -418
- package/validate-repo-action.js +139 -139
- package/watcher.js +84 -84
package/README.md
CHANGED
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
# PromptGraph
|
|
2
|
-
|
|
3
|
-
**Semantic skill router and marketplace for Claude Code.**
|
|
4
|
-
|
|
5
|
-
Instead of loading every `.md` skill into your context, Claude calls `pg_search` and loads only the one skill it needs.
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/promptgraph-mcp)
|
|
8
|
-
[](LICENSE)
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## How it works
|
|
13
|
-
|
|
14
|
-
```
|
|
15
|
-
pg_search("refactor without breaking tests")
|
|
16
|
-
→ embed query (BGE-Small-EN, 384-dim)
|
|
17
|
-
→ ANN index (HNSW by default, flat fallback) — topK×4 candidates
|
|
18
|
-
→ BM25 (FTS5) — topK×4 candidates
|
|
19
|
-
→ hybrid merge (embedWeight × cosine + bm25Weight × BM25)
|
|
20
|
-
→ term-overlap reranker (TF frequency + header-position boost)
|
|
21
|
-
→ return topK skill paths + snippets
|
|
22
|
-
→ Claude reads only the files it needs
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
**Index:** SQLite + Float32 BLOB embeddings + HNSW approximate nearest neighbor (configurable: `PG_VECTOR_STORE=flat` for brute-force cosine). No external vector DB, no API key, no cloud.
|
|
26
|
-
|
|
27
|
-
**Reranker:** lightweight term-overlap scorer (binary overlap + TF frequency + header-position boost). Not a cross-encoder — disable via `PG_RERANKER=0`.
|
|
28
|
-
|
|
29
|
-
**File watcher:** `chokidar` detects `.md` changes and reindexes automatically (MCP server mode only).
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Benchmarks (measured on real hardware)
|
|
34
|
-
|
|
35
|
-
| Operation | Result |
|
|
36
|
-
|---|---|
|
|
37
|
-
| 88 new skills indexed (first time, cold ONNX) | **49.5 s** |
|
|
38
|
-
| 88 skills reindexed (unchanged, hash match) | **< 1 s** |
|
|
39
|
-
| `pg reindex --fast` (3000 files, keyword only) | **~30 s** |
|
|
40
|
-
| `pg reindex` full embed (3000 files) | **~30 min** |
|
|
41
|
-
| Semantic search query (HNSW) | **< 50 ms** |
|
|
42
|
-
| Semantic search query (flat, brute-force) | **< 200 ms** |
|
|
43
|
-
| Model size (BGE-Small-EN-v1.5, one-time download) | **23 MB** |
|
|
44
|
-
| Embedding dimensions | **384** |
|
|
45
|
-
| Max chunks per skill | **8** (configurable: `PG_MAX_CHUNKS`) |
|
|
46
|
-
| Embedding batch size | **256** |
|
|
47
|
-
|
|
48
|
-
> ONNX model initialization (~2–3 min) happens once on first use and is cached in `~/.claude/.promptgraph/model-cache/`.
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## Environment Variables
|
|
53
|
-
|
|
54
|
-
| Variable | Default | Description |
|
|
55
|
-
|---|---|---|
|
|
56
|
-
| `PG_VECTOR_STORE` | `hnsw` | Vector index: `hnsw` (ANN, faster at scale) or `flat` (brute-force cosine) |
|
|
57
|
-
| `PG_RERANKER` | `1` | Enable term-overlap reranker after hybrid search (set `0` to disable) |
|
|
58
|
-
| `PG_MAX_CHUNKS` | `8` | Max semantic chunks per skill (higher = more detail per long file, more embedding cost) |
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## Quick Start
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
npm install -g promptgraph-mcp@latest
|
|
66
|
-
pg init
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`pg init` downloads the model (~23 MB, once), indexes your local skills, and prints the config snippet.
|
|
70
|
-
|
|
71
|
-
### Claude Code (`~/.claude/settings.json`)
|
|
72
|
-
|
|
73
|
-
```json
|
|
74
|
-
{
|
|
75
|
-
"mcpServers": {
|
|
76
|
-
"promptgraph": {
|
|
77
|
-
"command": "npx",
|
|
78
|
-
"args": ["promptgraph-mcp"]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Claude Desktop / Cursor / Windsurf / Cline
|
|
85
|
-
|
|
86
|
-
Same config — any MCP-compatible client works.
|
|
87
|
-
|
|
88
|
-
### OpenCode (`~/.config/opencode/opencode.json`)
|
|
89
|
-
|
|
90
|
-
```json
|
|
91
|
-
{
|
|
92
|
-
"mcp": {
|
|
93
|
-
"promptgraph": {
|
|
94
|
-
"type": "local",
|
|
95
|
-
"command": ["npx", "promptgraph-mcp"],
|
|
96
|
-
"enabled": true
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
> `pg setup` auto-detects installed clients and writes config automatically.
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## CLI
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
pg init # first-time setup
|
|
110
|
-
pg status # show indexed sources, repos, installed bundles
|
|
111
|
-
pg reindex # full reindex (semantic search, slow)
|
|
112
|
-
pg reindex --fast # keyword-only reindex (~30s, no embeddings)
|
|
113
|
-
pg search "deploy" # search from terminal
|
|
114
|
-
pg import owner/repo # clone and index any GitHub repo of .md skills
|
|
115
|
-
pg marketplace # browse skills by category
|
|
116
|
-
pg marketplace bundles # browse curated bundles
|
|
117
|
-
pg bundle install <id> # install a bundle
|
|
118
|
-
pg validate my-skill.md # validate before publishing
|
|
119
|
-
pg doctor # clean orphaned DB rows
|
|
120
|
-
pg update # update to latest version
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
## Marketplace
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
pg marketplace # 🛠 Engineering 💻 Coding 🤖 AI Tools 🔒 Security 🎨 Creative
|
|
129
|
-
pg marketplace Engineering # filter by category
|
|
130
|
-
pg marketplace bundles # install whole repos as skill bundles
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
**Bundles** install an entire GitHub repo as a skill source — auto-detects `skills/`, `commands/`, `prompts/` subdirectory.
|
|
134
|
-
|
|
135
|
-
Example:
|
|
136
|
-
```bash
|
|
137
|
-
pg bundle install elementalsouls-claude-bughunter # 88 security skills from GitHub
|
|
138
|
-
pg bundle install engineering-essentials # 4 curated workflow skills
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
**Publish your skill** (auto-validated, no manual review):
|
|
142
|
-
|
|
143
|
-
Open an issue on [promptgraph-registry](https://github.com/NeiP4n/promptgraph-registry) with label `skill-submission`. The bot fetches, validates, commits, and closes the issue automatically.
|
|
144
|
-
|
|
145
|
-
Anti-spam checks: min 200 chars, 2+ headers, code/bullets required, prompt injection detection, duplicate URL/description check, 3 submissions per user per 24h.
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
## MCP Tools
|
|
150
|
-
|
|
151
|
-
Claude uses these automatically when the MCP server is running:
|
|
152
|
-
|
|
153
|
-
| Tool | What it does |
|
|
154
|
-
|---|---|
|
|
155
|
-
| `pg_search` | Semantic search by task description |
|
|
156
|
-
| `pg_list` | List all indexed skills |
|
|
157
|
-
| `pg_context` | Full skill details + callers/callees |
|
|
158
|
-
| `pg_callers` | Which skills reference this one |
|
|
159
|
-
| `pg_callees` | Which skills this one calls |
|
|
160
|
-
| `pg_impact` | What breaks if this skill changes |
|
|
161
|
-
| `pg_marketplace_browse` | Browse community registry |
|
|
162
|
-
| `pg_marketplace_install` | Install a skill by code or name |
|
|
163
|
-
| `pg_bundle_browse` | Browse skill bundles |
|
|
164
|
-
| `pg_bundle_install` | Install a bundle |
|
|
165
|
-
| `pg_top_rated` | Highest-rated skills |
|
|
166
|
-
| `pg_rate` | Rate a skill after use |
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
## Search modes
|
|
171
|
-
|
|
172
|
-
Search runs a multi-stage pipeline:
|
|
173
|
-
|
|
174
|
-
1. **ANN retrieval** — HNSW approximate nearest neighbor (default) or flat brute-force cosine (`PG_VECTOR_STORE=flat`)
|
|
175
|
-
2. **BM25 keyword** — SQLite FTS5
|
|
176
|
-
3. **Hybrid fusion** — weighted sum (embedding × embedWeight + BM25 × bm25Weight, adaptive per query)
|
|
177
|
-
4. **Reranker** — term-overlap rescoring with TF frequency and header-position boost (disable via `PG_RERANKER=0`)
|
|
178
|
-
5. **Rating boost** — success/fail history adjusts final ranking
|
|
179
|
-
|
|
180
|
-
Falls back to FTS5 only if no embeddings exist.
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## Skill filtering
|
|
185
|
-
|
|
186
|
-
When importing a GitHub repo, PromptGraph:
|
|
187
|
-
1. Looks for a dedicated subdir (`skills/`, `commands/`, `prompts/`, `agents/`, `templates/`, etc.) — indexes only that dir if found with 2+ `.md` files
|
|
188
|
-
2. Falls back to repo root with content quality filter: min 150 chars, 2+ headers, must have code blocks or bullet points, skips readme/changelog/license/docs
|
|
189
|
-
|
|
190
|
-
---
|
|
191
|
-
|
|
192
|
-
## Requirements
|
|
193
|
-
|
|
194
|
-
- Node.js 18+
|
|
195
|
-
- Any MCP-compatible client (Claude Code, Claude Desktop, Cline, OpenCode, Cursor, Windsurf…)
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
## Related
|
|
200
|
-
|
|
201
|
-
- 📋 [promptgraph-registry](https://github.com/NeiP4n/promptgraph-registry) — community skill registry and auto-publish bot
|
|
202
|
-
|
|
203
|
-
---
|
|
204
|
-
|
|
205
|
-
*Built with [Claude Code](https://claude.com/claude-code).*
|
|
1
|
+
# PromptGraph
|
|
2
|
+
|
|
3
|
+
**Semantic skill router and marketplace for Claude Code.**
|
|
4
|
+
|
|
5
|
+
Instead of loading every `.md` skill into your context, Claude calls `pg_search` and loads only the one skill it needs.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/promptgraph-mcp)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## How it works
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
pg_search("refactor without breaking tests")
|
|
16
|
+
→ embed query (BGE-Small-EN, 384-dim)
|
|
17
|
+
→ ANN index (HNSW by default, flat fallback) — topK×4 candidates
|
|
18
|
+
→ BM25 (FTS5) — topK×4 candidates
|
|
19
|
+
→ hybrid merge (embedWeight × cosine + bm25Weight × BM25)
|
|
20
|
+
→ term-overlap reranker (TF frequency + header-position boost)
|
|
21
|
+
→ return topK skill paths + snippets
|
|
22
|
+
→ Claude reads only the files it needs
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Index:** SQLite + Float32 BLOB embeddings + HNSW approximate nearest neighbor (configurable: `PG_VECTOR_STORE=flat` for brute-force cosine). No external vector DB, no API key, no cloud.
|
|
26
|
+
|
|
27
|
+
**Reranker:** lightweight term-overlap scorer (binary overlap + TF frequency + header-position boost). Not a cross-encoder — disable via `PG_RERANKER=0`.
|
|
28
|
+
|
|
29
|
+
**File watcher:** `chokidar` detects `.md` changes and reindexes automatically (MCP server mode only).
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Benchmarks (measured on real hardware)
|
|
34
|
+
|
|
35
|
+
| Operation | Result |
|
|
36
|
+
|---|---|
|
|
37
|
+
| 88 new skills indexed (first time, cold ONNX) | **49.5 s** |
|
|
38
|
+
| 88 skills reindexed (unchanged, hash match) | **< 1 s** |
|
|
39
|
+
| `pg reindex --fast` (3000 files, keyword only) | **~30 s** |
|
|
40
|
+
| `pg reindex` full embed (3000 files) | **~30 min** |
|
|
41
|
+
| Semantic search query (HNSW) | **< 50 ms** |
|
|
42
|
+
| Semantic search query (flat, brute-force) | **< 200 ms** |
|
|
43
|
+
| Model size (BGE-Small-EN-v1.5, one-time download) | **23 MB** |
|
|
44
|
+
| Embedding dimensions | **384** |
|
|
45
|
+
| Max chunks per skill | **8** (configurable: `PG_MAX_CHUNKS`) |
|
|
46
|
+
| Embedding batch size | **256** |
|
|
47
|
+
|
|
48
|
+
> ONNX model initialization (~2–3 min) happens once on first use and is cached in `~/.claude/.promptgraph/model-cache/`.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Environment Variables
|
|
53
|
+
|
|
54
|
+
| Variable | Default | Description |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `PG_VECTOR_STORE` | `hnsw` | Vector index: `hnsw` (ANN, faster at scale) or `flat` (brute-force cosine) |
|
|
57
|
+
| `PG_RERANKER` | `1` | Enable term-overlap reranker after hybrid search (set `0` to disable) |
|
|
58
|
+
| `PG_MAX_CHUNKS` | `8` | Max semantic chunks per skill (higher = more detail per long file, more embedding cost) |
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install -g promptgraph-mcp@latest
|
|
66
|
+
pg init
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`pg init` downloads the model (~23 MB, once), indexes your local skills, and prints the config snippet.
|
|
70
|
+
|
|
71
|
+
### Claude Code (`~/.claude/settings.json`)
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"mcpServers": {
|
|
76
|
+
"promptgraph": {
|
|
77
|
+
"command": "npx",
|
|
78
|
+
"args": ["promptgraph-mcp"]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Claude Desktop / Cursor / Windsurf / Cline
|
|
85
|
+
|
|
86
|
+
Same config — any MCP-compatible client works.
|
|
87
|
+
|
|
88
|
+
### OpenCode (`~/.config/opencode/opencode.json`)
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"mcp": {
|
|
93
|
+
"promptgraph": {
|
|
94
|
+
"type": "local",
|
|
95
|
+
"command": ["npx", "promptgraph-mcp"],
|
|
96
|
+
"enabled": true
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
> `pg setup` auto-detects installed clients and writes config automatically.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## CLI
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pg init # first-time setup
|
|
110
|
+
pg status # show indexed sources, repos, installed bundles
|
|
111
|
+
pg reindex # full reindex (semantic search, slow)
|
|
112
|
+
pg reindex --fast # keyword-only reindex (~30s, no embeddings)
|
|
113
|
+
pg search "deploy" # search from terminal
|
|
114
|
+
pg import owner/repo # clone and index any GitHub repo of .md skills
|
|
115
|
+
pg marketplace # browse skills by category
|
|
116
|
+
pg marketplace bundles # browse curated bundles
|
|
117
|
+
pg bundle install <id> # install a bundle
|
|
118
|
+
pg validate my-skill.md # validate before publishing
|
|
119
|
+
pg doctor # clean orphaned DB rows
|
|
120
|
+
pg update # update to latest version
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Marketplace
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pg marketplace # 🛠 Engineering 💻 Coding 🤖 AI Tools 🔒 Security 🎨 Creative
|
|
129
|
+
pg marketplace Engineering # filter by category
|
|
130
|
+
pg marketplace bundles # install whole repos as skill bundles
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Bundles** install an entire GitHub repo as a skill source — auto-detects `skills/`, `commands/`, `prompts/` subdirectory.
|
|
134
|
+
|
|
135
|
+
Example:
|
|
136
|
+
```bash
|
|
137
|
+
pg bundle install elementalsouls-claude-bughunter # 88 security skills from GitHub
|
|
138
|
+
pg bundle install engineering-essentials # 4 curated workflow skills
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Publish your skill** (auto-validated, no manual review):
|
|
142
|
+
|
|
143
|
+
Open an issue on [promptgraph-registry](https://github.com/NeiP4n/promptgraph-registry) with label `skill-submission`. The bot fetches, validates, commits, and closes the issue automatically.
|
|
144
|
+
|
|
145
|
+
Anti-spam checks: min 200 chars, 2+ headers, code/bullets required, prompt injection detection, duplicate URL/description check, 3 submissions per user per 24h.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## MCP Tools
|
|
150
|
+
|
|
151
|
+
Claude uses these automatically when the MCP server is running:
|
|
152
|
+
|
|
153
|
+
| Tool | What it does |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `pg_search` | Semantic search by task description |
|
|
156
|
+
| `pg_list` | List all indexed skills |
|
|
157
|
+
| `pg_context` | Full skill details + callers/callees |
|
|
158
|
+
| `pg_callers` | Which skills reference this one |
|
|
159
|
+
| `pg_callees` | Which skills this one calls |
|
|
160
|
+
| `pg_impact` | What breaks if this skill changes |
|
|
161
|
+
| `pg_marketplace_browse` | Browse community registry |
|
|
162
|
+
| `pg_marketplace_install` | Install a skill by code or name |
|
|
163
|
+
| `pg_bundle_browse` | Browse skill bundles |
|
|
164
|
+
| `pg_bundle_install` | Install a bundle |
|
|
165
|
+
| `pg_top_rated` | Highest-rated skills |
|
|
166
|
+
| `pg_rate` | Rate a skill after use |
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Search modes
|
|
171
|
+
|
|
172
|
+
Search runs a multi-stage pipeline:
|
|
173
|
+
|
|
174
|
+
1. **ANN retrieval** — HNSW approximate nearest neighbor (default) or flat brute-force cosine (`PG_VECTOR_STORE=flat`)
|
|
175
|
+
2. **BM25 keyword** — SQLite FTS5
|
|
176
|
+
3. **Hybrid fusion** — weighted sum (embedding × embedWeight + BM25 × bm25Weight, adaptive per query)
|
|
177
|
+
4. **Reranker** — term-overlap rescoring with TF frequency and header-position boost (disable via `PG_RERANKER=0`)
|
|
178
|
+
5. **Rating boost** — success/fail history adjusts final ranking
|
|
179
|
+
|
|
180
|
+
Falls back to FTS5 only if no embeddings exist.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Skill filtering
|
|
185
|
+
|
|
186
|
+
When importing a GitHub repo, PromptGraph:
|
|
187
|
+
1. Looks for a dedicated subdir (`skills/`, `commands/`, `prompts/`, `agents/`, `templates/`, etc.) — indexes only that dir if found with 2+ `.md` files
|
|
188
|
+
2. Falls back to repo root with content quality filter: min 150 chars, 2+ headers, must have code blocks or bullet points, skips readme/changelog/license/docs
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Requirements
|
|
193
|
+
|
|
194
|
+
- Node.js 18+
|
|
195
|
+
- Any MCP-compatible client (Claude Code, Claude Desktop, Cline, OpenCode, Cursor, Windsurf…)
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Related
|
|
200
|
+
|
|
201
|
+
- 📋 [promptgraph-registry](https://github.com/NeiP4n/promptgraph-registry) — community skill registry and auto-publish bot
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
*Built with [Claude Code](https://claude.com/claude-code).*
|
package/ann.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { getDb, blobToVec } from './db.js';
|
|
2
|
-
import { getStore, resetStore } from './src/store/index.js';
|
|
3
|
-
|
|
4
|
-
export async function buildAnnIndex() {
|
|
5
|
-
try {
|
|
6
|
-
const db = getDb();
|
|
7
|
-
const rows = db.prepare('SELECT skill_id, embedding FROM chunks').all();
|
|
8
|
-
const entries = rows.map(r => ({
|
|
9
|
-
skill_id: r.skill_id,
|
|
10
|
-
vector: blobToVec(r.embedding),
|
|
11
|
-
}));
|
|
12
|
-
const store = getStore();
|
|
13
|
-
await store.build(entries);
|
|
14
|
-
console.error(`[PromptGraph] ANN index ready: ${store.size} vectors`);
|
|
15
|
-
} catch (e) {
|
|
16
|
-
console.error(`[PromptGraph] ANN build failed: ${e.message}`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function annSearch(queryVec, topK = 20) {
|
|
21
|
-
try {
|
|
22
|
-
const store = getStore();
|
|
23
|
-
if (store.size === 0) return null;
|
|
24
|
-
return await store.search(queryVec, topK);
|
|
25
|
-
} catch (e) {
|
|
26
|
-
console.error(`[PromptGraph] ANN search error: ${e.message}`);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function resetAnnIndex() {
|
|
32
|
-
resetStore();
|
|
33
|
-
}
|
|
1
|
+
import { getDb, blobToVec } from './db.js';
|
|
2
|
+
import { getStore, resetStore } from './src/store/index.js';
|
|
3
|
+
|
|
4
|
+
export async function buildAnnIndex() {
|
|
5
|
+
try {
|
|
6
|
+
const db = getDb();
|
|
7
|
+
const rows = db.prepare('SELECT skill_id, embedding FROM chunks').all();
|
|
8
|
+
const entries = rows.map(r => ({
|
|
9
|
+
skill_id: r.skill_id,
|
|
10
|
+
vector: blobToVec(r.embedding),
|
|
11
|
+
}));
|
|
12
|
+
const store = getStore();
|
|
13
|
+
await store.build(entries);
|
|
14
|
+
console.error(`[PromptGraph] ANN index ready: ${store.size} vectors`);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.error(`[PromptGraph] ANN build failed: ${e.message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function annSearch(queryVec, topK = 20) {
|
|
21
|
+
try {
|
|
22
|
+
const store = getStore();
|
|
23
|
+
if (store.size === 0) return null;
|
|
24
|
+
return await store.search(queryVec, topK);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(`[PromptGraph] ANN search error: ${e.message}`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resetAnnIndex() {
|
|
32
|
+
resetStore();
|
|
33
|
+
}
|