Skip to content

feat: select the local embedding model with embedding.model - #541

Merged
RobertLD merged 1 commit into
mainfrom
feat/local-embedding-models
Nov 27, 2026
Merged

RobertLD merged 1 commit into
mainfrom
feat/local-embedding-models

Conversation

@RobertLD

Copy link
Copy Markdown
Owner

Problem

The local embedding provider was hard-coded to all-MiniLM-L6-v2 and ignored embedding.model, which the ollama and openai providers use. The only way to get a stronger embedding model was to run an Ollama or OpenAI-compatible server.

Change

embedding.model selects the local model from a built-in list in src/providers/local.ts:

  • all-MiniLM-L6-v2: the default, unchanged. Same index identifier (sentence-transformers/all-MiniLM-L6-v2), same cache path, revision, 256-token limit and mean pooling.
  • bge-small-en-v1.5: Xenova/bge-small-en-v1.5 at ea104dac. CLS pooling, 512 tokens, 384 dimensions, about 130 MB.
  • bge-base-en-v1.5: Xenova/bge-base-en-v1.5 at 4d6cd88e. CLS pooling, 512 tokens, 768 dimensions, about 440 MB.

Each model downloads on first use into ~/.libscope/models/<repo>, pinned to its revision. Nothing is added to the npm package. Pooling, max length and dimensions come from each model's 1_Pooling/config.json, sentence_bert_config.json and config.json.

Switching models changes the index identity, so the existing model-change error and libscope admin reindex --rebuild apply.

Downloads

downloadModelFile now streams to <file>.<uuid>.partial and renames it on success. It used to buffer the whole file in memory, which would peak near 870 MB for bge-base.

  • A failed attempt removes its temp file and keeps the original error.
  • The fetch, the stream and the rename are all retried together.
  • The unique name keeps concurrent downloads, in the same or another process, from sharing a temp file.

Behaviour change

With provider local, a leftover embedding.model used to log a warning and run MiniLM. Now:

  • An unknown name, such as a stale nomic-embed-text, is a ConfigError that names embedding.model and how to fix it.
  • A bge name selects that model, and an existing index then needs admin reindex --rebuild.

Users with no embedding.model set see no change. Documented in docs/guide/configuration.md.

Tests

  • tests/unit/local-embedding.test.ts: model selection, the unknown-model error (including prototype keys such as constructor), CLS pooling, and truncation per limit.
  • tests/unit/local-embedding-models.test.ts (new), with fs, tokenizer and onnxruntime mocked:
    • pooling and truncation through embed();
    • the pinned download URLs, the streamed write and the rename;
    • a body that fails on every attempt;
    • fail once, then succeed;
    • a missing content-length;
    • a failing cleanup that must not hide the original error.

Verification

  • npm run format:check, lint (0 errors), typecheck, npm test (2155 tests), build, docs:check.
  • Real download and embed of bge-small-en-v1.5 with a fresh HOME:
    • 384 dimensions, unit norm, no .partial files left;
    • a second run reused the cache and returned the identical vector.
  • bge-small and bge-base vectors matched a Python onnxruntime + tokenizers reference on BAAI's own ONNX export within 2.2e-07, over 5 texts including one truncated at 512 tokens.

Not verified

  • bge-base was downloaded end to end only before the streaming change.
  • No bge query instruction is added. The v1.5 model card says retrieval without it is only slightly worse, and EmbeddingProvider has no query/document distinction.
  • embedding.dimensions is still ignored by the local provider.

The local provider was hard-coded to all-MiniLM-L6-v2 and ignored embedding.model. It now supports all-MiniLM-L6-v2 (default, unchanged), bge-small-en-v1.5 and bge-base-en-v1.5, each pinned to a Hugging Face revision and downloaded on first use. An unknown name is a ConfigError instead of a warning.

Model files now stream to a uniquely named temp file that is renamed on success and removed on failure, and the whole download is retried.
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
libscope Ignored Ignored Preview Nov 27, 2026 3:22pm UTC

@sonarqubecloud

Copy link
Copy Markdown

@RobertLD
RobertLD merged commit 951ca99 into main Nov 27, 2026
10 checks passed
@RobertLD
RobertLD deleted the feat/local-embedding-models branch November 27, 2026 15:26
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