Skip to content

fix(knowledge): migrate Chroma collection on embedding-dimension mismatch (#10420) - #10439

Merged
mrveiss merged 3 commits into
Dev_new_guifrom
issue-10420
Jun 22, 2026
Merged

mrveiss merged 3 commits into
Dev_new_guifrom
issue-10420

Conversation

@mrveiss

@mrveiss mrveiss commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Thinking Path

While validating "log errors solved in codebase" on the live box, backend-error.log was flooded by services.knowledge.doc_indexer — Dropping chunk … Collection expecting embedding with dimension of 768, got 3072 (one per chunk). A ChromaDB collection's dimension is fixed at creation; when the configured embedding model changes dimension, get_or_create_collection returns the stale collection and every upsert is rejected → knowledge indexing silently broken + log flood.

What Changed

services/knowledge/doc_indexer.py:

  • Detect the dimension mismatch at init and migrate (opt-in AUTOBOT_KNOWLEDGE_AUTO_REINDEX_ON_DIM_MISMATCH=true → delete + re-index, since old vectors are unusable) or raise once with an actionable message — never the per-chunk flood.
  • Robust dimension resolution — the original guard only fired for models in _KNOWN_DIMS, so the live 3072-dim model bypassed it entirely:
    • active dim: org config → _KNOWN_DIMS → live probe of the embedding model
    • existing dim: provenance metadata → peek an actual stored vector (legacy collections created before provenance)

Verification

  • pytest services/knowledge/test_doc_indexer_dim_mismatch.py → 30 passed (probe, legacy-peek, config-dim, the exact 768→3072 case, flag on/off, idempotency).
  • flake8 --max-line-length=120 clean.

Model Used

Claude Opus 4.8

Closes #10420.

…atch instead of dropping all chunks (#10420)

A ChromaDB collection's vector dimension is fixed at creation. When the active
embedding model's dimension changes, get_or_create_collection returns the OLD
collection and every upsert is rejected — flooding backend-error.log with one
"Dropping chunk ... Collection expecting embedding with dimension of N, got M"
per chunk and silently breaking knowledge indexing (observed live: 768 vs 3072).

Detect the mismatch at init and either recreate the collection (opt-in
AUTOBOT_KNOWLEDGE_AUTO_REINDEX_ON_DIM_MISMATCH=true, destructive → re-index) or
raise once with an actionable message — instead of the per-chunk flood.

Robust dimension resolution (the original guard only worked for _KNOWN_DIMS
models, so the live 3072-dim model silently bypassed it):
- active dim: org config > _KNOWN_DIMS > live probe of the embedding model
- existing dim: provenance metadata > peek an actual stored vector (legacy
  collections created before provenance metadata)

30 unit tests (probe, legacy-peek, config-dim, the 768→3072 case, flag on/off).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No hardcoded values detected that have SSOT config equivalents!

github-actions Bot and others added 2 commits June 22, 2026 07:14
Applied Black, isort, and autoflake to match code-quality checks.
Triggered by workflow auto-fix-formatting.yml.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@mrveiss
mrveiss merged commit ca0c1d4 into Dev_new_gui Jun 22, 2026
28 checks passed
@mrveiss
mrveiss deleted the issue-10420 branch June 22, 2026 08:00
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