Mem0.NET
1.1.2
See the version list below for details.
dotnet add package Mem0.NET --version 1.1.2
NuGet\Install-Package Mem0.NET -Version 1.1.2
<PackageReference Include="Mem0.NET" Version="1.1.2" />
<PackageVersion Include="Mem0.NET" Version="1.1.2" />
<PackageReference Include="Mem0.NET" />
paket add Mem0.NET --version 1.1.2
#r "nuget: Mem0.NET, 1.1.2"
#addin nuget:?package=Mem0.NET&version=1.1.2
#tool nuget:?package=Mem0.NET&version=1.1.2
Mem0.NET
中文文档 | English
A .NET client library for Mem0, providing easy-to-use APIs for memory management in AI applications.
Features
- 🚀 Easy Integration - Simple and intuitive API design
- 📦 Multiple .NET Versions - Supports .NET 6.0, 7.0, 8.0, and 9.0
- 🔧 Dependency Injection - Built-in support for Microsoft.Extensions.DependencyInjection
- 🌐 HTTP Client Management - Flexible HTTP client configuration
- 📝 Full API Coverage - Complete implementation of Mem0 API
- ⚡ Async/Await Support - Modern asynchronous programming patterns
Installation
Install the package via NuGet Package Manager:
dotnet add package Mem0.NET
Or via Package Manager Console:
Install-Package Mem0.NET
Quick Start
Basic Usage
using Mem0.NET;
// Initialize the client
var client = new Mem0Client("https://api.mem0.ai", "your-api-key");
// Create a memory
var createRequest = new MemoryCreateRequest
{
Messages = new List<Message>
{
new Message { Role = "user", Content = "I love playing basketball" }
},
UserId = "user123"
};
var memories = await client.CreateMemoryAsync(createRequest);
// Search memories
var searchRequest = new SearchRequest
{
Query = "What sports does the user like?",
UserId = "user123"
};
var results = await client.SearchMemoriesAsync(searchRequest);
// Get all memories for a user
var userMemories = await client.GetAllMemoriesAsync(userId: "user123");
Dependency Injection
using Mem0.NET.Extensions;
// In your Program.cs or Startup.cs
services.AddMem0Client(options =>
{
options.BaseUrl = "https://api.mem0.ai";
options.ApiKey = "your-api-key";
});
// Use in your service
public class MyService
{
private readonly Mem0Client _mem0Client;
public MyService(Mem0Client mem0Client)
{
_mem0Client = mem0Client;
}
public async Task DoSomethingAsync()
{
var memories = await _mem0Client.GetAllMemoriesAsync();
// Your logic here
}
}
API Reference
Core Methods
Memory Management
CreateMemoryAsync(MemoryCreateRequest request)
- Create new memoriesGetAllMemoriesAsync(string? userId, string? runId, string? agentId)
- Retrieve all memoriesGetMemoryAsync(string memoryId)
- Get a specific memory by IDUpdateMemoryAsync(string memoryId, Dictionary<string, object> updatedMemory)
- Update a memoryDeleteMemoryAsync(string memoryId)
- Delete a specific memoryDeleteAllMemoriesAsync(string? userId, string? runId, string? agentId)
- Delete all memories
Search and History
SearchMemoriesAsync(SearchRequest request)
- Search memories with queriesGetMemoryHistoryAsync(string memoryId)
- Get memory history
Configuration
ConfigureAsync(Dictionary<string, object> config)
- Configure Mem0 settingsResetMemoryAsync()
- Reset all memories
Data Models
MemoryCreateRequest
public class MemoryCreateRequest
{
public List<Message> Messages { get; set; }
public string? UserId { get; set; }
public string? AgentId { get; set; }
public string? RunId { get; set; }
public Dictionary<string, object>? Metadata { get; set; }
}
SearchRequest
public class SearchRequest
{
public string Query { get; set; }
public string? UserId { get; set; }
public string? RunId { get; set; }
public string? AgentId { get; set; }
public Dictionary<string, object>? Filters { get; set; }
}
Memory
public class Memory
{
public string Id { get; set; }
public string Content { get; set; }
public string? UserId { get; set; }
public string? AgentId { get; set; }
public string? RunId { get; set; }
public Dictionary<string, object>? Metadata { get; set; }
public DateTime? CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
}
Examples
Creating Memories with Metadata
var createRequest = new MemoryCreateRequest
{
Messages = new List<Message>
{
new Message { Role = "user", Content = "I prefer working in the morning" },
new Message { Role = "assistant", Content = "I'll remember your morning preference" }
},
UserId = "user123",
Metadata = new Dictionary<string, object>
{
["category"] = "preference",
["priority"] = "high"
}
};
var memories = await client.CreateMemoryAsync(createRequest);
Advanced Search with Filters
var searchRequest = new SearchRequest
{
Query = "user preferences",
UserId = "user123",
Filters = new Dictionary<string, object>
{
["category"] = "preference",
["priority"] = "high"
}
};
var results = await client.SearchMemoriesAsync(searchRequest);
Custom HTTP Client Configuration
var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(30);
var client = new Mem0Client("https://api.mem0.ai", "your-api-key", httpClient);
Error Handling
The client throws exceptions for HTTP errors. Always wrap your calls in try-catch blocks:
try
{
var memories = await client.GetAllMemoriesAsync();
}
catch (HttpRequestException ex)
{
// Handle HTTP errors
Console.WriteLine($"HTTP Error: {ex.Message}");
}
catch (Exception ex)
{
// Handle other errors
Console.WriteLine($"Error: {ex.Message}");
}
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for your changes
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Changelog
See CHANGELOG.md for a list of changes and updates.
Made with ❤️ by AIDotNet
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
-
net7.0
-
net8.0
-
net9.0
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Mem0.NET:
Package | Downloads |
---|---|
mem0.NET.Qdrant
Package Description |
|
mem0.FreeSql
Package Description |
|
mem0.EntityFrameworkCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
1.1.3 | 679 | 6/20/2025 | |
1.1.2 | 139 | 6/19/2025 | |
1.1.1 | 138 | 6/19/2025 | |
1.1.0 | 135 | 6/19/2025 | |
1.0.0 | 137 | 6/19/2025 | |
0.2.2 | 254 | 12/10/2024 | |
0.2.0 | 181 | 8/18/2024 | |
0.1.91 | 153 | 8/18/2024 | |
0.1.9 | 157 | 8/18/2024 | |
0.1.8 | 155 | 8/18/2024 | |
0.1.7 | 129 | 8/4/2024 | |
0.1.6 | 104 | 8/3/2024 | |
0.1.5 | 139 | 8/2/2024 | |
0.1.3 | 114 | 7/30/2024 | |
0.1.2 | 114 | 7/30/2024 | |
0.1.1 | 114 | 7/30/2024 | |
0.1.0 | 191 | 7/30/2024 |