The py/gaas_gpt_storage.py module provides the StorageEngine class, which serves as a Python proxy for interacting with SEMOSS storage engines. This enables Python-based Generative AI Agent Services (GAAS) or other Python scripts to perform file and directory operations on storage systems managed by the SEMOSS backend (e.g., local file system, AWS S3, Google Cloud Storage, Azure Blob Storage via RClone).
- Purpose: The
StorageEngineclass allows Python code to interact with a specific SEMOSSSTORAGEengine. It abstracts the communication details (viaServerProxy) needed to send commands to the Java backend where the actual storage operations occur. - Inheritance: It extends
gaas_server_proxy.ServerProxy, which handles the low-level communication with the SEMOSS Java backend.
The constructor __init__(self, engine_id=str, insight_id=None):
engine_id(str): Required. The ID of the target SEMOSSSTORAGEengine (anIStorageEngineinstance) configured in the Java backend.insight_id(Optional[str]): The ID of the current insight. This can be used for context, especially whenspaceparameter in methods is not defined, defaulting operations to the insight's space.- The constructor asserts that
engine_idis provided and prints an initialization message.
All methods that interact with the storage engine translate their operations into Pixel scripts, which are then executed on the SEMOSS Java backend via super().callReactor().
-
list(self, storagePath: str = None, insight_id: Optional[str] = None):- Purpose: Lists files and folders at a given
storagePathwithin the configured storage engine. - Pixel Command:
Storage("<engine_id>")|ListStoragePath(storagePath="<storagePath>"); - Output: Returns the output from the Pixel execution, typically a list of file/folder names or paths.
- Purpose: Lists files and folders at a given
-
listDetails(self, storagePath: str = None, insight_id: Optional[str] = None):- Purpose: Provides a more detailed listing of files and folders at
storagePath, including metadata like size, type, and modification date. - Pixel Command:
Storage("<engine_id>")|ListStoragePathDetails(storagePath="<storagePath>"); - Output: Returns the output from the Pixel execution, usually a list of maps where each map contains details for an asset.
- Purpose: Provides a more detailed listing of files and folders at
-
syncLocalToStorage(self, storagePath: str = None, localPath: str = None, space: Optional[str] = None, metadata: Optional[Dict] = {}, insight_id: Optional[str] = None):- Purpose: Synchronizes a local path (within SEMOSS's application context like an insight, project, or user space) to a path in the storage engine.
- Inputs:
storagePath: Target path in the storage engine.localPath: Source path in the application space.space(Optional[str]): Defines the application space forlocalPath(e.g., project ID, "user", or defaults to current insight ifNone).metadata(Optional[Dict]): Custom metadata for the synced files (if supported by the storage backend).
- Pixel Command:
Storage("<engine_id>")|SyncLocalToStorage(storagePath="<storagePath>",filePath="<localPath>",space="<space>",metadata=[<metadata_json>]); - Output: Boolean indicating success/failure.
-
syncStorageToLocal(self, storagePath: str = None, localPath: str = None, space: Optional[str] = None, insight_id: Optional[str] = None):- Purpose: Synchronizes a path from the storage engine to a local application path.
- Pixel Command:
Storage("<engine_id>")|SyncStorageToLocal(storagePath="<storagePath>",filePath="<localPath>",space="<space>"); - Output: Boolean indicating success/failure.
-
copyToLocal(self, storagePath: str = None, localPath: str = None, space: Optional[str] = None, insight_id: Optional[str] = None):- Purpose: Copies a file from the storage engine (
storagePath) to a local application folder (localPath). (Pixel command usesPullFromStorage). - Pixel Command:
Storage("<engine_id>")|PullFromStorage(storagePath="<storagePath>",filePath="<localPath>",space="<space>"); - Output: Boolean indicating success/failure.
- Purpose: Copies a file from the storage engine (
-
copyToStorage(self, storagePath: str = None, localPath: str = None, space: Optional[str] = None, metadata: Optional[Dict] = {}, insight_id: Optional[str] = None):- Purpose: Copies a local application file (
localPath) to a path in the storage engine (storagePath). (Pixel command usesPushToStorage). - Pixel Command:
Storage("<engine_id>")|PushToStorage(storagePath="<storagePath>",filePath="<localPath>",space="<space>",metadata=[<metadata_json>]); - Output: Boolean indicating success/failure.
- Purpose: Copies a local application file (
-
deleteFromStorage(self, storagePath: str = None, leaveFolderStructure: bool = False, insight_id: Optional[str] = None):- Purpose: Deletes a file or folder from the storage engine.
- Inputs:
storagePath: The path to delete in the storage engine.leaveFolderStructure(bool): IfTrue, attempts to maintain parent folder structure (behavior depends on backend implementation).
- Pixel Command:
Storage("<engine_id>")|DeleteFromStorage(storagePath="<storagePath>",leaveFolderStructure=<leaveFolderStructureStr>); - Output: Boolean indicating success/failure.
-
to_langchain_storage(self):- Purpose: Transforms the
StorageEngineinstance into a LangchainBaseStore-compatible object. This allows the SEMOSS storage engine to be used within Langchain workflows that require a key-value store interface (though the fit might be partial asBaseStoreis more generic). - Core Logic:
- Defines an inner class
SemossLangchainStoragethat inherits fromlangchain_core.stores.BaseStore. - The inner class constructor takes the
StorageEngineinstance. - It implements methods like
list,listDetails,syncLocalToStorage,syncStorageToLocal,copyToLocal,deleteFromStorageby calling the corresponding methods of the outerStorageEngineinstance. - Stubbed methods (
mdelete,mget,mset,yield_keys) are present to fulfill theBaseStoreinterface but are not implemented.
- Defines an inner class
- Outputs: An instance of
SemossLangchainStorage.
- Purpose: Transforms the
The StorageEngine Python class is a client to a specific SEMOSS IStorageEngine (e.g., LocalFileSystemStorageEngine, S3StorageEngine) running on the Java backend. All operations are translated into Pixel scripts and executed via the ServerProxy, meaning the Java engine handles the actual interaction with the file system or cloud storage service.
- Methods include
assertstatements for required parameters. - Errors from the Pixel execution or backend storage operations would typically be propagated via the
pixelReturnobject, potentially requiring the calling code to inspect this return for success or failure indicators.
# Assuming gaas_server_proxy is configured and SEMOSS backend is running
# And a STORAGE engine with ID "my_s3_storage" is configured in SEMOSS
storage_engine_id = "my_s3_storage"
insight_id_context = "some_active_insight_id" # Optional
# Initialize the StorageEngine client
storage_tool = StorageEngine(engine_id=storage_engine_id, insight_id=insight_id_context)
# List items in a storage path
try:
items = storage_tool.list(storagePath="my-folder/data/")
if items:
print("Items in storage path:", items)
except Exception as e:
print(f"Error listing items: {e}")
# Copy a local file (relative to insight/project/user space) to storage
try:
# Assuming 'my_file.txt' exists in the root of the current insight's space
success = storage_tool.copyToStorage(localPath="my_file.txt", storagePath="my-folder/destination/")
if success:
print("File copied to storage successfully.")
else:
print("File copy to storage failed.")
except Exception as e:
print(f"Error copying to storage: {e}")This StorageEngine class enables Python GAAS components to manage and interact with files across various storage backends configured within SEMOSS.