Compare commits

..

3 Commits

Author SHA1 Message Date
Devin AI
ae5f4fb9cb Fix import sorting with ruff --fix
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-25 14:00:12 +00:00
Devin AI
71ff89c8c7 Fix import sorting in knowledge storage test
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-25 13:58:56 +00:00
Devin AI
74e018ae43 Fix #2464: Fix embedding dimension mismatch with reset-memories command
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-25 13:57:20 +00:00
11 changed files with 89 additions and 23 deletions

View File

@@ -1,7 +1,6 @@
---
title: 'Event Listeners'
description: 'Tap into CrewAI events to build custom integrations and monitoring'
icon: spinner
---
# Event Listeners

View File

@@ -97,19 +97,14 @@
"how-to/kickoff-async",
"how-to/kickoff-for-each",
"how-to/replay-tasks-from-latest-crew-kickoff",
"how-to/conditional-tasks"
]
},
{
"group": "Agent Monitoring & Observability",
"pages": [
"how-to/conditional-tasks",
"how-to/weave-integration",
"how-to/agentops-observability",
"how-to/langfuse-observability",
"how-to/langtrace-observability",
"how-to/mlflow-observability",
"how-to/openlit-observability",
"how-to/portkey-observability"
"how-to/portkey-observability",
"how-to/langfuse-observability"
]
},
{

View File

@@ -1,5 +1,5 @@
---
title: AgentOps Integration
title: Agent Monitoring with AgentOps
description: Understanding and logging your agent performance with AgentOps.
icon: paperclip
---

View File

@@ -1,7 +1,7 @@
---
title: Langfuse Integration
title: Agent Monitoring with Langfuse
description: Learn how to integrate Langfuse with CrewAI via OpenTelemetry using OpenLit
icon: vials
icon: magnifying-glass-chart
---
# Integrate Langfuse with CrewAI

View File

@@ -1,5 +1,5 @@
---
title: Langtrace Integration
title: Agent Monitoring with Langtrace
description: How to monitor cost, latency, and performance of CrewAI Agents using Langtrace, an external observability tool.
icon: chart-line
---

View File

@@ -1,5 +1,5 @@
---
title: MLflow Integration
title: Agent Monitoring with MLflow
description: Quickly start monitoring your Agents with MLflow.
icon: bars-staggered
---

View File

@@ -1,5 +1,5 @@
---
title: OpenLIT Integration
title: Agent Monitoring with OpenLIT
description: Quickly start monitoring your Agents in just a single line of code with OpenTelemetry.
icon: magnifying-glass-chart
---

View File

@@ -1,5 +1,5 @@
---
title: Portkey Integration
title: Agent Monitoring with Portkey
description: How to use Portkey with CrewAI
icon: key
---

View File

@@ -1,7 +1,7 @@
---
title: Weave Integration
description: Learn how to use Weights & Biases (W&B) Weave to track, experiment with, evaluate, and improve your CrewAI applications.
icon: radar
icon: insights
---
# Weave Overview

View File

@@ -114,8 +114,20 @@ class KnowledgeStorage(BaseKnowledgeStorage):
settings=Settings(allow_reset=True),
)
self.app.reset()
shutil.rmtree(base_path)
# If a specific collection name is provided, try to delete just that collection
if self.collection_name:
try:
collection_name = f"knowledge_{self.collection_name}"
self.app.delete_collection(name=collection_name)
Logger(verbose=True).log("info", f"Collection '{collection_name}' has been reset.")
except Exception:
# If deletion of specific collection fails, fall back to resetting all
self.app.reset()
shutil.rmtree(base_path)
else:
self.app.reset()
shutil.rmtree(base_path)
self.app = None
self.collection = None
@@ -164,15 +176,19 @@ class KnowledgeStorage(BaseKnowledgeStorage):
ids=filtered_ids,
)
except chromadb.errors.InvalidDimensionException as e:
collection_reset_cmd = "`crewai reset-memories -a`"
if self.collection_name:
collection_reset_cmd = f"`crewai reset-memories --knowledge` (for collection: {self.collection_name})"
Logger(verbose=True).log(
"error",
"Embedding dimension mismatch. This usually happens when mixing different embedding models. Try resetting the collection using `crewai reset-memories -a`",
f"Embedding dimension mismatch. This usually happens when mixing different embedding models. Try resetting using {collection_reset_cmd}",
"red",
)
raise ValueError(
"Embedding dimension mismatch. Make sure you're using the same embedding model "
"across all operations with this collection."
"Try resetting the collection using `crewai reset-memories -a`"
f"Embedding dimension mismatch. Make sure you're using the same embedding model "
f"across all operations with this collection. "
f"Try resetting using {collection_reset_cmd}"
) from e
except Exception as e:
Logger(verbose=True).log("error", f"Failed to upsert documents: {e}", "red")

View File

@@ -0,0 +1,56 @@
import os
from unittest.mock import MagicMock, patch
import pytest
from crewai.knowledge.storage.knowledge_storage import KnowledgeStorage
class TestKnowledgeStorage:
@patch("crewai.knowledge.storage.knowledge_storage.chromadb")
@patch("crewai.knowledge.storage.knowledge_storage.shutil")
def test_reset_with_default_collection(self, mock_shutil, mock_chromadb):
# Setup
mock_app = MagicMock()
mock_chromadb.PersistentClient.return_value = mock_app
# Execute
storage = KnowledgeStorage()
storage.reset()
# Verify
mock_app.reset.assert_called_once()
mock_shutil.rmtree.assert_called_once()
@patch("crewai.knowledge.storage.knowledge_storage.chromadb")
@patch("crewai.knowledge.storage.knowledge_storage.shutil")
def test_reset_with_custom_collection(self, mock_shutil, mock_chromadb):
# Setup
mock_app = MagicMock()
mock_chromadb.PersistentClient.return_value = mock_app
# Execute
storage = KnowledgeStorage(collection_name="custom_collection")
storage.reset()
# Verify
mock_app.delete_collection.assert_called_once_with(name="knowledge_custom_collection")
mock_app.reset.assert_not_called()
mock_shutil.rmtree.assert_not_called()
@patch("crewai.knowledge.storage.knowledge_storage.chromadb")
@patch("crewai.knowledge.storage.knowledge_storage.shutil")
def test_reset_with_custom_collection_fallback(self, mock_shutil, mock_chromadb):
# Setup
mock_app = MagicMock()
mock_app.delete_collection.side_effect = Exception("Collection not found")
mock_chromadb.PersistentClient.return_value = mock_app
# Execute
storage = KnowledgeStorage(collection_name="custom_collection")
storage.reset()
# Verify
mock_app.delete_collection.assert_called_once_with(name="knowledge_custom_collection")
mock_app.reset.assert_called_once()
mock_shutil.rmtree.assert_called_once()