Repository navigation
fix(tools): isolate RAG auto-detection across items and support uppercase extensions - #7828
Conversation
…case extensions In CrewAIRagAdapter.add(), when data_type was not specified, the loop reassigned the outer data_type variable on the first item, permanently locking its type onto all subsequent items. This caused tool.add(directory, file) to crash with ValueError: Directory does not exist on the file. Additionally, DataTypes.from_content() checked suffixes using path.endswith() without lowercasing, causing uppercase extensions like .PDF and .JSON to fall back to DataType.TEXT_FILE (which crashes binary files with UnicodeDecodeError in TextFileLoader) or DataType.WEBSITE for URLs. Fixes crewAIInc#7827
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughRAG ingestion now detects mapped file extensions without case sensitivity. It also resolves the data type separately for each content item and uses that type when processing and recording the item. ChangesRAG content type detection
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The mixed-item regression test would fail with the previous behavior, and no actionable merge risk is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
cc Vidit Ostwal (@Vidit-Ostwal) João Moura (@joaomdmoura) whenever you have a moment to review. This addresses #7827 by ensuring RAG auto-detection uses an item-local data type instead of mutating the outer loop variable across multi-item inputs, and makes extension matching in DataTypes.from_content case-insensitive. Regression unit tests are included and all checks are passing. |
Related issue
Fixes #7827
Summary
In
CrewAIRagAdapter.add(), whendata_typewas not explicitly provided, the loop reassigned the outerdata_typeparameter to the first item's detected type (data_type = DataTypes.from_content(...)). Subsequent iterations sawif not data_type:asFalseand forced that type onto every subsequent item. Callingrag_tool.add(directory, file)crashed withValueError: Directory does not exist: <file>because the file was validated as a directory.In addition,
DataTypes.from_content()checked extensions withpath.endswith(ext)without lowercasing, causing uppercase extensions (.PDF,.JSON,.CSV,.DOCX) to fall back toDataType.TEXT_FILE. InTextFileLoader, decoding binary.PDFor.DOCXfiles with UTF-8 crashed immediately withUnicodeDecodeError. For URLs, uppercase extensions fell back toDataType.WEBSITE.This fix:
CrewAIRagAdapter.add()with a loop-localitem_data_type, so each item incontent_itemsis auto-detected independently.pathbefore checking suffix mappings inDataTypes.from_content().Verification
Added
TestAutoDetectMultipleItemsAndCaseSensitivitytolib/crewai-tools/tests/tools/rag/test_rag_tool_add_data_type.py:test_auto_detect_uppercase_file_extensiontest_auto_detect_uppercase_url_extensiontest_auto_detect_multiple_items_independent_typesAll 54 tests in
lib/crewai-tools/tests/tools/rag/pass locally.Additional context
None
Note
Low Risk
Scoped bugfix in RAG ingestion auto-detection with new regression tests; no auth, security, or persistence schema changes.
Overview
Fixes two bugs in RAG
add()auto-detection that broke mixed batch ingestion and uppercase filenames.Per-item type detection: When
data_typeis omitted, the adapter no longer writes the first item’s detected type back into the shareddata_typevariable inside the loop. Each content item now uses a loop-localitem_data_type, so calls likeadd(directory, file)no longer treat the file as a directory (which raisedValueError: Directory does not exist).Case-insensitive extensions:
DataTypes.from_content()lowercases the path before suffix matching, so extensions such as.JSON,.PDF, and.CSVresolve to the correct loaders instead of falling back to text/website handling (which could trigger decode errors on binary formats).Regression coverage adds tests for uppercase paths/URLs and directory-plus-file batches without type leakage.
Reviewed by Cursor Bugbot for commit 7b1c87a. Bugbot is set up for automated code reviews on this repo. Configure here.