Skip to content

Commit 42b7dcf

Browse files
committed
Match the kb folder as a path component in _load_path
_load_path classified any config file or folder whose relative path starts with the letters "kb" as a knowledge-base document. A file named e.g. kbsettings.yml, or a subfolder like kbase/, was therefore treated as an (empty) kb doc and silently dropped -- its YAML config and any .co flows never loaded. Match the kb folder as a path component (kb + os.sep) so only files actually inside kb/ are collected as docs. Signed-off-by: winklemad <winklemad@outlook.com>
1 parent 5331054 commit 42b7dcf

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

nemoguardrails/rails/llm/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,8 +1566,11 @@ def _load_path(
15661566
full_path = os.path.join(root, file)
15671567
rel_path = os.path.relpath(full_path, config_path)
15681568

1569-
# If it's a file in the `kb` folder we need to append it to the docs
1570-
if rel_path.startswith("kb"):
1569+
# If it's a file in the `kb` folder we need to append it to the docs.
1570+
# Match the folder as a path component, not a name prefix, so that
1571+
# files/folders merely named `kb...` (e.g. `kbsettings.yml`) are not
1572+
# misclassified as knowledge-base docs and dropped.
1573+
if rel_path == "kb" or rel_path.startswith("kb" + os.sep):
15711574
_raw_config = {"docs": []}
15721575
if rel_path.endswith(".md"):
15731576
with open(full_path, encoding="utf-8") as f:

tests/test_config_loading.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
from nemoguardrails import RailsConfig
17-
from nemoguardrails.rails.llm.config import Instruction
17+
from nemoguardrails.rails.llm.config import Instruction, _load_path
1818

1919

2020
def test_default_instructions():
@@ -56,3 +56,24 @@ def test_instructions_override():
5656
content="Below is a conversation between a helpful AI assistant and a user.\n",
5757
)
5858
]
59+
60+
61+
def test_load_path_kb_prefixed_names_are_not_dropped(tmp_path):
62+
# A file or folder whose name merely starts with "kb" (but is not inside the
63+
# `kb/` knowledge-base folder) must be loaded normally, not silently dropped
64+
# as an empty knowledge-base doc.
65+
(tmp_path / "kbsettings.yml").write_text('sample_conversation: "hello world"\n')
66+
(tmp_path / "kbase").mkdir()
67+
(tmp_path / "kbase" / "greeting.co").write_text("define flow greeting\n bot express greeting\n")
68+
# A genuine kb/ document must still be collected as a doc (control).
69+
(tmp_path / "kb").mkdir()
70+
(tmp_path / "kb" / "doc.md").write_text("# real kb doc\n")
71+
72+
raw_config, colang_files = _load_path(str(tmp_path))
73+
74+
# kb-prefixed config file is parsed, not dropped.
75+
assert raw_config.get("sample_conversation") == "hello world"
76+
# kb-prefixed subfolder's colang file is registered.
77+
assert any(name == "greeting.co" for name, _ in colang_files)
78+
# a genuine kb/ document is still collected as a doc (control).
79+
assert {"format": "md", "content": "# real kb doc\n"} in raw_config.get("docs", [])

0 commit comments

Comments
 (0)