pi-knowledge 0.3.1 → 0.3.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/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/embedding/provider.ts +10 -4
- package/src/search/reranker.ts +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.3] - 2026-06-15
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Added a mandatory async lifecycle review contract for timers, event handlers, dispose, and shutdown paths.
|
|
7
|
+
- Clarified review requirements for overlap analysis, guard-state updates before await points, idempotent cleanup, and recreate-after-dispose behavior.
|
|
8
|
+
|
|
9
|
+
## [0.3.2] - 2026-06-15
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- Made local embedding and deep reranker model disposal idempotent to avoid concurrent native ONNX session teardown from idle timers and Pi `session_shutdown`.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Updated the onnxruntime exit-crash pitfall notes with the double-dispose race mitigation.
|
|
16
|
+
|
|
3
17
|
## [0.3.1] - 2026-06-15
|
|
4
18
|
|
|
5
19
|
### Fixed
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ type FeatureExtractionPipeline = {
|
|
|
8
8
|
|
|
9
9
|
let pipelineInstance: FeatureExtractionPipeline | null = null;
|
|
10
10
|
let disposeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
let disposePromise: Promise<void> | null = null;
|
|
11
12
|
|
|
12
13
|
const IDLE_TIMEOUT_MS = 30_000;
|
|
13
14
|
const EMBEDDING_CONFIG = process.env.PI_KNOWLEDGE_EMBEDDING ?? "local:multilingual-e5-small";
|
|
@@ -18,6 +19,7 @@ function getModelCacheDir(): string {
|
|
|
18
19
|
|
|
19
20
|
async function loadPipeline(): Promise<FeatureExtractionPipeline> {
|
|
20
21
|
if (pipelineInstance) return pipelineInstance;
|
|
22
|
+
if (disposePromise) await disposePromise;
|
|
21
23
|
const { pipeline, env } = await import("@huggingface/transformers");
|
|
22
24
|
env.cacheDir = getModelCacheDir();
|
|
23
25
|
pipelineInstance = await pipeline("feature-extraction", "Xenova/multilingual-e5-small", {
|
|
@@ -37,10 +39,14 @@ export async function dispose(): Promise<void> {
|
|
|
37
39
|
clearTimeout(disposeTimer);
|
|
38
40
|
disposeTimer = null;
|
|
39
41
|
}
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (disposePromise) return disposePromise;
|
|
43
|
+
const instance = pipelineInstance;
|
|
44
|
+
pipelineInstance = null;
|
|
45
|
+
if (!instance) return;
|
|
46
|
+
disposePromise = Promise.resolve(instance.dispose()).finally(() => {
|
|
47
|
+
disposePromise = null;
|
|
48
|
+
});
|
|
49
|
+
return disposePromise;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
async function embedViaAPI(texts: string[], prefix: "query" | "passage"): Promise<Float32Array[]> {
|
package/src/search/reranker.ts
CHANGED
|
@@ -8,10 +8,12 @@ type RerankerPipeline = {
|
|
|
8
8
|
|
|
9
9
|
let rerankerPipeline: RerankerPipeline | null = null;
|
|
10
10
|
let disposeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
let disposePromise: Promise<void> | null = null;
|
|
11
12
|
const IDLE_MS = 30_000;
|
|
12
13
|
|
|
13
14
|
async function load(): Promise<RerankerPipeline> {
|
|
14
15
|
if (rerankerPipeline) return rerankerPipeline;
|
|
16
|
+
if (disposePromise) await disposePromise;
|
|
15
17
|
const { pipeline, env } = await import("@huggingface/transformers");
|
|
16
18
|
env.cacheDir = join(getDefaultKnowledgeDir(), "models");
|
|
17
19
|
rerankerPipeline = await pipeline("text-classification", "Xenova/ms-marco-MiniLM-L-4-v2");
|
|
@@ -28,10 +30,14 @@ export async function disposeReranker(): Promise<void> {
|
|
|
28
30
|
clearTimeout(disposeTimer);
|
|
29
31
|
disposeTimer = null;
|
|
30
32
|
}
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (disposePromise) return disposePromise;
|
|
34
|
+
const instance = rerankerPipeline;
|
|
35
|
+
rerankerPipeline = null;
|
|
36
|
+
if (!instance) return;
|
|
37
|
+
disposePromise = Promise.resolve(instance.dispose()).finally(() => {
|
|
38
|
+
disposePromise = null;
|
|
39
|
+
});
|
|
40
|
+
return disposePromise;
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
export interface RerankCandidate {
|