Mem0.NET 1.1.2

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mem0.NET" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mem0.NET" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Mem0.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mem0.NET --version 1.1.2
                    
#r "nuget: Mem0.NET, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Mem0.NET&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Mem0.NET&version=1.1.2
                    
Install as a Cake Tool

Mem0.NET

NuGet Version NuGet Downloads License

中文文档 | 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 memories
  • GetAllMemoriesAsync(string? userId, string? runId, string? agentId) - Retrieve all memories
  • GetMemoryAsync(string memoryId) - Get a specific memory by ID
  • UpdateMemoryAsync(string memoryId, Dictionary<string, object> updatedMemory) - Update a memory
  • DeleteMemoryAsync(string memoryId) - Delete a specific memory
  • DeleteAllMemoriesAsync(string? userId, string? runId, string? agentId) - Delete all memories
Search and History
  • SearchMemoriesAsync(SearchRequest request) - Search memories with queries
  • GetMemoryHistoryAsync(string memoryId) - Get memory history
Configuration
  • ConfigureAsync(Dictionary<string, object> config) - Configure Mem0 settings
  • ResetMemoryAsync() - 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.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for your changes
  5. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2 is deprecated because it is no longer maintained and has critical bugs.
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