Enable WebGPU execution provider for semantic embeddings (WASM fallback)

未关闭
#1,209 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃

调研方向

Start by reading src/lib/search/embeddings.ts, especially the device selection around lines 48 and 58-68, then inspect the device-guard tests. Extend the existing worker pipeline to probe WebGPU, retry with WASM on failure, and include the selected device in the fingerprints handled by src/lib/search/semantic-cache.ts and src/lib/search/semantic-digest.ts. Done means the fallback tests pass and the Settings view reports the active embedding device.

由索引模型根据 Issue 内容生成。

描述

enhancement performance priority: medium search

Summary

The semantic search engine currently pins the transformers.js embedding pipeline to CPU/WASM execution (device: embeddingDevice with a WASM-only default). Transformers.js v4 — already the project dependency (@huggingface/transformers ^4.3.1) — makes WebGPU the default backend where the browser supports it, with a one-line device flag and mature WASM fallback.

Evidence

  • src/lib/search/embeddings.ts:48 — "CPU execution via WASM — no WebGPU required" comment documents the current deliberate choice.
  • src/lib/search/embeddings.ts:66-68 — setEmbeddingDeviceForTests shows the device selection is already parameterized; adding webgpu is a small, contained change.
  • Dependency is already at v4.x, so no upgrade is required to try it.

Impact

  • Performance: 2026 benchmarks report 40–75× embedding speedups on WebGPU vs WASM across integrated and discrete GPUs; semantic indexing of a large corpus drops from tens of seconds to near-instant for incremental updates.
  • Battery/UX: GPU inference frees the main thread and reduces CPU spin during indexing (the search worker already exists, so worker placement is solved).
  • No regression risk for unsupported browsers: navigator.gpu.requestAdapter() probe → fall back to the existing wasm path.

Proposed approach

  1. Probe navigator.gpu?.requestAdapter() in the worker before pipeline creation.
  2. Select device: 'webgpu' when available; on pipeline-creation failure, retry once with device: 'wasm'.
  3. Record the chosen device in the semantic cache fingerprint so vectors are not reused across devices (src/lib/search/semantic-cache.ts / semantic-digest.ts already fingerprint model + preprocessing + corpus).
  4. Extend the device-guard test (device error handling around embeddings.ts:58) and a new fallback unit test.
  5. Surface the active device in the Settings view (it already reports semantic index cost/budget).

References

主要语言
TypeScript
星标
3
派生
2
平均合并
11 小时 49 分钟
30 天内合并 PR
102

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

d-oit/do-knowledge-studio 的其他 Issue

查看 d-oit/do-knowledge-studio 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。