Class Mem0Client

java.lang.Object
io.agentscope.core.memory.mem0.Mem0Client

public class Mem0Client extends Object
HTTP client for interacting with the Mem0 API.

Supports both Platform Mem0 and self-hosted Mem0 deployments:

  • Platform Mem0: Uses endpoints /v1/memories/ and /v2/memories/search/
  • Self-hosted Mem0: Uses endpoints /memories and /memories/search

By default, the client uses Platform Mem0 endpoints. To use self-hosted Mem0, specify "self-hosted" as the apiType parameter.

  • Constructor Details

    • Mem0Client

      public Mem0Client(String apiBaseUrl, String apiKey)
      Creates a new Mem0Client with specified configuration (defaults to Platform Mem0).
      Parameters:
      apiBaseUrl - The base URL of the Mem0 API (e.g., "http://localhost:8000")
      apiKey - The API key for authentication (can be null for local deployments without authentication)
    • Mem0Client

      public Mem0Client(String apiBaseUrl, String apiKey, Duration timeout)
      Creates a new Mem0Client with custom timeout (defaults to Platform Mem0).
      Parameters:
      apiBaseUrl - The base URL of the Mem0 API
      apiKey - The API key for authentication (can be null for local deployments without authentication)
      timeout - HTTP request timeout duration
    • Mem0Client

      public Mem0Client(String apiBaseUrl, String apiKey, Mem0ApiType apiType, Duration timeout)
      Creates a new Mem0Client with API type specification.
      Parameters:
      apiBaseUrl - The base URL of the Mem0 API
      apiKey - The API key for authentication (can be null for local deployments without authentication)
      apiType - API type enum
      timeout - HTTP request timeout duration
  • Method Details

    • add

      public reactor.core.publisher.Mono<Mem0AddResponse> add(Mem0AddRequest request)
      Adds memories to Mem0 by sending messages for processing.

      This method calls the POST /v1/memories endpoint. Mem0 will process the messages and extract memorable information using LLM inference (unless infer is set to false in the request).

      The operation is performed asynchronously on the bounded elastic scheduler to avoid blocking the caller thread.

      Parameters:
      request - The add request containing messages and metadata
      Returns:
      A Mono emitting the response with extracted memories
    • search

      public reactor.core.publisher.Mono<Mem0SearchResponse> search(Mem0SearchRequest request)
      Searches memories in Mem0 using semantic similarity.

      This method calls the POST /v2/memories/search/ endpoint to find memories relevant to the query string. Results are ordered by relevance score (highest first).

      Automatically compatible with two Mem0 API response formats:

      • format v1.1 — response is a JSON object with a results field (e.g. {"results": [...]}), deserialized directly into Mem0SearchResponse.
      • format v1.0 — response is a direct JSON array (e.g. [...]), parsed as a list of results and wrapped into a Mem0SearchResponse.

      The metadata filters (agent_id, user_id, run_id) in the request ensure that only memories from the specified context are returned.

      Parameters:
      request - The search request containing query and filters
      Returns:
      A Mono emitting the search response with relevant memories
    • shutdown

      public void shutdown()
      Shuts down the HTTP client and releases resources.

      This method should be called when the client is no longer needed. After calling this method, the client should not be used for further requests.