Class Mem0Client
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 Summary
ConstructorsConstructorDescriptionMem0Client(String apiBaseUrl, String apiKey) Creates a new Mem0Client with specified configuration (defaults to Platform Mem0).Mem0Client(String apiBaseUrl, String apiKey, Mem0ApiType apiType, Duration timeout) Creates a new Mem0Client with API type specification.Mem0Client(String apiBaseUrl, String apiKey, Duration timeout) Creates a new Mem0Client with custom timeout (defaults to Platform Mem0). -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Mem0AddResponse>add(Mem0AddRequest request) Adds memories to Mem0 by sending messages for processing.reactor.core.publisher.Mono<Mem0SearchResponse>search(Mem0SearchRequest request) Searches memories in Mem0 using semantic similarity.voidshutdown()Shuts down the HTTP client and releases resources.
-
Constructor Details
-
Mem0Client
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
Creates a new Mem0Client with custom timeout (defaults to Platform Mem0).- Parameters:
apiBaseUrl- The base URL of the Mem0 APIapiKey- The API key for authentication (can be null for local deployments without authentication)timeout- HTTP request timeout duration
-
Mem0Client
Creates a new Mem0Client with API type specification.- Parameters:
apiBaseUrl- The base URL of the Mem0 APIapiKey- The API key for authentication (can be null for local deployments without authentication)apiType- API type enumtimeout- HTTP request timeout duration
-
-
Method Details
-
add
Adds memories to Mem0 by sending messages for processing.This method calls the
POST /v1/memoriesendpoint. Mem0 will process the messages and extract memorable information using LLM inference (unlessinferis 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
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
resultsfield (e.g.{"results": [...]}), deserialized directly intoMem0SearchResponse. - format v1.0 — response is a direct JSON array (e.g.
[...]), parsed as a list of results and wrapped into aMem0SearchResponse.
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
- format v1.1 — response is a JSON object with a
-
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.
-