Skip to content

fix(index): build the vector schema from the provider's width (G4) - #123

Merged
ManSio merged 2 commits into
mainfrom
fix/g4-embedding-dim-contract
Nov 12, 2026
Merged

ManSio merged 2 commits into
mainfrom
fix/g4-embedding-dim-contract

Conversation

@ManSio

@ManSio ManSio commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Merge branch 'main' into fix/g4-embedding-dim-contract

Bring the G4 embedding-width contract onto the post-merge main (G1/G2/G3/G4
docs, Goal 2 install/data/docs work). AGENT_DIARY.md conflict resolved by
keeping every dated entry.

Audit in the same pass:

  • stale_detector: a dependency pin (onnxruntime==1.27.0) was compared with
    the project version (3.5.0) and reported as doc drift on ru/zh
    SYSTEM_REQUIREMENTS, where the pin is correct. Versions preceded by
    =/@/~/>/</^/! are now skipped as pins, not project versions.
    Guard: tests/test_stale_detector_versions.py (2 cases; the positive control
    proves a real drift is still reported). The guard's negative control was
    re-proved and re-pinned (reason recorded in pin_log.json) -> ALL PROVEN (3).
  • Diary records the merge hashes, the new test bar and the audit results.

Gates on this branch with the merge applied:
pytest tests/ -m "not integration and not benchmark"
-> 2607 passed, 9 skipped (was 2560/10)
ruff_gate -> OK
smoke_e2e --project . -> PASSED (4 checks, step 4 = text, shipped default)
stale_detector -> Docs appear up to date
check_docs_vs_installer -> 155 flags, 0 problems
check_docs_vs_config -> 66 variables, 0 problems

The dense build failed with "Cannot cast to FixedSizeList(384): value at index 0
has length 768" on a table declared 384-d with zero rows. The cast was a symptom.

Root cause: `LanceDBManager._open_or_create_table` read the stored width from a
sample ROW, and the migration helpers used `table = table or self.table`. An
empty LanceDB table is falsy, so on an empty table `self.table` (not yet
assigned) raised AttributeError, the broad handler treated that as "table not
found", and the dimension check never ran.

Contract (new `src/core/indexing/dim_contract.py`):
  - a provider declares its output width (`embedding_dim` / `provider_name`);
  - the schema is built from that width;
  - an empty table with another width is rebuilt (no rows to lose);
  - a non-empty table with another width refuses loudly: provider name and both
    numbers (`EmbeddingDimMismatch`), never a silent 768->384 resize;
  - `LanceDBWriter` no longer pads or truncates a vector.
The schema width is read from the SCHEMA, not from a data row.

Retries: `bounded_attempts` replaces the open-ended "embed error -> idle-unload
-> restart" loop on the llama branch: 3 batch attempts, one revive, two single
attempts, then `EmbedderUnavailable` with provider and last error (BLOCKED).
Red-first test: `test_embed_batch_raises_blocked_instead_of_restart_loop`.

External endpoints: `MSCODEBASE_EMBEDDER_PROVIDER` pins the provider. With it
set, the background scanner and the :8080 dimension probe are disabled, so
LM Studio / llama-server only answer when named. `auto` keeps the old order.

Smoke: the query vector comes from the active provider and its width is checked
against the table schema before search; an empty vector table falls back to the
text index (shipped default stays text-only). No `--dense` flag was added.

Measured (night 12->13.11.2026, temp data root):
  provider onnx:multilingual-e5-small-int8, dim 384
  7307 chunks, fixed_size_list<float>[384], 2210.8 s, 73.3 MB
  smoke_e2e --project . with MSCODEBASE_DENSE_OFF=false:
    PASSED (4 checks), step 4 = vector, provider=onnx, dim=384, results=3

Gates: pytest -m "not integration and not benchmark" 2570 passed / 10 skipped
(was 2560; +10 new, none lost), ruff OK, text-only smoke PASSED.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ee64c762-66ba-445e-8279-93907606a408
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Bring the G4 embedding-width contract onto the post-merge main (G1/G2/G3/G4
docs, Goal 2 install/data/docs work). AGENT_DIARY.md conflict resolved by
keeping every dated entry.

Audit in the same pass:
- stale_detector: a dependency pin (`onnxruntime==1.27.0`) was compared with
  the project version (3.5.0) and reported as doc drift on ru/zh
  SYSTEM_REQUIREMENTS, where the pin is correct. Versions preceded by
  `=`/`@`/`~`/`>`/`<`/`^`/`!` are now skipped as pins, not project versions.
  Guard: tests/test_stale_detector_versions.py (2 cases; the positive control
  proves a real drift is still reported). The guard's negative control was
  re-proved and re-pinned (reason recorded in pin_log.json) -> ALL PROVEN (3).
- Diary records the merge hashes, the new test bar and the audit results.

Gates on this branch with the merge applied:
  pytest tests/ -m "not integration and not benchmark"
    -> 2607 passed, 9 skipped (was 2560/10)
  ruff_gate -> OK
  smoke_e2e --project . -> PASSED (4 checks, step 4 = text, shipped default)
  stale_detector -> Docs appear up to date
  check_docs_vs_installer -> 155 flags, 0 problems
  check_docs_vs_config -> 66 variables, 0 problems
@ManSio
ManSio merged commit a25627a into main Nov 12, 2026
13 checks passed
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