mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
fix: handle empty documents list in KnowledgeStorage.save() and asave()
Fixes #4277 When KnowledgeStorage.save() or asave() is called with an empty documents list, the method now returns early instead of propagating a low-level ValueError from ChromaDB's upsert operation. This is a valid edge case that can occur in real-world workflows (e.g., after filtering, retrieval failures, or conditional logic), and should be handled gracefully as a no-op. Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -99,6 +99,9 @@ class KnowledgeStorage(BaseKnowledgeStorage):
|
||||
)
|
||||
|
||||
def save(self, documents: list[str]) -> None:
|
||||
if not documents:
|
||||
return
|
||||
|
||||
try:
|
||||
client = self._get_client()
|
||||
collection_name = (
|
||||
@@ -177,6 +180,9 @@ class KnowledgeStorage(BaseKnowledgeStorage):
|
||||
Args:
|
||||
documents: List of document strings to save.
|
||||
"""
|
||||
if not documents:
|
||||
return
|
||||
|
||||
try:
|
||||
client = self._get_client()
|
||||
collection_name = (
|
||||
|
||||
Reference in New Issue
Block a user