feat(embeddings): forward dimensions param in HTTP embedding requests#1498
Conversation
…TP request body
When GITNEXUS_EMBEDDING_DIMS is set, include it as the `dimensions` field
in the /v1/embeddings request body. This enables Matryoshka-capable models
(OpenAI text-embedding-3-*, Cohere embed-v3, Voyage) to return truncated
vectors at the requested size.
When the env var is unset, the request body remains `{ input, model }` —
no breaking change for backends that reject unknown fields.
Adds 4 unit tests covering both paths (with/without dimensions) on both
the batch embed and single-query embed code paths.
|
Someone is attempting to deploy a commit to the NexusCore Team on Vercel. A member of the Team first needs to authorize it. |
|
Claude finished @magyargergo's task in 5m 27s —— View job Adversarial Production-Readiness Review — PR #1498Tasks completed:
Review bar for this PRApplied against: DoD.md §2 (Correctness, Contracts, Security, Tests), §4.2 (gitnexus/ validation baseline), plus the PR-specific Definition of Done from the trigger comment. Key gates:
Current PR state
Cannot verify: Final unit test conclusion on all 3 OS. Merge is conditional on CI passing. Branch hygiene assessmentVerdict: merge-from-main commit present but harmless and merge-safe. Git evidence: the feature commit Understanding of the changeBefore this PR, The PR adds a The MCP single-query path ( FindingsFinding 1 —
|
| Path | Unset dims body | Set dims body | Mismatch detection |
|---|---|---|---|
embedText (batch) |
✅ line 99 | ✅ line 121 | ✅ line 311 |
embedQuery (MCP) |
— | ✅ line 144 | ✅ line 376 |
| Retry preserves body | ✅ (body is pre-serialized string) | — | — |
| API key absent from errors | ✅ line 206 | — | — |
| Multi-batch, dims set | ❌ missing | ❌ missing | — |
| Invalid env string | ❌ missing | — | — |
vi.resetModules() + env cleanup in afterEach at lines 19–29 is sufficient to prevent module-level cache leakage between tests. Each test re-imports its module after setting env vars. Isolation is adequate.
CI / checks
- TypeScript typecheck: ✅
quality / typecheckpassed on current head199e662 - Lint + format: ✅ passed
- Unit tests (Ubuntu/Windows/macOS): 🔄 in progress at review time, zero failed steps
- CodeQL + Gitleaks + Dependency Review: ✅ all passed
- The macOS
onnxruntimelocal incompatibility noted in the PR body is the ONNX path, not the HTTP path. HTTP embedding tests mockfetchglobally and do not touch ONNX/transformers.js, so they will pass on macOS CI. The PR body's "could not fully run locally" note is not a CI coverage gap.
Hidden Unicode
- Bidi controls (U+202A–U+202E, U+2066–U+2069): None found in either changed file. ✅
- Non-ASCII characters: 3 occurrences of em dash
—(U+2014) inhttp-client.tscomments at lines 8, 33, and 250. These are ordinary visible punctuation in comments, consistent with repo style (em dashes appear throughout the codebase). Not bidi controls, not in executable code or test assertions. No blocking Unicode issue. ✅
Final verdict
Production-ready with minor follow-ups.
The core change is correctly implemented end-to-end: unset dimensions preserve the exact previous request shape (key-absence verified by test, not just undefined-value), set dimensions are threaded consistently through both the batch ingestion path and the MCP single-query path, returned-vector validation remains on both paths preventing bad vectors from reaching FLOAT[N] storage, API keys are absent from all error surfaces, Unicode is clean, and branch hygiene is acceptable. TypeScript typecheck, lint, and format all passed on the current head; unit tests are in progress with no failures visible. The two follow-up items — (1) strict parseInt validation for GITNEXUS_EMBEDDING_DIMS (pre-existing pattern, low risk) and (2) a multi-batch test verifying dimensions forwarding on each fetch call (code is correct, test gap only) — do not block merge but should be addressed before the next embedding-related change.
CI Report✅ All checks passed Pipeline Status
Test Results
✅ All 8677 tests passed 1 test(s) skipped — expand for details
Code CoverageTests
📋 View full run · Generated by CI |
|
@henry201605 Could you please look into claude's findings? 🙏 |
…ch test, comment wording 1. Strict parseInt validation: reject non-numeric strings like '1024abc' by checking /^\d+$/ before parseInt (Finding 1). 2. Add multi-batch test asserting dimensions is forwarded in every fetch call when inputs exceed batch size (Finding 2). 3. Soften JSDoc comment: backends may ignore or reject the dimensions field rather than universally ignoring it (Finding 3). 4. Add test for invalid GITNEXUS_EMBEDDING_DIMS values.
|
@magyargergo Thanks for flagging these! All three findings have been addressed in be1073e:
Also added a test for invalid |
Summary
Forward GITNEXUS_EMBEDDING_DIMS as the dimensions field in the /v1/embeddings HTTP request body, enabling Matryoshka-capable models to return truncated vectors at the requested size.
Motivation / context
Models like OpenAI text-embedding-3-large (3072d native) support returning lower-dimensional vectors via the dimensions request parameter. Previously, GitNexus only used GITNEXUS_EMBEDDING_DIMS for local validation of the returned vector length — it was never sent to the endpoint. This meant users could not leverage Matryoshka truncation (e.g. requesting 1024d from a 3072d model) and would get a dimension-mismatch error instead.
Areas touched
Scope and constraints
In scope
Explicitly out of scope / not done here
Implementation notes
Testing and verification
4 new unit tests added:
Risk and rollout
Checklist