Mem0

Mem0

AgentOps로 Mem0 메모리 작업을 추적하고 모니터링하는 방법을 소개해요. Mem0를 추적해야 하는 이유부터 설치, 메모리 작업 추적 예제까지 알아볼게요.

출처: 문서

본문

Mem0는 AI 애플리케이션을 위한 스마트 메모리 레이어를 제공하며, 사용자 선호도, 대화 기록, 세션 전반의 컨텍스트를 기억해 개인화된 상호작용을 가능하게 해줍니다.

Mem0를 AgentOps로 추적해야 하는 이유 (Why Track Mem0 with AgentOps?)

메모리 기반 AI 애플리케이션을 구축할 때 다음에 대한 가시성이 필요해요.

  • Memory Operations: 메모리가 생성, 업데이트, 검색되는 시점 추적
  • Search Performance: AI가 관련 메모리를 얼마나 효과적으로 찾는지 모니터링
  • Memory Usage Patterns: 어떤 정보가 저장되고 접근되는지 이해
  • Error Tracking: 메모리 저장이나 검색에서의 문제 식별
  • Cost Analysis: Mem0와 LLM 프로바이더 양쪽에 대한 API 호출 추적

AgentOps는 Mem0을 자동으로 계측해 메모리 작업에 대한 완전한 관측성을 제공합니다.

설치 (Installation)

```bash pip theme={null} pip install agentops mem0ai python-dotenv ```
poetry add agentops mem0ai python-dotenv
uv pip install agentops mem0ai python-dotenv

환경 설정 (Environment Configuration)

환경 변수를 로드하고 API 키를 설정하세요. MEM0_API_KEY는 클라우드 기반 MemoryClient를 사용하는 경우에만 필요합니다.

```bash Export to CLI theme={null} export AGENTOPS_API_KEY="your_agentops_api_key_here" export OPENAI_API_KEY="your_openai_api_key_here" ```
AGENTOPS_API_KEY="your_agentops_api_key_here"
OPENAI_API_KEY="your_openai_api_key_here"

메모리 작업 추적 (Tracking Memory Operations)

```python Local Memory theme={null} import agentops from mem0 import Memory

agentops.start_trace("user_preference_learning",tags=["mem0_memory_example"])

try: # Initialize Memory - AgentOps tracks the configuration memory = Memory.from_config({ "llm": { "provider": "openai", "config": { "model": "gpt-4o-mini", "temperature": 0.1 } } })

  # Add memories - AgentOps tracks each operation
  memory.add(
      "I prefer morning meetings and dark roast coffee",
      user_id="user_123",
      metadata={"category": "preferences"}
  )

  # Search memories - AgentOps tracks search queries and results
  results = memory.search(
      "What are the user's meeting preferences?",
      user_id="user_123"
  )

  # End trace - AgentOps aggregates all operations
  agentops.end_trace(end_state="success")

except Exception as e: agentops.end_trace(end_state="error")


```python Cloud Memory theme={null}
import agentops
from mem0 import MemoryClient

# Start trace for cloud operations
agentops.start_trace("cloud_memory_sync",tags=["mem0_memoryclient_example"])

try:
    # Initialize MemoryClient - AgentOps tracks API authentication
    client = MemoryClient(api_key="your_mem0_api_key")

    # Batch add memories - AgentOps tracks bulk operations
    messages = [
        {"role": "user", "content": "I work in software engineering"},
        {"role": "user", "content": "I prefer Python over Java"},
    ]

    client.add(messages, user_id="user_123")

    # Search with filters - AgentOps tracks complex queries
    filters = {"AND": [{"user_id": "user_123"}]}
    results = client.search(
        query="What programming languages does the user know?",
        filters=filters,
        version="v2"
    )

    # End trace - AgentOps aggregates all operations
    agentops.end_trace(end_state="success")

except Exception as e:
    agentops.end_trace(end_state="error")

AgentOps에서 볼 수 있는 것 (What You'll See in AgentOps)

Mem0을 AgentOps와 함께 사용하면 대시보드에 다음이 표시됩니다.

  1. Memory Operation Timeline: 모든 메모리 작업의 시각적 흐름
  2. Search Analytics: 쿼리 패턴과 검색 효과성
  3. Memory Growth: 사용자 메모리가 시간에 따라 축적되는 방식 추적
  4. Performance Metrics: 추가, 검색, 조회의 지연 시간
  5. Error Tracking: 전체 오류 컨텍스트가 포함된 실패 작업
  6. Cost Attribution: 메모리 추출과 검색의 토큰 사용량

예제 (Examples)

AgentOps 추적을 사용한 메모리 저장과 검색을 보여주는 간단한 예제 async/await 패턴으로 동시 메모리 작업 추적하기

더 알아보기 (Learn more)