Skip to content

storage

__all__ = ['BaseArtifactStorage', 'TextArtifactStorage', 'BlobArtifactStorage'] module-attribute

BaseArtifactStorage

Bases: ABC

Source code in griptape/memory/task/storage/base_artifact_storage.py
@define
class BaseArtifactStorage(ABC):
    @abstractmethod
    def store_artifact(self, namespace: str, artifact: BaseArtifact) -> None: ...

    @abstractmethod
    def load_artifacts(self, namespace: str) -> ListArtifact: ...

    @abstractmethod
    def can_store(self, artifact: BaseArtifact) -> bool: ...

can_store(artifact) abstractmethod

Source code in griptape/memory/task/storage/base_artifact_storage.py
@abstractmethod
def can_store(self, artifact: BaseArtifact) -> bool: ...

load_artifacts(namespace) abstractmethod

Source code in griptape/memory/task/storage/base_artifact_storage.py
@abstractmethod
def load_artifacts(self, namespace: str) -> ListArtifact: ...

store_artifact(namespace, artifact) abstractmethod

Source code in griptape/memory/task/storage/base_artifact_storage.py
@abstractmethod
def store_artifact(self, namespace: str, artifact: BaseArtifact) -> None: ...

BlobArtifactStorage

Bases: BaseArtifactStorage

Source code in griptape/memory/task/storage/blob_artifact_storage.py
@define
class BlobArtifactStorage(BaseArtifactStorage):
    blobs: dict[str, list[BlobArtifact]] = field(factory=dict, kw_only=True)

    def can_store(self, artifact: BaseArtifact) -> bool:
        return isinstance(artifact, BlobArtifact)

    def store_artifact(self, namespace: str, artifact: BaseArtifact) -> None:
        if isinstance(artifact, BlobArtifact):
            if namespace not in self.blobs:
                self.blobs[namespace] = []

            self.blobs[namespace].append(artifact)
        else:
            raise ValueError("Artifact must be of instance BlobArtifact")

    def load_artifacts(self, namespace: str) -> ListArtifact:
        return ListArtifact(next((blobs for key, blobs in self.blobs.items() if key == namespace), []))

blobs: dict[str, list[BlobArtifact]] = field(factory=dict, kw_only=True) class-attribute instance-attribute

can_store(artifact)

Source code in griptape/memory/task/storage/blob_artifact_storage.py
def can_store(self, artifact: BaseArtifact) -> bool:
    return isinstance(artifact, BlobArtifact)

load_artifacts(namespace)

Source code in griptape/memory/task/storage/blob_artifact_storage.py
def load_artifacts(self, namespace: str) -> ListArtifact:
    return ListArtifact(next((blobs for key, blobs in self.blobs.items() if key == namespace), []))

store_artifact(namespace, artifact)

Source code in griptape/memory/task/storage/blob_artifact_storage.py
def store_artifact(self, namespace: str, artifact: BaseArtifact) -> None:
    if isinstance(artifact, BlobArtifact):
        if namespace not in self.blobs:
            self.blobs[namespace] = []

        self.blobs[namespace].append(artifact)
    else:
        raise ValueError("Artifact must be of instance BlobArtifact")

TextArtifactStorage

Bases: BaseArtifactStorage

Source code in griptape/memory/task/storage/text_artifact_storage.py
@define(kw_only=True)
class TextArtifactStorage(BaseArtifactStorage):
    vector_store_driver: BaseVectorStoreDriver = field(
        default=Factory(lambda: Defaults.drivers_config.vector_store_driver)
    )

    def can_store(self, artifact: BaseArtifact) -> bool:
        return isinstance(artifact, TextArtifact)

    def store_artifact(self, namespace: str, artifact: BaseArtifact) -> None:
        if isinstance(artifact, TextArtifact):
            self.vector_store_driver.upsert_text_artifact(artifact, namespace=namespace)
        else:
            raise ValueError("Artifact must be of instance TextArtifact")

    def load_artifacts(self, namespace: str) -> ListArtifact:
        return self.vector_store_driver.load_artifacts(namespace=namespace)

vector_store_driver: BaseVectorStoreDriver = field(default=Factory(lambda: Defaults.drivers_config.vector_store_driver)) class-attribute instance-attribute

can_store(artifact)

Source code in griptape/memory/task/storage/text_artifact_storage.py
def can_store(self, artifact: BaseArtifact) -> bool:
    return isinstance(artifact, TextArtifact)

load_artifacts(namespace)

Source code in griptape/memory/task/storage/text_artifact_storage.py
def load_artifacts(self, namespace: str) -> ListArtifact:
    return self.vector_store_driver.load_artifacts(namespace=namespace)

store_artifact(namespace, artifact)

Source code in griptape/memory/task/storage/text_artifact_storage.py
def store_artifact(self, namespace: str, artifact: BaseArtifact) -> None:
    if isinstance(artifact, TextArtifact):
        self.vector_store_driver.upsert_text_artifact(artifact, namespace=namespace)
    else:
        raise ValueError("Artifact must be of instance TextArtifact")