Skip to content

feat(wren memory): torch-free ONNX embedding backend to cut install size and cold start #2643

Description

@goldmedal

Problem

wrenai[memory] is currently ["lancedb>=0.6", "sentence-transformers>=3.0.0"]. That pulls in torch, and on linux-x86_64 the default index resolves the CUDA build: torch plus the whole nvidia-* stack, roughly 2.7 GB of wheels and 6–7 GB installed, where a CPU-only build is about 200 MB. It also imposes a per-process floor before the first result: importing torch and loading the model weights, which is the dominant cost in #2611.

A CPU-only pin is not available to us: an extra cannot pin a package index, so wrenai[memory] cannot express "torch, but the CPU wheel". Every user on Linux pays the CUDA download unless they know to reinstall torch from the PyTorch CPU index afterwards. Telling users to do that by hand is a workaround, not a fix.

Proposal

Add a torch-free embedding backend based on onnxruntime, selectable at install and runtime, and keep sentence-transformers as the existing option.

  • New extra, e.g. wrenai[memory-onnx]: lancedb + onnxruntime + tokenizer, no torch.
  • Runtime selection via an env var, e.g. WREN_EMBEDDING_BACKEND=onnx|sentence-transformers, defaulting to whichever is installed (ONNX preferred when both are).
  • Slot it in behind the existing embedding abstraction in core/wren/src/wren/memory/embeddings.py so MemoryStore is unchanged: the backend only has to provide compute_source_embeddings / compute_query_embeddings.
  • Keep the default model's 384 dimensions and multilingual coverage (paraphrase-multilingual-MiniLM-L12-v2 equivalent). Existing LanceDB tables are typed with a fixed-size 384 vector, so preserving the dimension means existing indexes keep working; a different dimension forces every user to wren memory reset && wren memory index.

What the evaluation needs to answer

  • Cold-start time to first embedding, compared with the current sentence-transformers path.
  • Install footprint of the ONNX extra vs. the current one, on linux-x86_64 specifically (where the CUDA resolution happens).
  • Retrieval parity: the same set of fetch / recall queries should return comparable results — this must not quietly degrade Chinese/multilingual retrieval quality.
  • Where the ONNX weights come from and how they are cached offline (the local-first resolution behaviour must be preserved).
  • Platform coverage: linux/macOS/Windows, x86_64 and arm64.

Acceptance criteria

  • pip install wrenai[memory-onnx] installs no torch and no nvidia-* packages.
  • wren memory index / fetch / recall work end-to-end on the ONNX backend, at 384 dimensions, against an index built by either backend.
  • Model resolution stays local-first, so a cached model needs no network access.
  • Backend selection is explicit and reported by wren memory status.
  • The evaluation numbers above are recorded on this issue before the default is changed.

Context

Follow-up from #2611. This is the item that removes both the multi-GB install and the per-process load floor, rather than working around them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions