Add metadata support to Knowledge Source classes

- Implement _coerce_to_records function to handle both string and dict formats
- Update KnowledgeStorage.save() to accept list[str] | list[dict[str, Any]]
- Add metadata (filepath, chunk_index, source_type) to all Knowledge Source classes:
  - TextFileKnowledgeSource
  - PDFKnowledgeSource
  - CSVKnowledgeSource
  - JSONKnowledgeSource
  - ExcelKnowledgeSource (includes sheet_name for multi-sheet files)
  - StringKnowledgeSource
  - CrewDoclingSource
- Add comprehensive tests for metadata functionality
- Maintain backward compatibility with existing string-based chunks

Fixes #3812

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-10-30 09:04:35 +00:00
parent 2e9eb8c32d
commit 82bb304147
10 changed files with 4626 additions and 4058 deletions

8079
uv.lock generated

File diff suppressed because it is too large Load Diff