mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 16:48:30 +00:00
Fix syntax errors in memory storage implementation
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -23,39 +23,41 @@ class EntityMemory(Memory):
|
|||||||
if crew and hasattr(crew, "memory_config") and crew.memory_config is not None:
|
if crew and hasattr(crew, "memory_config") and crew.memory_config is not None:
|
||||||
memory_config = crew.memory_config
|
memory_config = crew.memory_config
|
||||||
memory_provider = memory_config.get("provider")
|
memory_provider = memory_config.get("provider")
|
||||||
|
|
||||||
# Initialize with basic parameters
|
|
||||||
super().__init__(
|
|
||||||
storage=storage,
|
|
||||||
embedder_config=embedder_config,
|
|
||||||
memory_provider=memory_provider
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
# If no storage is provided, try to create one
|
||||||
# Try to select storage using helper method
|
if storage is None:
|
||||||
self.storage = self._select_storage(
|
try:
|
||||||
storage=storage,
|
# Try to select storage using helper method
|
||||||
memory_config=memory_config,
|
storage = self._select_storage(
|
||||||
storage_type="entity",
|
storage=storage,
|
||||||
crew=crew,
|
memory_config=memory_config,
|
||||||
path=path,
|
storage_type="entity",
|
||||||
default_storage_factory=lambda path, crew: RAGStorage(
|
crew=crew,
|
||||||
|
path=path,
|
||||||
|
default_storage_factory=lambda path, crew: RAGStorage(
|
||||||
|
type="entities",
|
||||||
|
allow_reset=True,
|
||||||
|
crew=crew,
|
||||||
|
embedder_config=embedder_config,
|
||||||
|
path=path,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
# Fallback to default storage
|
||||||
|
storage = RAGStorage(
|
||||||
type="entities",
|
type="entities",
|
||||||
allow_reset=True,
|
allow_reset=True,
|
||||||
crew=crew,
|
crew=crew,
|
||||||
embedder_config=embedder_config,
|
embedder_config=embedder_config,
|
||||||
path=path,
|
path=path,
|
||||||
)
|
)
|
||||||
)
|
|
||||||
except ValueError:
|
# Initialize with parameters
|
||||||
# Fallback to default storage
|
super().__init__(
|
||||||
self.storage = RAGStorage(
|
storage=storage,
|
||||||
type="entities",
|
embedder_config=embedder_config,
|
||||||
allow_reset=True,
|
memory_provider=memory_provider
|
||||||
crew=crew,
|
)
|
||||||
embedder_config=embedder_config,
|
|
||||||
path=path,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def save(
|
def save(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from typing import Any, Dict, List, Optional
|
|||||||
from crewai.memory.storage.interface import SearchResult, Storage
|
from crewai.memory.storage.interface import SearchResult, Storage
|
||||||
|
|
||||||
|
|
||||||
class BaseRAGStorage(Storage, ABC):
|
class BaseRAGStorage(Storage[Any], ABC):
|
||||||
"""
|
"""
|
||||||
Base class for RAG-based Storage implementations.
|
Base class for RAG-based Storage implementations.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class RAGStorage(BaseRAGStorage):
|
|||||||
search efficiency.
|
search efficiency.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
app: ClientAPI | None = None
|
app: Optional[ClientAPI] = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, type, allow_reset=True, embedder_config=None, crew=None, path=None
|
self, type, allow_reset=True, embedder_config=None, crew=None, path=None
|
||||||
@@ -137,7 +137,7 @@ class RAGStorage(BaseRAGStorage):
|
|||||||
logging.error(f"Error during {self.type} search: {str(e)}")
|
logging.error(f"Error during {self.type} search: {str(e)}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _generate_embedding(self, text: str, metadata: Dict[str, Any]) -> None: # type: ignore
|
def _generate_embedding(self, text: str, metadata: Optional[Dict[str, Any]] = None) -> Any:
|
||||||
if not hasattr(self, "app") or not hasattr(self, "collection"):
|
if not hasattr(self, "app") or not hasattr(self, "collection"):
|
||||||
self._initialize_app()
|
self._initialize_app()
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from crewai.memory.storage.interface import SearchResult, Storage
|
|||||||
from crewai.memory.user.user_memory import UserMemory
|
from crewai.memory.user.user_memory import UserMemory
|
||||||
|
|
||||||
|
|
||||||
class CustomStorage(Storage):
|
class CustomStorage(Storage[Any]):
|
||||||
"""Custom storage implementation for testing."""
|
"""Custom storage implementation for testing."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -141,7 +141,7 @@ def test_custom_storage_with_memory_config():
|
|||||||
def test_custom_storage_error_handling():
|
def test_custom_storage_error_handling():
|
||||||
"""Test error handling with custom storage."""
|
"""Test error handling with custom storage."""
|
||||||
# Test exception propagation
|
# Test exception propagation
|
||||||
class ErrorStorage(Storage):
|
class ErrorStorage(Storage[Any]):
|
||||||
"""Storage implementation that raises exceptions."""
|
"""Storage implementation that raises exceptions."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.data = []
|
self.data = []
|
||||||
@@ -172,7 +172,7 @@ def test_custom_storage_error_handling():
|
|||||||
|
|
||||||
def test_custom_storage_edge_cases():
|
def test_custom_storage_edge_cases():
|
||||||
"""Test edge cases with custom storage."""
|
"""Test edge cases with custom storage."""
|
||||||
class EdgeCaseStorage(Storage):
|
class EdgeCaseStorage(Storage[Any]):
|
||||||
"""Storage implementation for testing edge cases."""
|
"""Storage implementation for testing edge cases."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.data = []
|
self.data = []
|
||||||
|
|||||||
Reference in New Issue
Block a user