mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
import sys
|
|
|
|
from pydantic import BaseModel
|
|
|
|
if sys.version_info < (3, 11):
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
from typing_extensions import Self
|
|
else:
|
|
from typing import Any, Dict, List, Optional, Self
|
|
|
|
|
|
class Memory(BaseModel):
|
|
"""
|
|
Base class for memory, now supporting agent tags and generic metadata.
|
|
"""
|
|
|
|
embedder_config: Optional[Dict[str, Any]] = None
|
|
crew: Optional[Any] = None
|
|
|
|
storage: Any
|
|
|
|
def __init__(self, storage: Any, **data: Any):
|
|
super().__init__(storage=storage, **data)
|
|
|
|
def save(
|
|
self,
|
|
value: Any,
|
|
metadata: Optional[Dict[str, Any]] = None,
|
|
agent: Optional[str] = None,
|
|
) -> None:
|
|
metadata = metadata or {}
|
|
if agent:
|
|
metadata["agent"] = agent
|
|
|
|
self.storage.save(value, metadata)
|
|
|
|
def search(
|
|
self,
|
|
query: str,
|
|
limit: int = 3,
|
|
score_threshold: float = 0.35,
|
|
) -> List[Any]:
|
|
return self.storage.search(
|
|
query=query, limit=limit, score_threshold=score_threshold
|
|
)
|
|
|
|
def set_crew(self, crew: Any) -> Self:
|
|
self.crew = crew
|
|
return self
|