@dpesch/mantisbt-mcp-server 1.5.0 → 1.5.1
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/CHANGELOG.md +7 -0
- package/README.de.md +1 -0
- package/README.md +1 -0
- package/dist/config.js +2 -0
- package/dist/search/embedder.js +10 -3
- package/dist/search/index.js +1 -1
- package/package.json +1 -1
- package/tests/search/embedder.test.ts +81 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.5.1] – 2026-03-17
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- Semantic search: ONNX thread pool now defaults to 1 thread (`intra_op_num_threads=1`) instead of auto-detecting all available CPU cores. On WSL and multi-core machines the unrestricted default caused CPU saturation (700%+ CPU, 12 GB VM) during the initial index build. The number of threads is configurable via the new `MANTIS_SEARCH_THREADS` environment variable (default: `1`). `inter_op_num_threads` is always kept at 1 because Transformer model graphs are sequential and inter-op parallelism provides no benefit.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
10
17
|
## [1.5.0] – 2026-03-17
|
|
11
18
|
|
|
12
19
|
### Added
|
package/README.de.md
CHANGED
|
@@ -73,6 +73,7 @@ npm run build
|
|
|
73
73
|
| `MANTIS_SEARCH_BACKEND` | – | `vectra` | Vektorspeicher: `vectra` (reines JS) oder `sqlite-vec` (manuelle Installation erforderlich) |
|
|
74
74
|
| `MANTIS_SEARCH_DIR` | – | `{MANTIS_CACHE_DIR}/search` | Verzeichnis für den Suchindex |
|
|
75
75
|
| `MANTIS_SEARCH_MODEL` | – | `Xenova/paraphrase-multilingual-MiniLM-L12-v2` | Embedding-Modell (wird beim ersten Start einmalig heruntergeladen, ~80 MB) |
|
|
76
|
+
| `MANTIS_SEARCH_THREADS` | – | `1` | Anzahl der ONNX-Intra-Op-Threads für das Embedding-Modell. Standard ist 1, um CPU-Sättigung auf Mehrkernsystemen und in WSL zu verhindern. Nur erhöhen, wenn die Indexierungsgeschwindigkeit kritisch ist und der Host ausschließlich für diese Last vorgesehen ist. |
|
|
76
77
|
|
|
77
78
|
### Config-Datei (Fallback)
|
|
78
79
|
|
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ npm run build
|
|
|
73
73
|
| `MANTIS_SEARCH_BACKEND` | – | `vectra` | Vector store backend: `vectra` (pure JS) or `sqlite-vec` (requires manual install) |
|
|
74
74
|
| `MANTIS_SEARCH_DIR` | – | `{MANTIS_CACHE_DIR}/search` | Directory for the search index |
|
|
75
75
|
| `MANTIS_SEARCH_MODEL` | – | `Xenova/paraphrase-multilingual-MiniLM-L12-v2` | Embedding model name (downloaded once on first use, ~80 MB) |
|
|
76
|
+
| `MANTIS_SEARCH_THREADS` | – | `1` | Number of ONNX intra-op threads for the embedding model. Default is 1 to prevent CPU saturation on multi-core machines and WSL. Increase only if index rebuild speed matters and the host is dedicated to this workload. |
|
|
76
77
|
|
|
77
78
|
### Config file (fallback)
|
|
78
79
|
|
package/dist/config.js
CHANGED
|
@@ -76,6 +76,7 @@ export async function getConfig() {
|
|
|
76
76
|
const searchDir = process.env.MANTIS_SEARCH_DIR ?? join(cacheDir, 'search');
|
|
77
77
|
const searchModelName = process.env.MANTIS_SEARCH_MODEL ??
|
|
78
78
|
'Xenova/paraphrase-multilingual-MiniLM-L12-v2';
|
|
79
|
+
const searchNumThreads = Math.max(1, parseInt(process.env.MANTIS_SEARCH_THREADS ?? '', 10) || 1);
|
|
79
80
|
cachedConfig = {
|
|
80
81
|
baseUrl: baseUrl.replace(/\/$/, ''), // strip trailing slash
|
|
81
82
|
apiKey,
|
|
@@ -86,6 +87,7 @@ export async function getConfig() {
|
|
|
86
87
|
backend: searchBackend,
|
|
87
88
|
dir: searchDir,
|
|
88
89
|
modelName: searchModelName,
|
|
90
|
+
numThreads: searchNumThreads,
|
|
89
91
|
},
|
|
90
92
|
};
|
|
91
93
|
return cachedConfig;
|
package/dist/search/embedder.js
CHANGED
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
export class Embedder {
|
|
10
10
|
modelName;
|
|
11
|
+
numThreads;
|
|
11
12
|
pipe = null;
|
|
12
|
-
constructor(modelName) {
|
|
13
|
+
constructor(modelName, numThreads = 1) {
|
|
13
14
|
this.modelName = modelName;
|
|
15
|
+
this.numThreads = numThreads;
|
|
14
16
|
}
|
|
15
17
|
async load() {
|
|
16
18
|
if (this.pipe)
|
|
17
19
|
return this.pipe;
|
|
18
|
-
process.stderr.write(`[mantisbt-search] Loading embedding model ${this.modelName}...\n`);
|
|
20
|
+
process.stderr.write(`[mantisbt-search] Loading embedding model ${this.modelName} (threads: ${this.numThreads})...\n`);
|
|
19
21
|
let transformers;
|
|
20
22
|
try {
|
|
21
23
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -25,7 +27,12 @@ export class Embedder {
|
|
|
25
27
|
const msg = err instanceof Error ? err.message : String(err);
|
|
26
28
|
throw new Error(`Failed to load @huggingface/transformers: ${msg}`);
|
|
27
29
|
}
|
|
28
|
-
this.pipe = await transformers.pipeline('feature-extraction', this.modelName
|
|
30
|
+
this.pipe = await transformers.pipeline('feature-extraction', this.modelName, {
|
|
31
|
+
session_options: {
|
|
32
|
+
intra_op_num_threads: this.numThreads,
|
|
33
|
+
inter_op_num_threads: 1, // Transformer graphs are sequential — no benefit from inter-op parallelism
|
|
34
|
+
},
|
|
35
|
+
});
|
|
29
36
|
return this.pipe;
|
|
30
37
|
}
|
|
31
38
|
async embed(text) {
|
package/dist/search/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export async function initializeSearchModule(server, client, config) {
|
|
|
9
9
|
if (!config.enabled)
|
|
10
10
|
return;
|
|
11
11
|
const store = createVectorStore(config.backend, config.dir);
|
|
12
|
-
const embedder = new Embedder(config.modelName);
|
|
12
|
+
const embedder = new Embedder(config.modelName, config.numThreads);
|
|
13
13
|
registerSearchTools(server, client, store, embedder);
|
|
14
14
|
// Pre-initialize lastKnownTotal so get_search_index_status shows a value
|
|
15
15
|
// immediately on startup, even while the background sync is still running.
|
package/package.json
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Embedder } from '../../src/search/embedder.js';
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Mock @huggingface/transformers (dynamic import)
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
const mockPipelineFn = vi.fn(async (texts: string | string[]) => {
|
|
9
|
+
if (Array.isArray(texts)) {
|
|
10
|
+
return texts.map(() => ({ data: new Float32Array(4).fill(0.1), dims: [1, 4] }));
|
|
11
|
+
}
|
|
12
|
+
return { data: new Float32Array(4).fill(0.1), dims: [4] };
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const mockPipelineFactory = vi.fn(async (_task: string, _model: string, _opts?: unknown) => mockPipelineFn);
|
|
16
|
+
|
|
17
|
+
vi.mock('@huggingface/transformers', () => ({
|
|
18
|
+
pipeline: mockPipelineFactory,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Thread configuration
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
describe('Embedder – thread configuration', () => {
|
|
30
|
+
it('passes intra_op_num_threads=1 by default', async () => {
|
|
31
|
+
const embedder = new Embedder('test-model');
|
|
32
|
+
await embedder.embed('hello');
|
|
33
|
+
|
|
34
|
+
expect(mockPipelineFactory).toHaveBeenCalledWith(
|
|
35
|
+
'feature-extraction',
|
|
36
|
+
'test-model',
|
|
37
|
+
expect.objectContaining({
|
|
38
|
+
session_options: { intra_op_num_threads: 1, inter_op_num_threads: 1 },
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('passes configured numThreads to intra_op_num_threads; inter stays 1', async () => {
|
|
44
|
+
const embedder = new Embedder('test-model', 4);
|
|
45
|
+
await embedder.embed('hello');
|
|
46
|
+
|
|
47
|
+
expect(mockPipelineFactory).toHaveBeenCalledWith(
|
|
48
|
+
'feature-extraction',
|
|
49
|
+
'test-model',
|
|
50
|
+
expect.objectContaining({
|
|
51
|
+
session_options: { intra_op_num_threads: 4, inter_op_num_threads: 1 },
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('loads the pipeline only once (lazy singleton)', async () => {
|
|
57
|
+
const embedder = new Embedder('test-model', 1);
|
|
58
|
+
await embedder.embed('first');
|
|
59
|
+
await embedder.embed('second');
|
|
60
|
+
|
|
61
|
+
expect(mockPipelineFactory).toHaveBeenCalledTimes(1);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Embedder default — numThreads omitted
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
describe('Embedder – numThreads default', () => {
|
|
70
|
+
it('uses intra_op_num_threads=1 when numThreads is not passed', async () => {
|
|
71
|
+
const embedder = new Embedder('m');
|
|
72
|
+
await embedder.embed('x');
|
|
73
|
+
expect(mockPipelineFactory).toHaveBeenCalledWith(
|
|
74
|
+
'feature-extraction',
|
|
75
|
+
'm',
|
|
76
|
+
expect.objectContaining({
|
|
77
|
+
session_options: expect.objectContaining({ intra_op_num_threads: 1 }),
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
});
|