{"record":{"id":"e5d02dcf4fa4c3f1","repo":"rohitg00/agentmemory","slug":"install-huggingface-transformers-for-clip-embeddi","errorCode":null,"errorMessage":"Install @huggingface/transformers for CLIP embeddings: npm install @huggingface/transformers","messagePattern":"Install @huggingface/transformers for CLIP embeddings: npm install @huggingface/transformers","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/providers/embedding/clip.ts","lineNumber":64,"sourceCode":"    const t = await loadTransformers();\n    this.textExtractor = (await t.pipeline(\"feature-extraction\", this.modelId, { dtype: \"q8\" })) as ClipPipeline;\n    return this.textExtractor;\n  }\n\n  private async getImageExtractor(): Promise<ClipPipeline> {\n    if (this.imageExtractor) return this.imageExtractor;\n    const t = await loadTransformers();\n    this.imageExtractor = (await t.pipeline(\"image-feature-extraction\", this.modelId, { dtype: \"q8\" })) as ClipPipeline;\n    return this.imageExtractor;\n  }\n}\n\nasync function loadTransformers(): Promise<TransformersModule> {\n  try {\n    return await import(\"@huggingface/transformers\");\n  } catch (err) {\n    if ((err as NodeJS.ErrnoException).code === \"ERR_MODULE_NOT_FOUND\") {\n      throw new Error(\n        \"Install @huggingface/transformers for CLIP embeddings: npm install @huggingface/transformers\",\n      );\n    }\n    throw err;\n  }\n}\n\nasync function loadImage(\n  t: TransformersModule,\n  src: string,\n): Promise<RawImage> {\n  if (src.startsWith(\"data:\")) {\n    const comma = src.indexOf(\",\");\n    const b64 = comma >= 0 ? src.slice(comma + 1) : src;\n    const buf = Buffer.from(b64, \"base64\");\n    return t.RawImage.fromBlob(new Blob([buf]));\n  }\n  const data = await readFile(src);","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/providers/embedding/clip.ts#L46-L82","documentation":"The CLIP embedding provider lazily imports `@huggingface/transformers` at first use; if the dynamic import fails with ERR_MODULE_NOT_FOUND it rethrows this actionable message. The library treats the transformers package as an optional peer dependency, so CLIP embeddings are unavailable until you install it.","triggerScenarios":"Selecting the CLIP embedding provider (multimodal image/text embeddings) when `@huggingface/transformers` is not present in node_modules — e.g. it was never installed, was in optionalDependencies and skipped, or the import throws ERR_MODULE_NOT_FOUND for another resolution reason.","commonSituations":"Fresh clone where only `npm install` of core deps ran; pnpm/yarn PnP strict installs that don't hoist optional peers; using a version of the package before/after the transformers dependency became optional; Node version too old for the package's export map causing resolution failure.","solutions":["Run `npm install @huggingface/transformers` (or the equivalent for your package manager) in the project root.","Restart the process after installing — dynamic import caches failures only per-call, but module resolution may need a fresh start.","If you don't need CLIP, switch to another embedding provider (OpenAI, Gemini, Cohere, local) so loadTransformers is never called.","If installed but still failing, check Node version compatibility and that the package resolves (`node -e \"import('@huggingface/transformers')\"`)."],"exampleFix":"// before\nnpm install  # @huggingface/transformers missing -> CLIP provider throws\n// after\nnpm install @huggingface/transformers\nnpm run build && npm start","handlingStrategy":"fallback","validationCode":"// Probe before selecting CLIP\nasync function clipAvailable(): Promise<boolean> {\n  try { await import(\"@huggingface/transformers\"); return true; }\n  catch { return false; }\n}\nconst provider = (await clipAvailable()) ? new ClipProvider() : new LocalEmbeddingProvider();","typeGuard":null,"tryCatchPattern":"try {\n  provider = new ClipProvider();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"Install @huggingface/transformers\")) {\n    console.warn(\"CLIP unavailable; falling back to default text embeddings\");\n    provider = new DefaultEmbeddingProvider();\n  } else throw e;\n}","preventionTips":["Add @huggingface/transformers to package.json dependencies if you use CLIP at all.","Document the optional dependency in the README setup section.","Probe the dynamic import at startup and log which embedding provider was selected.","Keep a non-CLIP fallback provider configured for environments without the package."],"tags":["missing-dependency","embeddings","optional-peer","install"],"backgroundTag":"missing-dependency","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}