Repository navigation
feat(core): improve indexing recovery and scoped retrieval for v4.10.0 - #234
Conversation
FastEmbed TextEmbedding.embed() default batch_size=256 allocates ~500MB intermediate buffers under CPU execution with bge-small at seq_len=512. On fragmented Windows heaps this triggered ONNXRuntime BAD_ALLOC during ingestion of minified JS or large JSON. GPU VRAM is contiguous so 256 is safe. Fix dispatches batch_size based on active ONNX provider: 32 (CPU) / 256 (CUDA). Exposes KNOWLEDGE_RAG_EMBED_BATCH_SIZE env override and documents.embed_batch_size YAML key for per-workload tuning. API surface unchanged (12 MCP tools preserved). Added 3 regression tests and updated 3 existing mock lambdas to accept the new kwarg (baseline 336 -> 339). Closes #224
CI runs ruff 0.16.10 which collapses the three updated lambda mocks back to a single line (they fit in the 120-char limit configured in pyproject.toml). Local ruff 0.16.0 split them. Pinning to CI's version and reformatting. No behavior change — identical AST, same tests pass.
|
Important Review skippedToo many files! This PR contains 144 files, which is 44 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry. ⚙️ Run configuration
📒 Files selected for processing (144)
You can disable this status message by setting the
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. Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Bumps the github-actions group with 3 updates: [actions/checkout](https://github.com/actions/checkout), [actions/setup-python](https://github.com/actions/setup-python) and [actions/setup-node](https://github.com/actions/setup-node). Updates `actions/checkout` from 4 to 7 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v4...v7) Updates `actions/setup-python` from 5 to 7 - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@v5...v7) Updates `actions/setup-node` from 6 to 7 - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](actions/setup-node@v6...v7) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/setup-python dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/setup-node dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] <[email protected]> (cherry picked from commit eedb00a)
Updates the requirements on [hypothesis](https://github.com/HypothesisWorks/hypothesis) to permit the latest version. - [Release notes](https://github.com/HypothesisWorks/hypothesis/releases) - [Commits](HypothesisWorks/hypothesis@v6.165.9...v6.168.3) --- updated-dependencies: - dependency-name: hypothesis dependency-version: 6.168.3 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> (cherry picked from commit f8c51b5)
Updates the requirements on [ruff](https://github.com/astral-sh/ruff) to permit the latest version. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.16.2...0.16.9) --- updated-dependencies: - dependency-name: ruff dependency-version: 0.16.9 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> (cherry picked from commit ee59179)
Updates the requirements on [pytest-rerunfailures](https://github.com/pytest-dev/pytest-rerunfailures) to permit the latest version. - [Changelog](https://github.com/pytest-dev/pytest-rerunfailures/blob/master/CHANGES.rst) - [Commits](pytest-dev/pytest-rerunfailures@16.4...16.7) --- updated-dependencies: - dependency-name: pytest-rerunfailures dependency-version: '16.7' dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> (cherry picked from commit b4e17cb)
Updates the requirements on [mutmut](https://github.com/boxed/mutmut) to permit the latest version. - [Release notes](https://github.com/boxed/mutmut/releases) - [Changelog](https://github.com/boxed/mutmut/blob/main/HISTORY.rst) - [Commits](boxed/mutmut@3.5.0...3.8.0) --- updated-dependencies: - dependency-name: mutmut dependency-version: 3.8.0 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> (cherry picked from commit 1c39cbd)
Updates the requirements on [pytest-memray](https://github.com/bloomberg/pytest-memray) to permit the latest version. - [Release notes](https://github.com/bloomberg/pytest-memray/releases) - [Changelog](https://github.com/bloomberg/pytest-memray/blob/main/docs/news.rst) - [Commits](bloomberg/pytest-memray@v1.10.0...v1.11.0) --- updated-dependencies: - dependency-name: pytest-memray dependency-version: 1.11.0 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> (cherry picked from commit 2c5e541)
…ents (cherry picked from commit cd100f3)
Signed-off-by: Lui Lui <[email protected]> (cherry picked from commit dd488f1)
Signed-off-by: Lui Lui <[email protected]> (cherry picked from commit 4571e3e)
| except Exception: | ||
| newly_created = sorted(set(ids) - set(previous["ids"])) | ||
| if newly_created: | ||
| self._write_collection.delete(ids=newly_created) | ||
| self._fts5_sync_remove_ids(newly_created) | ||
| self._restore_document_chunks(previous) | ||
| self._bm25_initialized = False |
There was a problem hiding this comment.
Failed rollback goes unrecorded
If incremental indexing fails while replacing a document and restoring its previous vectors also fails, this path raises without recording a repair. The inventory still describes the old document, but some vectors may be missing. A later incremental run can skip the unchanged source, leaving it unrepaired.
Prompt To Fix With AI
This is a comment left during a code review.
Path: mcp_server/server.py
Line: 2237-2243
Comment:
**Failed rollback goes unrecorded**
If incremental indexing fails while replacing a document and restoring its previous vectors also fails, this path raises without recording a repair. The inventory still describes the old document, but some vectors may be missing. A later incremental run can skip the unchanged source, leaving it unrepaired.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| except Exception as exc: | ||
| print(f"[RECOVERY] Rebuild committed; post-commit repair cleanup failed: {exc}", file=sys.stderr) | ||
| self._retire_previous_collection(prod_name, ts) | ||
| self._fts5_reset_and_rebuild() |
There was a problem hiding this comment.
Committed swap reports failure
If resetting FTS5 fails after the staging swap, such as when the new SQLite index or migration marker cannot be written, the primary collection and metadata have already committed. This exception still reports the rebuild as failed: startup force-indexes the already-replaced collection, while an MCP caller receives a misleading failure.
Prompt To Fix With AI
This is a comment left during a code review.
Path: mcp_server/server.py
Line: 2896
Comment:
**Committed swap reports failure**
If resetting FTS5 fails after the staging swap, such as when the new SQLite index or migration marker cannot be written, the primary collection and metadata have already committed. This exception still reports the rebuild as failed: startup force-indexes the already-replaced collection, while an MCP caller receives a misleading failure.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| where_filter = {"$and": [where_filter, source_filter]} if where_filter else source_filter | ||
| allowed_ids = None | ||
| if where_filter: | ||
| allowed_ids = frozenset(self.collection.get(where=where_filter, include=[])["ids"]) |
There was a problem hiding this comment.
Every uncached search with a category or folder filter loads all matching chunk IDs from Chroma before requesting a small set of results. A broad filter over a large corpus therefore adds a corpus-sized database read and memory allocation to each distinct query, undermining bounded-memory retrieval.
Prompt To Fix With AI
This is a comment left during a code review.
Path: mcp_server/server.py
Line: 3455
Comment:
**Broad filters load every ID**
Every uncached search with a category or folder filter loads all matching chunk IDs from Chroma before requesting a small set of results. A broad filter over a large corpus therefore adds a corpus-sized database read and memory allocation to each distinct query, undermining bounded-memory retrieval.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Prepare 4.10.0 with bounded memory, safer indexing and rollback, recursive folder filters before retrieval top-k, and better semantic candidate coverage. Repeated indexing previously retained historical state, could duplicate derived rows or lose recoverable state after failures, and could select the wrong root in a Windows preflight subprocess.
Fixes #223, fixes #224, fixes #232, fixes #233.
This candidate incorporates PR #225 and the reviewed contributions from #222, #226 and #227–231. PR #226 includes all four commits through
4571e3e; dependency changes run through the combined CI rather than relying on their older isolated checks. The unpublished 4.9.3 proposal is included in 4.10.0.Type of change
What changed
include_folders/exclude_foldersbefore top-k across Chroma/BM25/FTS5, intersect with category, and include scope in cache identity.Why
The changes address reproduced failures and measured retained state. The broad audit crosses the shared index/cache/publication lifecycle, so independent review and integrated failure tests cover those boundaries. The default embedding model is retained: the isolated multilingual E5 experiment did not improve evidence coverage enough to justify its larger resource cost.
7 Pillars Quality Gate
Measurements and limitations
The 60 development diagnostics improved expected-source hits@10 from 33 to 37 and evidence hits@10 from 28 to 31. These cases were used during development; a separate 12-question reserve is evaluated only after runtime freeze and is not used for tuning. Source matches are not proof of complete or correct generated answers. The larger E5 comparison returned 36 source hits and 31 evidence hits; BGE remains the default.
The frozen final reserve (six PT/EN pairs, twelve questions) improved source hits@10 from 4/12 to 6/12, evidence hits@10 from 3/12 to 4/12 and MRR@10 from 0.2619 to 0.3361. Hits@1 stayed at 3/12. The improvement was confined to English; Portuguese source/evidence hits remained 0/6 in both versions. No runtime or ranking parameter was changed after this evaluation. This is a remaining cross-language limitation, not a claim of resolved multilingual quality. Across the evaluation, 180 direct and 180 MCP calls agreed; seventeen real folder-filter scenarios passed through both interfaces. Negative controls returned approximate context without matching absent markers; generated answers and abstention were not evaluated.
Final Windows CUDA reindex: 5,962 attempted files, 5,951 indexed sources, 70,083 chunks, eleven explicit empty/invalid-source errors. Chroma/FTS5/BM25 counts and vector validation agree. The indexing call took 476.009 seconds, with peak process RSS 2,473,619,456 bytes; the full monitor window was 533.403 seconds. Corpus/configuration hashes remained unchanged.
Earlier controlled local diagnostics found BM25 retained Python memory decrease from 120,711,243 to 26,859,694 bytes for 10,000 documents; histogram retention decrease from 3,201,024 to 328 bytes for 100,001 observations of one series; and 100 FTS5 updates in 100,000 rows decrease from 1.754 to 0.0618 seconds. Initial FTS5 insertion increased from 0.412 to 0.800 seconds. These are workload-specific observations, not universal speed guarantees.
Private corpus paths, content, queries and acceptance artifacts remain local. Empty/invalid sources remain visible failures. AMD DirectML on this Windows adapter does not establish Linux ROCm or Apple GPU support. CPU fallback remains available.
Migration / Breaking changes
No required index-format migration or incompatible MCP tool change. Folder filters use document-root-relative paths and reject traversal, absolute paths and escaping links. Stop legacy server instances before upgrading to the OS lock protocol; do not delete a live
.guardsidecar. Keep embedding-model migrations in separate data/metadata paths.DirectML is explicit and experimental; use an isolated ONNX environment as documented in the GPU guide. The production installation, original corpus, drivers and registry settings are unchanged.
Test plan
199f4c3, documentation head86d44ef.86d44ef: all 35 checks passed. CI, Quality Gate.Documentation
The configuration/API, GPU setup, reindex recovery, multi-client guidance and CHANGELOG are updated. Detailed measurements and qualifications are recorded in
docs/audit-2026-10-03.md,docs/audit-2026-10-04.mdanddocs/search-quality.md.Reviewer checklist
The PR is not ready to merge until incremental rollback failure and post-commit rebuild reporting are corrected.
Fix with agent prompt
Summary
The PR adds folder-scoped retrieval, broad indexing and rollback recovery changes, bounded metrics and indexing work, platform and parser handling, and release tooling.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Discover source files] --> B[Incremental replacement] B --> C[Chroma collection] B --> D[Metadata and repair journal] C --> E[Scoped candidate selection] D --> E E --> F[Semantic / BM25 / FTS5] F --> G[Rerank and return] H[Staging rebuild] --> I[Publish collection and metadata] I --> J[Reset derived FTS5 index]Reviews (1) · Last reviewed commit: "docs(recovery): describe durable repair ..."