mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 22:53:17 +09:00
fix(embeddings): graceful agentic-flow fallback in downloadEmbeddingModel
#1700 item 2: `embeddings init` failed with `Cannot find package 'agentic-flow'` because downloadEmbeddingModel did not catch the dynamic import error, even though agentic-flow is declared as an optional peer. Now logs an informative warning and returns the target dir as a no-op success — @xenova/transformers fetches the model lazily on first embeddings_generate call. Bumps @claude-flow/embeddings to 3.0.0-alpha.13. ruflo@3.6.14 picks it up automatically via caret range. Verified in clean /tmp install: $ node -e "import('@claude-flow/embeddings').then(m => m.downloadEmbeddingModel('Xenova/all-MiniLM-L6-v2', '/tmp/test-models'))" [embeddings] agentic-flow not installed — skipping eager model download. Models will be fetched lazily by @xenova/transformers on first generate. downloadEmbeddingModel returned: "/tmp/test-models" PASS — graceful fallback worked Previously this threw "Cannot find package 'agentic-flow' imported from .../@claude-flow/embeddings/dist/neural-integration.js". Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
1 parent
c5915a718d
commit
4f2f68d52c
2 files changed
+26
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@claude-flow/embeddings",
|
||||
"version": "3.0.0-alpha.12",
|
||||
"version": "3.0.0-alpha.13",
|
||||
"description": "V3 Embedding Service - OpenAI, Transformers.js, Agentic-Flow (ONNX), Mock providers with hyperbolic embeddings, normalization, and chunking",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -283,13 +283,35 @@ export async function listEmbeddingModels(): Promise<Array<{
|
||||
}
|
||||
|
||||
/**
|
||||
* Download embedding model
|
||||
* Download embedding model.
|
||||
*
|
||||
* #1700 item 2: previously this propagated `Cannot find package 'agentic-flow'`
|
||||
* when the optional peer wasn't installed, breaking `embeddings init` even
|
||||
* though the rest of the embedding pipeline (Xenova/transformers ONNX) does
|
||||
* not need agentic-flow. Now we try the agentic-flow path first and fall
|
||||
* back to a no-op success when it isn't installed — the model still loads
|
||||
* lazily on first `embeddings_generate` call via @xenova/transformers.
|
||||
*/
|
||||
export async function downloadEmbeddingModel(
|
||||
modelId: string,
|
||||
targetDir?: string,
|
||||
onProgress?: (progress: { percent: number; bytesDownloaded: number; totalBytes: number }) => void
|
||||
): Promise<string> {
|
||||
const { downloadModel } = await import('agentic-flow/embeddings');
|
||||
return downloadModel(modelId, targetDir ?? '.models', onProgress);
|
||||
try {
|
||||
const { downloadModel } = await import('agentic-flow/embeddings');
|
||||
return await downloadModel(modelId, targetDir ?? '.models', onProgress);
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
// Distinguish "package missing" from real download errors so callers
|
||||
// can surface the right hint to users.
|
||||
if (/Cannot find package 'agentic-flow'|Cannot find module/.test(msg)) {
|
||||
console.warn('[embeddings] agentic-flow not installed — skipping eager model download. ' +
|
||||
'Models will be fetched lazily by @xenova/transformers on first generate. ' +
|
||||
'For pre-downloaded models, run: npm install agentic-flow');
|
||||
// Resolve to the target dir as a no-op completion — generate() will
|
||||
// download via @xenova/transformers when first called.
|
||||
return targetDir ?? '.models';
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user