@getmikk/intent-engine 2.0.16 → 2.0.18
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/package.json +1 -1
- package/src/semantic-searcher.ts +12 -2
package/package.json
CHANGED
package/src/semantic-searcher.ts
CHANGED
|
@@ -41,7 +41,7 @@ export class SemanticSearcher {
|
|
|
41
41
|
private pipeline: any = null
|
|
42
42
|
private cache: EmbeddingCache | null = null
|
|
43
43
|
|
|
44
|
-
constructor(private readonly projectRoot: string) {
|
|
44
|
+
constructor(private readonly projectRoot: string, private readonly onProgress?: (percent: number) => void) {
|
|
45
45
|
this.cachePath = path.join(projectRoot, '.mikk', 'embeddings.json')
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -97,12 +97,16 @@ export class SemanticSearcher {
|
|
|
97
97
|
await this.ensurePipeline()
|
|
98
98
|
const embeddings: Record<string, number[]> = {}
|
|
99
99
|
const BATCH = 64
|
|
100
|
+
const total = fns.length
|
|
100
101
|
for (let i = 0; i < fns.length; i += BATCH) {
|
|
101
102
|
const batch = texts.slice(i, i + BATCH)
|
|
102
103
|
const output = await this.pipeline(batch, { pooling: 'mean', normalize: true })
|
|
103
104
|
for (let j = 0; j < batch.length; j++) {
|
|
104
105
|
embeddings[fns[i + j].id] = Array.from(output[j].data as Float32Array)
|
|
105
106
|
}
|
|
107
|
+
if (this.onProgress) {
|
|
108
|
+
this.onProgress(Math.round(((i + BATCH) / total) * 100))
|
|
109
|
+
}
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
this.cache = { lockFingerprint: fingerprint, model: SemanticSearcher.MODEL, embeddings }
|
|
@@ -148,10 +152,16 @@ export class SemanticSearcher {
|
|
|
148
152
|
}).filter((r): r is SemanticMatch => r !== null)
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
private async ensurePipeline() {
|
|
155
|
+
private async ensurePipeline(progressMsg?: string) {
|
|
152
156
|
if (this.pipeline) return
|
|
157
|
+
if (progressMsg && this.onProgress) {
|
|
158
|
+
this.onProgress(0)
|
|
159
|
+
}
|
|
153
160
|
const { pipeline } = await import('@xenova/transformers')
|
|
154
161
|
this.pipeline = await pipeline('feature-extraction', SemanticSearcher.MODEL)
|
|
162
|
+
if (this.onProgress) {
|
|
163
|
+
this.onProgress(5)
|
|
164
|
+
}
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
167
|
|