Memory Bank を設定する

Vertex AI Agent Engine Memory Bank を使用するには、Vertex AI Agent Engine インスタンスが必要です。このページでは、環境を設定して Vertex AI Agent Engine インスタンスを作成する方法について説明します。

ご利用にあたって

Vertex AI Agent Engine Memory Bank を使用する前に、環境を設定する必要があります。

Google Cloud プロジェクトを設定する

すべてのプロジェクトは、プロジェクト番号またはプロジェクト ID によって識別できます。PROJECT_NUMBER はプロジェクトの作成時に自動的に作成されますが、PROJECT_ID はプロジェクトの作成者が作成します。プロジェクトを設定するには:

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. 必要なロールを取得する

    Vertex AI Agent Engine の使用に必要な権限を取得するには、プロジェクトに対する Vertex AI ユーザー roles/aiplatform.user)IAM ロールの付与を管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

    必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

    Google Kubernetes Engine または Cloud Run にデプロイされたエージェントから Memory Bank にリクエストを送信する場合は、サービス アカウントに必要な権限があることを確認してください。Reasoning Engine サービス エージェントには、記憶の読み取りと書き込みに必要な権限がすでに付与されているため、Agent Engine Runtime からのアウトバウンド リクエストには、Memory Bank にアクセスする権限がすでに付与されているはずです。

    ライブラリをインストールする

    このセクションでは、Python 開発環境を設定しているか、Python 開発環境(Colab など)を含むランタイムを使用していることを前提としています。

    Vertex AI SDK をインストールします。

      pip install google-cloud-aiplatform>=1.111.0

    認証

    認証手順は、Vertex AI をエクスプレス モードで使用しているかどうかによって異なります。

    • エクスプレス モードで Vertex AI を使用していない場合は、Vertex AI に対する認証の手順に沿って操作します。

    • エクスプレス モードで Vertex AI を使用している場合は、環境に API キーを設定して認証を設定します。

        os.environ["API_KEY"] = "API_KEY"
      

    Vertex AI SDK クライアントを設定する

    Vertex AI SDK クライアントは、次のコードを実行して設定します。

    import vertexai
    
    client = vertexai.Client(
        project="PROJECT_ID",
        location="LOCATION",
    )
    

    ここで

    Agent Engine インスタンスを作成または更新する

    Memory Bank を使用するには、まず Agent Engine インスタンスが必要です。まだインスタンスがない場合は、デフォルト構成を使用して作成できます。

    agent_engine = client.agent_engines.create()
    

    新規または既存の Memory Bank インスタンスの動作の構成をカスタマイズする場合は、Memory Bank 用に Agent Engine インスタンスを構成するをご覧ください。たとえば、Memory Bank が永続化するのに意味があると考える情報を指定できます。

    Agent Engine インスタンスは、Vertex AI Agent Engine セッションと Memory Bank をすぐにサポートします。インスタンスの作成時にエージェントはデプロイされません。Vertex AI Agent Engine Runtime を使用するには、Agent Engine インスタンスの作成または更新時にデプロイするエージェントを指定する必要があります。

    Agent Engine インスタンスを作成したら、インスタンスの名前を使用して記憶の読み取りまたは書き込みを行えます。例:

    # Generate memories using your Memory Bank instance.
    client.agent_engines.memories.generate(
      # `name` should have the format `projects/.../locations/.../reasoningEngines/...`.
      name=agent_engine.api_resource.name,
      ...
    )
    

    Vertex AI Agent Engine ランタイムで使用する

    Memory Bank は任意のランタイムで使用できますが、Agent Engine Runtime と組み合わせて使用して、デプロイされたエージェントから記憶を読み書きすることも可能です。

    Vertex AI Agent Engine ランタイムで Memory Bank を使用してエージェントをデプロイするには、まず Agent Engine ランタイムの環境を設定します。次に、記憶統合機能を備えた Agent Engine ランタイムにデプロイするエージェントを準備します。デプロイされたエージェントは、必要に応じて記憶の読み取りと書き込みを行う必要があります。

    AdkApp

    Agent Engine Agent Development Kit テンプレートを使用している場合、エージェントは Agent Engine Runtime にデプロイされるときにデフォルトで VertexAiMemoryBankService を使用します。つまり、ADK Memory ツールは Memory Bank から記憶を読み取ります。

    from google.adk.agents import Agent
    from vertexai.preview.reasoning_engines import AdkApp
    
    # Develop an agent using the ADK template.
    agent = Agent(...)
    
    adk_app = AdkApp(
          agent=adk_agent,
          ...
    )
    
    # Deploy the agent to Agent Engine Runtime.
    agent_engine = client.agent_engines.create(
          agent_engine=adk_app,
          config={
                "staging_bucket": "STAGING_BUCKET",
                "requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
                # Optional.
                **context_spec
          }
    )
    
    # Update an existing Agent Engine to add or modify the Runtime.
    agent_engine = client.agent_engines.update(
          name=agent_engine.api_resource.name,
          agent=adk_app,
          config={
                "staging_bucket": "STAGING_BUCKET",
                "requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
                # Optional.
                **context_spec
          }
    )
    

    次のように置き換えます。

    • STAGING_BUCKET: Agent Engine Runtime のステージングに使用する Cloud Storage バケット。

    ADK での Memory Bank の使用に関する詳細は、Agent Development Kit のクイックスタートをご覧ください。

    カスタム エージェント

    Memory Bank は、Agent Engine ランタイムにデプロイされたカスタム エージェントで使用できます。この場合、エージェントは Memory Bank への呼び出しをオーケストレートして、記憶生成記憶取得の呼び出しをトリガーする必要があります。

    Vertex AI Agent Engine ランタイムにデプロイされたアプリケーションは、環境変数 GOOGLE_CLOUD_PROJECTGOOGLE_CLOUD_LOCATIONGOOGLE_CLOUD_AGENT_ENGINE_ID を読み取って、環境から Agent Engine の名前を推測できます。

    project = os.environ.get("GOOGLE_CLOUD_PROJECT")
    location = os.environ.get("GOOGLE_CLOUD_LOCATION")
    agent_engine_id = os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID")
    
    agent_engine_name = f"projects/{project}/locations/{location}/reasoningEngines/{agent_engine_id}"
    

    Vertex AI Agent Engine Runtime でエージェントのデフォルトのサービス エージェントを使用している場合、エージェントにはすでに記憶の読み取りと書き込みの権限が付与されています。カスタム サービス アカウントを使用している場合は、サービス アカウントに記憶の読み取りと書き込みの権限を付与する必要があります。必要な権限は、エージェントが実行できるオペレーションによって異なります。エージェントが記憶を取得して生成するだけでよい場合は、aiplatform.memories.generateaiplatform.memories.retrieve で十分です。

    他のすべてのランタイムで使用する

    Cloud Run や Colab などの別の環境で Memory Bank を使用する場合は、エージェントを指定せずに Agent Engine を作成します。ランタイムなしでの新しい Agent Engine の作成には、数秒しかかかりません。構成を指定しない場合、記憶の生成と取得を管理するためのデフォルト設定で Memory Bank が作成されます。

    agent_engine = client.agent_engines.create()
    

    動作を構成する場合は、Memory Bank の構成を指定します。

    作成

    agent_engine = client.agent_engines.create(
      config={
        "context_spec": {
          "memory_bank_config": ...
        }
      }
    )
    

    更新

    Memory Bank の構成を変更する場合は、Vertex AI Agent Engine インスタンスを更新できます。

    agent_engine = client.agent_engines.update(
      # You can access the name using `agent_engine.api_resource.name` for an AgentEngine object.
      name="AGENT_ENGINE_NAME",
      config={
        "context_spec": {
          "memory_bank_config": ...
        }
      }
    )
    

    次のように置き換えます。

    Memory Bank は、記憶の読み取りと書き込みの権限を持つ環境で使用できます。たとえば、Cloud Run で Memory Bank を使用するには、記憶の読み取りと書き込みを行う権限を Cloud Run サービス ID に付与します。必要な権限は、エージェントが実行できるオペレーションによって異なります。エージェントが記憶を取得して生成するだけでよい場合は、aiplatform.memories.generateaiplatform.memories.retrieve で十分です。

    Memory Bank 用に Agent Engine インスタンスを構成する

    必要に応じて、Memory Bank を構成して、記憶の生成と管理の方法をカスタマイズできます。構成が指定されていない場合、Memory Bank は各構成タイプのデフォルト設定を使用します。

    Memory Bank の構成は、Agent Engine インスタンスの作成時または更新時に設定されます。

    client.agent_engines.create(
          ...,
          config={
                "context_spec": {
                      "memory_bank_config": memory_bank_config
                }
          }
    )
    
    # Alternatively, update an existing Agent Engine's Memory Bank config.
    agent_engine = client.agent_engines.update(
          name=agent_engine.api_resource.name,
          config={
              "context_spec": {
                    "memory_bank_config": memory_bank_config
              }
          }
    )
    

    インスタンスに対して次の設定を構成できます。

    • カスタマイズ構成: ソースデータから記憶を抽出する方法を構成します。
    • 類似性検索の構成: 類似性検索に使用するエンベディング モデルを構成します。デフォルトは text-embedding-005 です。
    • 生成構成: 記憶の生成に使用する LLM を構成します。デフォルトは gemini-2.5-flash です。
    • TTL の構成: 作成または更新された記憶の TTL を自動的に設定する方法を構成します。デフォルトでは TTL は設定されません。

    カスタマイズ構成

    ソースデータから記憶を抽出する方法をカスタマイズする場合は、Agent Engine インスタンスの設定時に記憶抽出の動作を構成できます。カスタマイズに使用できるレバーは 2 つあります。

    Memory Bank の抽出動作のカスタマイズは、伝える(Telling)と示す(Showing)の 2 つのステップで行うことができます。メモリトピックは、Memory Bank に保持する情報を伝えます。Few-shot は、特定のメモリにつながる情報の種類を Memory Bank に示し、ユーザーが理解してほしいパターン、ニュアンス、言い回しを学習するのに役立ちます。

    必要に応じて、スコープレベルごとに異なる動作を構成できます。たとえば、セッション レベルの記憶にとって意味のあるトピックが、ユーザーレベルの記憶(複数のセッションにわたる)にとって意味のあるトピックとは限りません。特定の記憶のサブセットの動作を構成するには、カスタマイズ構成のスコープキーを設定します。これらのスコープキーを含む GenerateMemories リクエストのみが、その構成を使用します。scope_key フィールドを省略すると、デフォルトの動作(スコープキーのすべてのセットに適用)を構成することもできます。この構成は、別のカスタマイズ構成のスコープキーと完全に一致する構成がないすべてのリクエストに適用されます。

    たとえば、user_level_config は、スコープキー user_id を正確に使用する GenerateMemories リクエスト(追加のキーがない scope={"user_id": "123"} など)にのみ適用されます。default_config は、他のリクエストに適用されます。

    辞書

    
    user_level_config = {
      "scope_keys": ["user_id"],
      "memory_topics": [...],
      "generate_memories_examples": [...]
    }
    
    default_config = {
      "memory_topics": [...],
      "generate_memories_examples": [...]
    }
    
    memory_bank_config = {
      "customization_configs": [
        user_level_config,
        default_config
      ]
    }
    

    クラスベース

    from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
    
    user_level_config = CustomizationConfig(
      scope_keys=["user_id"],
      memory_topics=[...],
      generate_memories_examples=[...]
    )
    

    記憶のトピックの構成

    「記憶のトピック」は、Memory Bank が有意義と見なし、生成された記憶として保持すべきと判断した情報を特定します。Memory Bank は、次の 2 種類の記憶のトピックをサポートしています。

    • 管理対象トピック: ラベルと手順は Memory Bank によって定義されます。指定する必要があるのは、マネージド トピックの名前だけです。次に例を示します。

      辞書

      memory_topic = {
        "managed_memory_topic": {
          "managed_topic_enum": "USER_PERSONAL_INFO"
        }
      }
      

      クラスベース

      from vertexai.types import ManagedTopicEnum
      from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
      from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
      
      memory_topic = MemoryTopic(
          managed_memory_topic=ManagedMemoryTopic(
              managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO
          )
      )
      

      Memory Bank では、次のマネージド トピックがサポートされています。

      • 個人情報USER_PERSONAL_INFO): ユーザーに関する重要な個人情報(名前、関係、趣味、重要な日付など)。たとえば、「私は Google で働いています」、「結婚記念日は 12 月 31 日です」などです。
      • ユーザーの好みUSER_PREFERENCES): 明示的または暗黙的な好み、嫌いなもの、好みのスタイル、パターン。たとえば、「真ん中の席がいいです」と入力します。
      • 会話の重要なイベントとタスクの結果KEY_CONVERSATION_DETAILS): 会話内の重要なマイルストーンまたは結論。たとえば、「JFK と SFO 間の往復航空券を予約しました。2025 年 6 月 1 日に出発し、2025 年 6 月 7 日に帰ります。」
      • 明示的な記憶 / 忘却の指示EXPLICIT_INSTRUCTIONS): エージェントに記憶または忘却を明示的に指示する情報。たとえば、ユーザーが「私は主に Python を使用していることを覚えておいて」と言うと、Memory Bank は「私は主に Python を使用している」という記憶を生成します。
    • カスタム トピック: Memory Bank インスタンスの設定時に、ラベルと手順を定義します。これらは、Memory Bank の抽出ステップのプロンプトで使用されます。次に例を示します。

      辞書

      memory_topic = {
        "custom_memory_topic": {
          "label": "business_feedback",
          "description": """Specific user feedback about their experience at
      the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
      staff friendliness, service speed, cleanliness, and any suggestions for
      improvement."""
        }
      }
      

      クラスベース

      from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
      from vertexai.types import MemoryBankCustomizationConfigMemoryTopicCustomMemoryTopic as CustomMemoryTopic
      
      memory_topic = MemoryTopic(
        custom_memory_topic=CustomMemoryTopic(
          label="business_feedback",
          description="""Specific user feedback about their experience at
      the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
      staff friendliness, service speed, cleanliness, and any suggestions for
      improvement."""
        )
      )
      

      カスタム トピックを使用する場合は、会話から記憶を抽出する方法を示す少量のサンプルも指定することをおすすめします。

    カスタマイズでは、記憶のトピックを自由に組み合わせることが可能です。たとえば、使用可能な記憶のマネージド トピックのサブセットを使用できます。

    辞書

    customization_config = {
      "memory_topics": [
        { "managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" } },
        { "managed_memory_topic": { "managed_topic_enum": "USER_PREFERENCES" } }
      ]
    }
    

    クラスベース

    from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
    from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
    from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
    from vertexai.types import ManagedTopicEnum
    
    customization_config = CustomizationConfig(
      memory_topics=[
          MemoryTopic(
              managed_memory_topic=ManagedMemoryTopic(
                  managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)
          ),
          MemoryTopic(
              managed_memory_topic=ManagedMemoryTopic(
                  managed_topic_enum=ManagedTopicEnum.USER_PREFERENCES)
          ),
      ]
    )
    

    マネージド トピックとカスタム トピックを組み合わせて使用することや、カスタム トピックのみを使用することが可能です。

    辞書

    customization_config = {
      "memory_topics": [
        { "managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" } },
        {
          "custom_memory_topic": {
            "label": "business_feedback",
            "description": """Specific user feedback about their experience at
    the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
    staff friendliness, service speed, cleanliness, and any suggestions for
    improvement."""
            }
        }
      ]
    }
    

    クラスベース

    from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
    from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
    from vertexai.types import MemoryBankCustomizationConfigMemoryTopicCustomMemoryTopic as CustomMemoryTopic
    from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
    from vertexai.types import ManagedTopicEnum
    
    customization_config = CustomizationConfig(
      memory_topics=[
          MemoryTopic(
              managed_memory_topic=ManagedMemoryTopic(
                  managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)
          ),
          MemoryTopic(
              custom_memory_topic=CustomMemoryTopic(
                  label="business_feedback",
                  description="""Specific user feedback about their experience at
    the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
    staff friendliness, service speed, cleanliness, and any suggestions for
    improvement."""
              )
        )
      ]
    )
    

    少数ショットの例

    少数ショットの例を使用すると、Memory Bank に期待される記憶の抽出動作を示すことが可能です。たとえば、入力会話のサンプルと、その会話から抽出されることが想定される記憶を指定できます。

    Memory Bank が意図した動作を学習できるように、カスタム トピックで常に少数ショットを使用することをおすすめします。マネージド トピックを使用する場合、Memory Bank が各トピックの例を定義するため、少数ショットは省略できます。空の generated_memories リストを指定して、記憶が生成されない会話を示します。

    たとえば、お客様のメッセージからビジネスに関するフィードバックを抽出する方法を示す少数ショットの例を指定できます。

    辞書

    example = {
        "conversationSource": {
          "events": [
            {
              "content": {
                "role": "model",
                "parts": [{ "text": "Welcome back to The Daily Grind! We'd love to hear your feedback on your visit." }] }
            },
            {
              "content": {
                "role": "user",
                "parts": [{ "text": "Hey. The drip coffee was a bit lukewarm today, which was a bummer. Also, the music was way too loud, I could barely hear my friend." }] }
            }
          ]
        },
        "generatedMemories": [
          {
            "fact": "The user reported that the drip coffee was lukewarm."
          },
          {
            "fact": "The user felt the music in the shop was too loud."
          }
        ]
    }
    

    クラスベース

    from google.genai.types import Content, Part
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExample as GenerateMemoriesExample
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSource as ConversationSource
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSourceEvent as ConversationSourceEvent
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleGeneratedMemory as ExampleGeneratedMemory
    
    example = GenerateMemoriesExample(
        conversation_source=ConversationSource(
            events=[
                ConversationSourceEvent(
                    content=Content(
                        role="model",
                        parts=[Part(text="Welcome back to The Daily Grind! We'd love to hear your feedback on your visit.")]
                    )
                ),
                ConversationSourceEvent(
                    content=Content(
                        role="user",
                        parts=[Part(text= "Hey. The drip coffee was a bit lukewarm today, which was a bummer. Also, the music was way too loud, I could barely hear my friend.")]
                    )
                )
            ]
        ),
        generated_memories=[
            ExampleGeneratedMemory(
                fact="The user reported that the drip coffee was lukewarm."
            ),
            ExampleGeneratedMemory(
                fact="The user felt the music in the shop was too loud."
            )
        ]
    )
    

    記憶が生成されない会話の例を示すこともできます。その場合は、期待される出力(generated_memories)に空のリストを指定します。

    辞書

    example = {
        "conversationSource": {
            "events": [
              {
                  "content": {
                      "role": "model",
                      "parts": [{ "text": "Good morning! What can I get for you at The Daily Grind?" }] }
              },
              {
                  "content": {
                      "role": "user",
                      "parts": [{ "text": "Thanks for the coffee." }] }
              }
            ]
        },
        "generatedMemories": []
    }
    

    クラスベース

    from google.genai.types import Content, Part
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExample as GenerateMemoriesExample
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSource as ConversationSource
    from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSourceEvent as ConversationSourceEvent
    
    example = GenerateMemoriesExample(
        conversation_source=ConversationSource(
            events=[
                ConversationSourceEvent(
                    content=Content(
                        role="model",
                        parts=[Part(text="Welcome back to The Daily Grind! We'd love to hear your feedback on your visit.")]
                    )
                ),
                ConversationSourceEvent(
                    content=Content(
                        role="user",
                        parts=[Part(text= "Thanks for the coffee!")]
                    )
                )
            ]
        ),
        generated_memories=[]
    )
    

    類似性検索の構成

    類似性検索構成は、類似性検索用にインスタンスで使用されるエンベディング モデルを制御します。類似性検索は、統合の候補となる記憶を特定するためと、類似性検索ベースの記憶取得のために使用されます。この構成が指定されていない場合、Memory Bank はデフォルトのモデルとして text-embedding-005 を使用します。

    ユーザーの会話が英語以外の言語で行われることが予想される場合は、gemini-embedding-001text-multilingual-embedding-002 などの多言語をサポートするモデルを使用して、検索の品質を向上させます。

    辞書

    memory_bank_config = {
        "similarity_search_config": {
            "embedding_model": "EMBEDDING_MODEL",
        }
    }
    

    クラスベース

    from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
    from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfig as SimilaritySearchConfig
    
    memory_bank_config = MemoryBankConfig(
        similarity_search_config=SimilaritySearchConfig(
            embedding_model="EMBEDDING_MODEL"
        )
    )
    

    次のように置き換えます。

    • EMBEDDING_MODEL: 類似性検索に使用する Google テキスト エンベディング モデル。形式は projects/{project}/locations/{location}/publishers/google/models/{model} です。

    生成構成

    生成構成は、記憶の生成に使用される LLM を制御します。これには、記憶の抽出や、新しい記憶と既存の記憶の統合が含まれます。

    Memory Bank は、デフォルトのモデルとして gemini-2.5-flash を使用します。リージョンで Gemini を利用できない場合、グローバル エンドポイントが使用されます。

    辞書

    memory_bank_config = {
          "generation_config": {
                "model": "LLM_MODEL",
          }
    }
    

    クラスベース

    from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
    from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigGenerationConfig as GenerationConfig
    
    memory_bank_config = MemoryBankConfig(
        generation_config=GenerationConfig(
          model="LLM_MODEL"
        )
    )
    
    

    次のように置き換えます。

    • LLM_MODEL: 記憶の抽出と統合に使用する Google LLM モデル(projects/{project}/locations/{location}/publishers/google/models/{model} 形式)。

    有効期間(TTL)の構成

    TTL 構成は、Memory Bank が記憶の有効期限を動的に設定する方法を制御します。有効期限が切れると、記憶は取得できなくなり、削除されます。

    構成が指定されていない場合、作成または更新された記憶の有効期限は動的に設定されないため、有効期限が手動で設定されていない限り、記憶は期限切れになりません。

    TTL 構成には次の 2 つのオプションがあります。

    • デフォルト TTL: TTL は、UpdateMemoryCreateMemoryGenerateMemories など、記憶を作成または更新するすべてのオペレーションに適用されます。

      辞書

      memory_bank_config = {
          "ttl_config": {
              "default_ttl": f"TTLs"
          }
      }
      

      クラスベース

      from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
      from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig
      
      memory_bank_config = MemoryBankConfig(
          ttl_config=TtlConfig(
              default_ttl=f"TTLs"
          )
      )
      

      次のように置き換えます。

      • TTL: TTL の期間(秒単位)。更新された記憶の場合、新たに計算された有効期限(現在 + TTL)によって、記憶の以前の有効期限が上書きされます。
    • 詳細な(オペレーション単位の)TTL: TTL は、どのオペレーションが記憶を作成または更新したかに基づいて計算されます。特定のオペレーションに設定されていない場合、オペレーションは記憶の有効期限を更新しません。

      辞書

      memory_bank_config = {
          "ttl_config": {
              "granular_ttl": {
                  "create_ttl": f"CREATE_TTLs",
                  "generate_created_ttl": f"GENERATE_CREATED_TTLs",
                  "generate_updated_ttl": f"GENERATE_UPDATED_TTLs"
              }
          }
      }
      

      クラスベース

      from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
      from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig
      from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfigGranularTtlConfig as GranularTtlConfig
      
      memory_bank_config = MemoryBankConfig(
          ttl_config=TtlConfig(
              granular_ttl_config=GranularTtlConfig(
                  create_ttl=f"CREATE_TTLs",
                  generate_created_ttl=f"GENERATE_CREATED_TTLs",
                  generate_updated_ttl=f"GENERATE_UPDATED_TTLs",
              )
          )
      )
      

      次のように置き換えます。

      • CREATE_TTL: CreateMemory を使用して作成された記憶の TTL の秒単位の期間。
      • GENERATE_CREATED_TTL: GeneratedMemories を使用して作成された記憶の TTL の秒単位の期間。
      • GENERATE_UPDATED_TTL: GeneratedMemories を使用して更新された記憶の TTL の秒単位の期間。新たに計算された有効期限(現在 + TTL)は、記憶の以前の有効期限を上書きします。

    次のステップ