메모리 뱅크 설정

시작하기

Vertex AI Agent Engine 메모리 뱅크를 사용하기 전에 환경을 설정해야 합니다.

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에 배포된 에이전트에서 메모리 뱅크로 요청을 보내는 경우, 서비스 계정이 필요한 권한을 가지고 있는지 확인하세요. Reasoning Engine Service Agent는 메모리를 읽고 쓰는 데 필요한 권한을 이미 가지고 있으므로, Agent Engine 런타임에서 나가는 아웃바운드 요청은 이미 메모리 뱅크에 액세스할 권한을 갖습니다.

    라이브러리 설치

    이 섹션에서는 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["GOOGLE_API_KEY"] = "API_KEY"
      

    Vertex AI SDK 클라이언트 설정

    다음 코드를 실행하여 Vertex AI SDK 클라이언트를 설정합니다.

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

    각 항목의 의미는 다음과 같습니다.

    • PROJECT_ID는 프로젝트 ID입니다.
    • LOCATION은 메모리 뱅크의 지원되는 리전 중 하나입니다.

    Agent Engine 인스턴스 만들기 또는 업데이트

    Agent Engine 인스턴스가 이미 있는 경우 메모리 뱅크용 Agent Engine 인스턴스 구성으로 건너뛸 수 있습니다.

    메모리 뱅크를 시작하려면 먼저 Agent Engine 인스턴스가 필요합니다. 에이전트 엔진 인스턴스는 Vertex AI Agent Engine 세션 및 메모리 뱅크를 기본적으로 지원합니다. 인스턴스를 만들 때는 에이전트가 배포되지 않습니다. Vertex AI Agent Engine 런타임을 사용하려면 Agent Engine 인스턴스를 만들거나 업데이트할 때 배포할 에이전트를 제공해야 합니다.

    Agent Engine 인스턴스를 준비하면 해당 인스턴스 이름을 사용하여 메모리를 읽거나 쓸 수 있습니다. 예를 들면 다음과 같습니다.

    agent_engine = client.agent_engines.create()
    
    client.agent_engines.memories.generate(
      name=agent_engine.api_resource.name,
      ...
    )
    

    Vertex AI Agent Engine 런타임과 함께 사용

    메모리 뱅크는 모든 런타임에서 사용할 수 있지만, 배포된 에이전트에서 메모리를 읽고 쓰기 위해 Agent Engine 런타임과 함께 사용할 수도 있습니다.

    Vertex AI Agent Engine 런타임에서 메모리 뱅크와 함께 에이전트를 배포하려면 먼저 Agent Engine 런타임 환경을 설정하세요. 그런 다음 메모리 통합을 통해 에이전트 엔진 런타임에 배포할 에이전트를 준비합니다. 배포된 에이전트는 필요할 때 메모리를 읽고 쓰기 위한 호출을 수행해야 합니다.

    AdkApp

    Agent Engine 에이전트 개발 키트(ADK) 템플릿을 사용하는 경우 에이전트는 Agent Engine 런타임에 배포될 때 기본적으로 VertexAiMemoryBankService를 사용합니다. 즉, ADK 메모리 도구는 메모리 뱅크에서 메모리를 읽습니다.

    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 런타임을 스테이징하는 데 사용할 Cloud Storage 버킷입니다.

    ADK와 함께 메모리 뱅크를 사용하는 방법에 대한 자세한 내용은 에이전트 개발 키트 빠른 시작을 참조하세요.

    커스텀 에이전트

    Agent Engine 런타임에 배포된 커스텀 에이전트에서도 메모리 뱅크를 사용할 수 있습니다. 이 경우 에이전트는 메모리 생성메모리 검색 호출을 트리거하기 위해 메모리 뱅크 호출을 조정해야 합니다.

    Vertex AI Agent Engine 런타임에 배포된 애플리케이션은 환경에서 제공되는 환경 변수 GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION, GOOGLE_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 런타임에서 에이전트의 기본 서비스 에이전트를 사용하는 경우 에이전트는 이미 메모리를 읽고 쓸 수 있는 권한을 가지고 있습니다. 고객 서비스 계정을 사용하는 경우 서비스 계정에 메모리 읽기/쓰기 권한을 부여해야 합니다. 필요한 권한은 에이전트가 수행해야 하는 작업에 따라 달라집니다. 에이전트가 메모리 검색과 생성을 수행하기만 하면 된다면 aiplatform.memories.generateaiplatform.memories.retrieve 권한으로 충분합니다.

    다른 모든 런타임에서 사용

    Cloud Run 또는 Colab과 같은 다른 환경에서 메모리 뱅크를 사용하려면 에이전트를 제공하지 않고 Agent Engine을 만듭니다. 런타임 없이 Agent Engine을 새로 만드는 데는 몇 초밖에 걸리지 않습니다. 구성을 제공하지 않으면 메모리 뱅크는 메모리 생성과 검색을 관리하기 위한 기본 설정으로 생성됩니다.

    agent_engine = client.agent_engines.create()
    

    동작을 직접 구성하려면 메모리 뱅크 구성을 제공하세요.

    만들기

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

    업데이트

    메모리 뱅크 구성을 변경하려면 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": ...
        }
      }
    )
    

    다음을 바꿉니다.

    • AGENT_ENGINE_NAME: 에이전트 엔진의 이름입니다. projects/.../locations/.../reasoningEngines/... 형식이어야 합니다. 메모리 뱅크에서 지원되는 리전을 참조하세요.

    메모리 뱅크는 메모리를 읽고 쓸 권한이 있는 모든 환경에서 사용할 수 있습니다. 예를 들어 Cloud Run에서 메모리 뱅크를 사용하려면 Cloud Run 서비스 ID에 메모리를 읽고 쓸 수 있는 권한을 부여해야 합니다. 필요한 권한은 에이전트가 수행해야 하는 작업에 따라 달라집니다. 에이전트가 메모리 검색과 생성을 수행하기만 하면 된다면 aiplatform.memories.generateaiplatform.memories.retrieve 권한으로 충분합니다.

    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 없음입니다.

    맞춤설정 구성

    소스 데이터에서 메모리를 추출할 방법을 맞춤설정하려면 에이전트 엔진 인스턴스를 설정할 때 메모리 추출 동작을 구성하면 됩니다. 맞춤설정에 사용할 수 있는 방법은 두 가지입니다.

    • 메모리 주제 구성: 메모리 뱅크가 지속적으로 저장해야 할 의미 있는 정보 유형을 정의합니다. 이러한 메모리 주제 중 하나에 맞는 정보만 메모리 뱅크에 저장됩니다.
    • 퓨샷 예시 제공: 메모리 뱅크에 메모리 추출 시 기대되는 동작을 시연합니다.

    선택적으로, 서로 다른 범위 수준에 대해 다른 동작을 구성할 수도 있습니다. 예를 들어 세션 수준 메모리에 의미 있는 주제가 여러 세션에 걸쳐 적용되는 사용자 수준 메모리에서는 의미가 없을 수 있습니다. 특정 메모리 하위 집합의 동작을 구성하려면 맞춤설정 구성의 범위 키를 설정하세요. 해당 범위 키를 포함하는 GenerateMemories 요청에서만 그 구성이 적용됩니다. scope_key 필드를 생략하여 모든 범위 키 집합에 적용되는 기본 동작을 구성할 수 있습니다. 이 구성은 다른 맞춤설정 구성의 범위 키와 정확히 일치하는 구성이 없는 모든 요청에 적용됩니다.

    예를 들어 user_level_configuser_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": [...]
    }
    
    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_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
          )
      )
      

      메모리 뱅크에서 지원하는 관리형 주제는 다음과 같습니다.

      • 개인 정보(USER_PERSONAL_INFO): 이름, 관계, 취미, 중요한 기념일 등 사용자에 관한 중요한 개인 정보입니다. 예: '나는 Google에서 일해', '내 결혼기념일은 12월 31일이야'
      • 사용자 선호(USER_PREFERENCES): 명시적 또는 암시적인 기호, 불호, 선호 스타일이나 패턴입니다. 예: '중간 좌석이 좋아요'
      • 주요 대화 이벤트 및 작업 결과(KEY_CONVERSATION_DETAILS): 대화 중 중요한 이정표 또는 결론입니다. 예: 'JFK에서 SFO까지 왕복 항공권을 예약했어요. 2025년 6월 1일 출발하고 2025년 6월 7일에 돌아올거에요.'
      • 명시적 기억/망각 지시(EXPLICIT_INSTRUCTIONS): 사용자가 에이전트에게 명시적으로 기억하거나 잊도록 요청한 정보입니다. 예: 사용자가 '나는 주로 Python을 사용한다는 걸 기억해 줘'라고 말하면 메모리 뱅크는 '나는 주로 Python을 사용한다'와 같은 메모리를 생성합니다.
    • 커스텀 주제: 메모리 뱅크 인스턴스를 설정할 때 라벨과 지침은 사용자가 직접 정의합니다. 이 정보는 메모리 뱅크의 추출 단계 프롬프트에 사용됩니다. 예를 들면 다음과 같습니다.

      사전

      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."""
        )
      )
      

      커스텀 주제를 사용할 때는 대화에서 메모리를 추출하는 방법을 보여주는 퓨샷 예시를 함께 제공하는 것이 좋습니다.

    맞춤설정을 통해 메모리 주제를 다양하게 조합해 사용할 수 있습니다. 예를 들어 사용 가능한 관리형 메모리 주제 중 일부만 선택해 사용할 수 있습니다.

    사전

    {
      "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
    
    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)
          ),
      ]
    )
    

    관리형 주제와 커스텀 주제를 조합하여 사용하거나 커스텀 주제만 사용할 수도 있습니다.

    사전

    {
      "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
    
    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."""
              )
        )
      ]
    )
    

    퓨샷 예시

    퓨샷 예시를 사용하면 메모리 뱅크에 예상되는 메모리 추출 동작을 시연할 수 있습니다. 예를 들어 샘플 입력 대화와 그 대화에서 추출되기를 기대하는 메모리를 함께 제공할 수 있습니다.

    커스텀 주제를 사용할 때는 메모리 뱅크가 의도된 동작을 학습할 수 있도록 항상 퓨샷을 사용하는 것이 좋습니다. 관리형 주제를 사용할 때는 메모리 뱅크가 각 주제별 예시를 정의하고 있으므로, 퓨샷은 선택사항입니다. 메모리가 생성되지 않아야 하는 대화를 보여주고 싶다면, 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=[]
    )
    

    유사성 검색 구성

    유사성 검색 구성은 인스턴스에서 어떤 임베딩 모델을 유사성 검색에 사용할지를 제어합니다. 유사성 검색은 어떤 메모리를 통합 대상으로 삼을지 식별하고, 유사성 검색 기반 메모리 검색에 활용됩니다. 이 구성이 제공되지 않으면 메모리 뱅크는 text-embedding-005를 기본 모델로 사용합니다.

    사용자 대화가 영어 외의 언어로 이루어질 것으로 예상된다면, 다국어를 지원하는 모델(gemini-embedding-001 또는 text-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을 사용해 메모리를 생성할지를 제어합니다. 여기에는 메모리 추출과 새 메모리를 기존 메모리와 통합하는 작업이 포함됩니다.

    메모리 뱅크는 gemini-2.5-flash를 기본 모델로 사용합니다.

    사전

    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 구성은 메모리 뱅크가 메모리의 만료 시간을 동적으로 어떻게 설정할지를 제어합니다. 만료 시간이 지나면 메모리는 검색에 사용할 수 없으며 삭제됩니다.

    구성이 제공되지 않으면, 생성되거나 업데이트된 메모리에 만료 시간이 동적으로 설정되지 않습니다. 따라서 만료 시간이 수동으로 설정되지 않는 한 메모리는 만료되지 않습니다.

    TTL 구성에는 두 가지 옵션이 있습니다.

    • 기본 TTL: TTL은 UpdateMemory, CreateMemory, GenerateMemories를 포함하여 메모리를 생성하거나 업데이트하는 모든 작업에 적용됩니다.

      사전

      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은 어떤 연산이 메모리를 생성하거나 업데이트했는지에 따라 계산됩니다. 특정 연산에 대해 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)이 메모리의 이전 만료 시간을 덮어씁니다.

    다음 단계