fix(config): preserve KB default fallbacks#609
Open
VectorPeak wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes KB config fallback handling so empty or missing per-KB
rag_providerandsearch_modevalues inkb_config.jsonare treated as unset instead of overriding configured global defaults.What Problem This Solves
KnowledgeBaseConfigService.get_kb_config()is the read boundary that turns the persistedkb_config.jsonentry for a knowledge base into the runtime configuration used by RAG pipelines. The previous merge order applied default values first, then expanded**kb_config, so persisted per-KB empty strings could shadow the configured global defaults.A config shaped like this should mean "this KB has no explicit provider or search mode; use the global defaults":
{ "defaults": {"rag_provider": "graphrag", "search_mode": "global"}, "knowledge_bases": { "kb-empty": {"path": "kb-empty", "rag_provider": "", "search_mode": ""} } }Instead, the empty per-KB values were allowed to participate as if they were real overrides. For
search_mode, the empty string could replace the intended global mode. Forrag_provider, the empty value was even more misleading because provider normalization can collapse unknown or empty values back to the hardcoded default provider,llamaindex, before the configured global default, such asgraphrag, is applied.This makes the effective runtime config depend on whether a KB entry contains blank fields versus missing fields, even though both represent "unset" values from the user's point of view.
Changes
This PR makes the config fallback behavior explicit at the central config service boundary:
rag_providervalues are treated as unset during payload normalization instead of being materialized immediately asllamaindexget_kb_config()now applies the finalrag_providerandsearch_modefallback assignments after merging the KB entry, so blank persisted values cannot shadow global defaultsValid non-empty per-KB overrides still take priority over global defaults. Unknown legacy provider strings still normalize to
llamaindexand keep the existing reindex hint behavior. The change is intentionally limited to KB config fallback handling and does not alter RAG pipeline selection, indexing, retrieval, or unrelated config modules.Evidence
The added config test covers both affected fallback shapes:
Focused validation for the PR passed locally:
Possible call chain / impact
The change affects only empty or missing per-KB fallback handling. Explicit non-empty per-KB overrides remain the higher-priority KB-specific values, legacy unknown provider normalization still falls back to
llamaindex, and unrelated config modules are not changed.Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservicestoolsutilsweb(Frontend)docs(Documentation)scriptstests...Checklist
pre-commit run --all-filesand fixed any issues.Additional Notes
Evidence:
test_get_kb_config_empty_or_missing_fields_fall_back_to_defaults, covering empty per-KBrag_provider/search_modeand a KB entry with those fields missing.uvx --from pytest==8.4.2 --with pytest-asyncio --with PyYAML --with pydantic --with croniter --with requests pytest -q tests\services\config\test_knowledge_base_config.pypassed: 17 tests.uvx ruff check deeptutor\services\config\knowledge_base_config.py tests\services\config\test_knowledge_base_config.pypassed.uvx ruff format --check deeptutor\services\config\knowledge_base_config.py tests\services\config\test_knowledge_base_config.pypassed.git diff --checkpassed.pre-commit run --all-fileswas attempted viauvx pre-commit run --all-files. Python hooks passed through Ruff, but the full run could not complete cleanly in this Windows environment because:prettierattempted to reformat many unrelatedweb/files; those unrelated formatter side effects were reverted and are not included in this PR.banditfailed with repository configuration error:Unknown test found in profile: B105.mypyreported existing Windows platform issues around POSIX-only APIs such asresource.setrlimit,os.fork,os.getpgid, andos.killpg.