Repository navigation
feat: add Matryoshka variable-dimension embedding support for OpenAI and VoyageAI providers - #333
Conversation
… after runtime discovery
…n OpenAIEmbeddingProvider
…n VoyageAIEmbeddingProvider
… to update_config
…on to update_config
…CP read-only, and fixes Merge main into matryoshka-fix-6-26. main changes incorporated: - DuckDB compaction with atomic swap (#339) - PowerShell (#350) and Metal (#351) language parsers - MCP --read-only flag (#329) - Research per-step timing (#355) - Various fixes: websearch late-completion guard, quickresearch orphan cleanup, token literal counting, claude-cli auto-updater - openai_compatible in factory's supported_providers() Conflict resolution: chunkhound/services/realtime_indexing_service.py was deleted on main (dead code, no production callers). The branch's ModuleType __class__ hack + its test were removed to match.
VakninAriel
left a comment
There was a problem hiding this comment.
Code Review — PR #333
Verdict: ✅ Approve
| Severity | Count |
|---|---|
| 🔴 Critical | 0 |
| 🟠 High | 1 |
| 🟡 Medium | 2 |
| 🟢 Minor | 3 |
Strengths
- 1,895-line matryoshka test suite plus auth matrix, SSL env var, and daemon force-kill tests — excellent coverage
- Non-retryable error propagation —
EmbeddingProviderErrorre-raised before retry loops in both providers; dimension/config errors no longer pollute error stats or exhaust retries - Duplicate Protocol eliminated —
EmbeddingProviderProtocol removed fromembeddings.py; single source of truth ininterfaces/embedding_provider.py - Genuine bug fixes — env bool parsing (
_require_env_bool), force-kill deadline (_FORCE_KILL_DEADLINE = 2.0separate from graceful timeout), VoyageAI_rerank_via_sdkNone guard - Shared validation —
validate_positive_output_dims,validate_runtime_output_dims_config,validate_embedding_dimsextracted toshared_utils.pyand reused across both providers and config layer
Findings
🟠 High — dims property has side effects (logging + state mutation)
Location: chunkhound/providers/embeddings/openai_provider.py ~L650
The dims getter logs a logger.warning and flips self._warned_default_dims = True. Property getters should be pure reads — callers that access .dims for introspection (repr, health-check, dimension validation) trigger a spurious warning they didn't intend.
Suggested fix: Move the warning + flag flip into the embed path (_embed_batch_internal) where "no static metadata and no discovered dims" is unambiguously an active-use signal.
🟡 Medium — Dead code in extract_cli_overrides for embedding_output_dims
Location: chunkhound/core/config/embedding_config.py ~L714–723
--output-dims / --embedding-output-dims uses argparse's first option string to derive the dest, so the namespace attribute is always args.output_dims. The block checking hasattr(args, "embedding_output_dims") is always False and is dead code. Remove the second block.
🟡 Medium — _bare_provider() test helper missing attrs added in this PR
Location: tests/unit/provider_test_helpers.py ~L47–90
_bare_provider() constructs OpenAIEmbeddingProvider via __new__(), bypassing __init__. This PR adds _qwen_model_config and _qwen_rerank_config inside _configure_qwen_batch_sizes (called from __init__). Any future test exercising Qwen paths on a bare provider will hit AttributeError. Add provider._qwen_model_config = None and provider._qwen_rerank_config = None to the builder.
🟢 Minor — Magic number 1536 in 3+ places
OPENAI_DEFAULT_DIMS = 1536 alongside the existing OPENAI_DEFAULT_MODEL in constants.py would consolidate the fallback.
🟢 Minor — _trust_runtime_output_dims() name is counter-intuitive
The method returns True to skip static model validation for custom endpoints. _is_custom_openai_endpoint() or _skip_static_model_validation() would communicate intent more clearly.
🟢 Minor — FakeEmbeddingProvider.supported_dimensions returns only 2 values
When output_dims=512 and dims=1536, returns [1536, 512]. A real matryoshka model returns a range. Fine for current tests but could cause false-passing future assertions on intermediate values.
Architecture verification
- VoyageAI
supports_reranking()change — verified againstmain:rerank_modeldefaults toVOYAGE_DEFAULT_RERANK_MODEL("rerank-2.5"), notNone. New logic (return self._rerank_model is not Nonefor official API) is not a behavioral regression. validate_rerank_configurationfor VoyageAI with norerank_urlreturns immediately — no false rejections._FORCE_KILL_DEADLINEseparation correct and the real-subprocess test replacing the brittle mock is strictly better.
All findings are non-blocking. The feature is correctly implemented, the bugs fixed are genuine, and the test coverage is thorough.
Reviewed by Ariel Vaknin via Claude Code
Note: This PR was generated by an AI agent. If you'd like to talk with other humans, drop by our Discord!
Matryoshka Embedding Support
Adds variable-dimension embedding (Matryoshka) to OpenAI & VoyageAI providers — users can now request lower-dimension vectors without switching models.
What Changed
✨ Added: Matryoshka Feature (core)
output_dims,native_dims,client_side_truncation,supported_dimensionspropertiesoutput_dims/client_side_truncationfields with strict validationapply_client_side_truncation,l2_normalize,build_dimension_request_param,validate_positive_output_dims,validate_runtime_output_dims_configEmbeddingProviderError←EmbeddingDimensionError/EmbeddingConfigurationError(both non-retryable)validate_api_keysupports_reranking()guard fix🐛 Fixed: Bugs
_require_env_boolraisesValueErroron non-bool stringsl2_normalize→ division by zeroEmbeddingProviderErrorre-raised before retry loopget_usage_stats()["errors"]"408"→"upstream_timeout"rerank()with_rerank_model=None→ AttributeErrorRuntimeErrorguardvalidate_api_keyblocked on endpoints that don't need a key_endpoint_requires_api_key()first🧹 Refactored / Cleaned Up
EmbeddingProviderProtocol fromembeddings.py(single source of truth)OPENAI_MODEL_CONFIGasOpenAIModelConfigTypedDictshared_utils.py(DRY across providers)_discovered_dims→_discovered_native_dimsmean_pool_embeddings, dead MCP exception exports, deadsupports_matryoshka()sys.modulesmodule-swap withModuleType.__class__hack for realtime indexingBreaking Changes
supports_matryoshka()removed from provider protocol (replaced by metadata properties)_discovered_dims→_discovered_native_dims(internal rename, only affects direct attribute access)Value
Attached is an agent optimized description of the changes in this PR - AGENT_REVIEW.md