Skip to content

[1.8] refactor(embeddings): type extractor with FeatureExtractionPipeline - #207

Merged
h4yfans merged 2 commits into
mainfrom
debt/1.8-embeddings-type
Apr 15, 2026
Merged

[1.8] refactor(embeddings): type extractor with FeatureExtractionPipeline#207
h4yfans merged 2 commits into
mainfrom
debt/1.8-embeddings-type

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replaces the let extractor: any = null escape hatch in apps/desktop/src/main/lib/embeddings.ts with the real FeatureExtractionPipeline type imported from @huggingface/transformers, removing the file's only eslint-disable @typescript-eslint/no-explicit-any directive.

pipeline('feature-extraction', ...) returns a large discriminated union that TypeScript reports as "too complex to represent". The return is routed through unknown (not any) and cast once to the concrete pipeline type — keeping the module-level extractor strongly typed at every call site.

Before / After

-// Pipeline instance (lazy loaded)
-// eslint-disable-next-line @typescript-eslint/no-explicit-any
-let extractor: any = null
+let extractor: FeatureExtractionPipeline | null = null

And inside initEmbeddingModel():

-extractor = await pipeline('feature-extraction', MODEL_NAME, { ... })
+const loaded: unknown = await pipeline('feature-extraction', MODEL_NAME, { ... })
+extractor = loaded as FeatureExtractionPipeline

generateEmbedding() now calls a locally-typed extractorInstance (same narrowed reference) rather than re-reading the module variable after the initEmbeddingModel() call.

Verification

  • pnpm --filter @memry/desktop typecheck:node 2>&1 | grep "embeddings.ts" | wc -l = 0
  • rg ": any|as any" apps/desktop/src/main/lib/embeddings.ts = no matches
  • pnpm --filter @memry/desktop typecheck:web = pass
  • pnpm typecheck:packages = pass (10/10 cached)
  • pnpm exec eslint --cache src/main/lib/embeddings.ts = 0 errors, 0 warnings
  • pnpm test = 2 failures, both pre-existing and unrelated:
    • calendar-page.test.tsx:258 "Due draft" (known flake, ignored per unit instructions)
    • notes-tree.test.tsx T523 — reproduces on clean main without this change (@/components/kibo-ui/tree alias resolution issue in local env)

Test plan

  • typecheck:node clean for touched file
  • typecheck:web clean
  • typecheck:packages clean
  • No any remaining in embeddings.ts
  • No new lint errors in touched file
  • Smoke embedding generation in dev app (manual follow-up)

@h4yfans
h4yfans merged commit 621b86d into main Apr 15, 2026
2 checks passed
@h4yfans
h4yfans deleted the debt/1.8-embeddings-type branch April 15, 2026 20:18
h4yfans added a commit that referenced this pull request May 6, 2026
[1.8] refactor(embeddings): type extractor with FeatureExtractionPipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant