`Class InMemoryArtifactService`

java.lang.Object
com.google.adk.artifacts.InMemoryArtifactService
All Implemented Interfaces:
BaseArtifactService

public final class InMemoryArtifactService extends Object implements BaseArtifactService
这是一个基于内存(in-memory)的实现方案…… BaseArtifactService.
  • 构造函数详细信息

    • InMemoryArtifactService

      public InMemoryArtifactService()
  • 方法详细信息(Method Details)

    • saveArtifact

      public io.reactivex.rxjava3.core.Single<Integer> saveArtifact(String appName, String userId, String sessionId, String filename, com.google.genai.types.Part artifact)
      将某个“工件”(artifact)保存在内存中,并为其分配一个新的版本号。
      Specified by:
      saveArtifact in interface BaseArtifactService
      Parameters:
      appName - the app name
      userId - the user ID
      sessionId - the session ID
      filename - the filename
      artifact - the artifact
      Returns:
      Single with assigned version number.
    • loadArtifact

      public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String appName, String userId, String sessionId, String filename, @Nullable Integer version)
      可以根据版本号或最新版本来加载相应的工件(artifact)。
      Specified by:
      loadArtifact in interface BaseArtifactService
      Returns:
      Maybe with the artifact, or empty if not found.
    • listArtifactKeys

      public io.reactivex.rxjava3.core.Single<ListArtifactsResponse> listArtifactKeys(String appName, String userId, String sessionId)
      列出该会话中存储的所有工件的文件名。
      Specified by:
      listArtifactKeys in interface BaseArtifactService
      Parameters:
      appName - the app name
      userId - the user ID
      sessionId - the session ID
      Returns:
      Single with list of artifact filenames.
    • deleteArtifact

      public io.reactivex.rxjava3.core.Completable deleteArtifact(String appName, String userId, String sessionId, String filename)
      删除给定资源的所有版本。
      Specified by:
      deleteArtifact in interface BaseArtifactService
      Parameters:
      appName - the app name
      userId - the user ID
      sessionId - the session ID
      filename - the filename
      Returns:
      Completable indicating completion.
    • listVersions

      public io.reactivex.rxjava3.core.Single<com.google.common.collect.ImmutableList<Integer>> listVersions(String appName, String userId, String sessionId, String filename)
      列出指定工件的所有版本。
      Specified by:
      listVersions in interface BaseArtifactService
      Parameters:
      appName - the app name
      userId - the user ID
      sessionId - the session ID
      filename - the artifact filename
      Returns:
      Single with list of version numbers.
    • saveAndReloadArtifact

      public io.reactivex.rxjava3.core.Single<com.google.genai.types.Part> saveAndReloadArtifact(String appName, String userId, String sessionId, String filename, com.google.genai.types.Part artifact)
      描述内容复制自接口文档: BaseArtifactService
      保存一个“artefact”(即某种数据或对象),并在文件数据(fileData)可用时将其一并返回。

      为了提高效率,实现类应该覆盖这个默认方法;因为默认方法会执行两次 I/O 操作(先保存数据,再读取数据)。

      Specified by:
      saveAndReloadArtifact in interface BaseArtifactService
      Parameters:
      appName - the app name
      userId - the user ID
      sessionId - the session ID
      filename - the filename
      artifact - the artifact to save
      Returns:
      the saved artifact with fileData if available.