You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(embedding): support embedding.dimensions for openai-compatible Matryoshka models (e.g. Qwen3-Embedding-8B 768/1024/4096)
What problem does this solve?
Qwen3-Embedding-8B (and other Matryoshka models) supports variable output dimensions via the OpenAI-compatible dimensions request field. The model can return 768, 1024, 2048, or 4096 truncated vectors from the same weights via MRL.
Magic Context 0.41.1 has no embedding.dimensions config. The openai-compatible provider always omits dimensions, so the endpoint's default is used:
POST /v1/embeddings {model: Qwen3-Embedding-8B, input: "hello world"} → 768 dims
POST /v1/embeddings {model: Qwen3-Embedding-8B, input: "测试中文"} → 1024 dims (same endpoint, same model, different input language)
POST /v1/embeddings {model: Qwen3-Embedding-8B, dimensions: 4096} → 4096 dims (native)
We use Magic Context with a mixed Chinese/English codebase (Pi). localXenova/all-MiniLM-L6-v2 (384 dims) has poor Chinese→English recall, and the default 768/1024 from the remote endpoint is also unstable across languages. For a small 17-case bilingual retrieval test (same as #259 style), 4096 preserved the best recall. There's currently no way to pin the store to the native 4096 without forking the plugin.
Proposed solution
Add an optional embedding.dimensions for the openai-compatible provider, plumbed end-to-end:
Schemapackages/plugin/src/config/schema/magic-context.ts: BaseEmbeddingConfigSchema.dimensions: z.number().int().positive().max(8192).optional() + include in EmbeddingConfigSchema.transform for openai-compatible (and synapse for completeness).
Identityembedding-identity.ts: getEmbeddingProviderIdentity includes ...dimensions?{dimensions}:{}
(changing dimensions must re-embed; omitted keeps byte-identical identity for existing configs).
Runtimeembedding.ts / project-embedding-registry.ts: resolveEmbeddingConfig preserves dimensions; getChunkEmbeddingModelId includes dimensions in chunkIdentity; EMBEDDING_AFFECTING_KEYS includes embedding.dimensions.
Transportembedding-openai.ts: OpenAICompatibleEmbeddingProviderOptions.dimensions, this.dimensions, modelId includes dimensions, embedBatch adds ...this.dimensions?{dimensions}:{} to POST /v1/embeddings body.
Verified locally on pi-magic-context@0.41.1 (Pi 0.84.4, Qwen3-Embedding-8B via https://api.example.com/v1):
Deploy a separate model alias that defaults to 4096: requires server-side change, not client-configurable.
Switch to local multilingual model with q8: solves recall but ~858 MB RSS vs remote 0 MB, and still fixed dims.
Area
Memory / historian / dreamer
Additional context
Endpoint is api.example.com/v1Qwen3-Embedding-8B (Matryoshka MRL). Verified dimensions is standard OpenAI-compatible field (also used by text-embedding-3-*).
Willing to PR the 8-site patch (schema + identity + 2× resolveEmbeddingConfig + 2× createProvider + provider + chunk) with tests if approach is approved.
Short description
feat(embedding): support
embedding.dimensionsfor openai-compatible Matryoshka models (e.g. Qwen3-Embedding-8B 768/1024/4096)What problem does this solve?
Qwen3-Embedding-8B(and other Matryoshka models) supports variable output dimensions via the OpenAI-compatibledimensionsrequest field. The model can return 768, 1024, 2048, or 4096 truncated vectors from the same weights via MRL.Magic Context 0.41.1 has no
embedding.dimensionsconfig. Theopenai-compatibleprovider always omitsdimensions, so the endpoint's default is used:POST /v1/embeddings {model: Qwen3-Embedding-8B, input: "hello world"}→ 768 dimsPOST /v1/embeddings {model: Qwen3-Embedding-8B, input: "测试中文"}→ 1024 dims (same endpoint, same model, different input language)POST /v1/embeddings {model: Qwen3-Embedding-8B, dimensions: 4096}→ 4096 dims (native)We use Magic Context with a mixed Chinese/English codebase (Pi).
localXenova/all-MiniLM-L6-v2(384 dims) has poor Chinese→English recall, and the default 768/1024 from the remote endpoint is also unstable across languages. For a small 17-case bilingual retrieval test (same as #259 style), 4096 preserved the best recall. There's currently no way to pin the store to the native 4096 without forking the plugin.Proposed solution
Add an optional
embedding.dimensionsfor theopenai-compatibleprovider, plumbed end-to-end:{ "embedding": { "provider": "openai-compatible", "endpoint": "https://api.example.com/v1", "model": "Qwen3-Embedding-8B", "api_key": "sk-...", "dimensions": 4096 // 768 | 1024 | 2048 | 4096 | omitted = provider default } }Implementation (mirrors
truncate/input_typepattern):Schema
packages/plugin/src/config/schema/magic-context.ts:BaseEmbeddingConfigSchema.dimensions: z.number().int().positive().max(8192).optional()+ include inEmbeddingConfigSchema.transformforopenai-compatible(andsynapsefor completeness).Identity
embedding-identity.ts:getEmbeddingProviderIdentityincludes...dimensions?{dimensions}:{}(changing dimensions must re-embed; omitted keeps byte-identical identity for existing configs).
Runtime
embedding.ts/project-embedding-registry.ts:resolveEmbeddingConfigpreservesdimensions;getChunkEmbeddingModelIdincludesdimensionsinchunkIdentity;EMBEDDING_AFFECTING_KEYSincludesembedding.dimensions.Transport
embedding-openai.ts:OpenAICompatibleEmbeddingProviderOptions.dimensions,this.dimensions,modelIdincludes dimensions,embedBatchadds...this.dimensions?{dimensions}:{}toPOST /v1/embeddingsbody.Verified locally on
pi-magic-context@0.41.1(Pi 0.84.4,Qwen3-Embedding-8Bviahttps://api.example.com/v1):dimensions(en)b2b64c6a1044797a0a3f8f26672942a5dimensions:1024(zh)dimensions:4096(zh)0f39523135a2dfd6c3a58933ede73966:chunk:2b0c...After
dimensions:4096+/reload,memory 2 → 16384 bytes / 4096 dimscorrectly.Omitted
dimensionskeeps current behavior (no re-embed for existing users).Alternatives considered
local_dtype.localmultilingual model withq8: solves recall but ~858 MB RSS vs remote 0 MB, and still fixed dims.Area
Memory / historian / dreamer
Additional context
api.example.com/v1Qwen3-Embedding-8B(Matryoshka MRL). Verifieddimensionsis standard OpenAI-compatible field (also used bytext-embedding-3-*).