Mem0Sharp 0.2.2
dotnet add package Mem0Sharp --version 0.2.2
NuGet\Install-Package Mem0Sharp -Version 0.2.2
<PackageReference Include="Mem0Sharp" Version="0.2.2" />
<PackageVersion Include="Mem0Sharp" Version="0.2.2" />
<PackageReference Include="Mem0Sharp" />
paket add Mem0Sharp --version 0.2.2
#r "nuget: Mem0Sharp, 0.2.2"
#:package Mem0Sharp@0.2.2
#addin nuget:?package=Mem0Sharp&version=0.2.2
#tool nuget:?package=Mem0Sharp&version=0.2.2
<div align="center"> <img src="assets/banner.png" alt="Mem0Sharp Banner" width="100%" /> </div>
Mem0Sharp
Long-term cognitive memory engine for AI applications and agents in .NET.
Mem0Sharp is an independent, standalone C#/.NET implementation of the open-source Mem0 project. It delivers a unified service API for saving, searching, updating, and consolidating semantic memories with modular embedding and vector storage providers.
- ð 100% Standalone & Local-First: Runs entirely in-process in .NET with zero telemetry or third-party cloud service requirements.
- ðŠķ Broad Runtime Support: NuGet packages target .NET Standard 2.0, .NET 8, .NET 9, and .NET 10. Persistence providers (PostgreSQL/pgvector, SQLite, Qdrant) are modular add-ons.
- ð§ Cognitive Memory Behaviors: Goes beyond raw vector storage with autonomous behaviors (dreaming/consolidation, spontaneous associations, and personality-shaped first-person recall).
- ð Native Model Context Protocol (MCP): Includes 9 local MCP tools out of the box for agentic developer tools (Cursor, Claude Desktop, Copilot).
Mem0Sharp is not affiliated with, sponsored by, or endorsed by Mem0 or mem0ai.
Quickstart
Get started immediately with in-memory storage, deterministic local embeddings, and no external services:
using Mem0Sharp;
var memory = new MemoryService();
await memory.AddAsync("I prefer C# over Python.", new MemoryAddOptions { UserId = "alice" });
var results = await memory.SearchAsync(
"What language does Alice like?",
new MemorySearchOptions { Filter = new MemoryFilter(UserId: "alice"), TopK = 1 });
Console.WriteLine(results[0].Memory.Text); // I prefer C# over Python.
Why Mem0Sharp? (Comparison Matrix)
| Feature / Capability | Mem0Sharp | Python Mem0 (OSS) | Hosted Mem0 SaaS | Raw Vector DBs | Ephemeral Chat Buffers |
|---|---|---|---|---|---|
| Ecosystem & Runtime | .NET Standard 2.0 / .NET 8-10 | Python | Cloud API | Any Driver | Any Framework |
| Local-First & Offline | 100% (No Telemetry) | 100% | â Cloud Only | 100% | 100% |
| Local In-Process Core | Yes | â Multi-package | â Client SDK | â Heavy client | Yes |
| Cognitive Behaviors (Dreaming, Identity) | Built-in | â (Static) | â (Static) | â (Raw vectors) | â |
| Model Context Protocol (MCP) | 9 Built-in Tools | Separate repo | â Cloud only | â | â |
| Hybrid Search + Cross-Encoder Reranking | Built-in (BM25 + Dense) | Basic | Proprietary | â Manual setup | â |
| Audit History & Temporal Tracking | Built-in | Basic | Proprietary | â Manual setup | â |
Architecture & Memory Lifecycle
flowchart LR
subgraph Ingestion["1. Memory Ingestion"]
Msg["User & Agent Messages"] --> Extractor["LLM / Lexical Extractor"]
Extractor --> Dedupe["Deduplication & Conflict Resolver"]
end
subgraph Behaviors["2. Cognitive Behaviors"]
Dedupe --> Normal["Normal Fact Memory"]
Dedupe --> Dream["Dreaming & Consolidation"]
Dedupe --> Assoc["Spontaneous Associations"]
Dedupe --> Identity["Personality / First-Person"]
end
subgraph Storage["3. Modular Persistence"]
Normal & Dream & Assoc & Identity --> Store["Storage Engine<br/>(InMemory / SQLite / PostgreSQL pgvector / Qdrant)"]
end
subgraph Retrieval["4. Context Retrieval"]
Query["Search Query"] --> Hybrid["Hybrid Search<br/>(Dense Vector + BM25)"]
Store --> Hybrid
Hybrid --> Rerank["Reranker (Cohere / Cross-Encoder / LLM)"]
Rerank --> Context["Filtered Agent Context"]
end
Installation
Install the dependency-free core package:
dotnet add package Mem0Sharp
For persistent database backends, install the optional provider packages:
dotnet add package Mem0Sharp.PostgreSQL
dotnet add package Mem0Sharp.SQLite
Features
- Semantic & Hybrid Retrieval: Dense vector search combined with BM25 keyword scoring and LLM/Cohere/Cross-Encoder reranking.
- Model Support: Built-in support for OpenAI-compatible, Anthropic, and Ollama model APIs.
- Cognitive Behaviors:
Normal: Standard factual extraction and recall.Dreaming: Background memory consolidation, compressing repeated facts into long-term insights.Random Thoughts: Spontaneous associations and creative prompt injections.Personal/Identity: First-person perspective memory shaping.
- Audit & History: Persistent
ADD,UPDATE, andDELETEhistory with audit timestamps, actor, and role tracking. - Scoped Organization: User, session, and agent-level memory partitioning with run filters and metadata matching.
- Model Context Protocol (MCP): 9 built-in tools ready to plug into Claude Desktop, Cursor, and VS Code.
- Batch Operations: High-throughput transactional batch embeddings and searches.
Usage Examples
1. Basic In-Memory Operations
using Mem0Sharp;
var memory = new MemoryService();
// Add a memory
await memory.AddAsync("I prefer dark mode and vim keybindings", userId: "alice");
// Search memories
var results = await memory.SearchAsync(
"What editor settings does Alice prefer?",
new MemoryFilter(UserId: "alice"),
topK: 3);
foreach (var result in results)
{
Console.WriteLine($"{result.Score:F3}: {result.Memory.Text}");
}
// Update and History
var allMemories = await memory.GetAllAsync(new MemoryFilter(UserId: "alice"));
var memoryId = allMemories[0].Id;
await memory.UpdateAsync(memoryId, "I prefer dark mode and Neovim keybindings");
var history = await memory.GetHistoryAsync(memoryId);
2. Multi-turn Conversation Extraction
await memory.AddAsync(
[
new Message("user", "I live in Berlin and work as a .NET architect."),
new Message("assistant", "Nice to meet you! I will remember that.")
],
userId: "alice",
scope: MemoryScope.User);
3. Persistent PostgreSQL with pgvector
using Mem0Sharp;
var embeddings = new LocalEmbeddingGenerator(384);
await using var store = new PostgresMemoryStore(new PostgresMemoryStoreOptions
{
ConnectionString = Environment.GetEnvironmentVariable("MEM0_POSTGRES")!,
EmbeddingDimensions = 384,
TableName = "mem0_memories"
});
await store.InitializeAsync();
var memory = new MemoryService(store, embeddings);
4. Portable SQLite Store
using Mem0Sharp;
await using var store = new SqliteMemoryStore("data/mem0sharp.db");
await store.InitializeAsync();
var memory = new MemoryService(store, new LocalEmbeddingGenerator(384));
Ecosystem Integration & Samples
Explore practical runnable examples in the samples/ folder:
- Getting Started: Zero-setup CRUD, search, and history tracking.
- Memory Behaviors: Fact extraction, dreaming/consolidation, spontaneous associations, and personality-shaped memory.
- Ollama Integration: Fully offline local LLM extraction and embeddings.
- PostgreSQL + OpenAI: Enterprise persistent pgvector storage with OpenAI models.
- Agent Framework Memory: Cross-session persistent memory for Microsoft Agent Framework.
- MCP Server: Standalone Model Context Protocol server exposing Mem0Sharp tools to Claude Desktop & Cursor.
Documentation
- Guides: Documentation Home | Getting Started | Providers & Persistence
- Reference: API Reference | Mem0 Python Parity Guide
- Benchmarking: Evaluation Harness & Metrics
- Architecture: Architecture Overview | Contribution Guidelines
Build & Test
dotnet build .\Mem0Sharp.slnx
dotnet test .\tests\Mem0Sharp.Tests\Mem0Sharp.Tests.csproj
Attribution and Trademarks
Mem0Sharp is an independent .NET implementation inspired by the open-source Mem0 project. The original Mem0 project is copyright 2023 Taranjeet Singh and is licensed under the Apache License 2.0. Copyright for the Mem0Sharp implementation and its modifications is held by Jihad Khawaja and contributors. See NOTICE and LICENSE for details.
Mem0 and related marks belong to their respective owners. Mem0Sharp is not affiliated with, sponsored by, or endorsed by Mem0 or mem0ai.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.11)
- Microsoft.Extensions.AI.Abstractions (>= 10.9.0)
- System.Net.Http.Json (>= 10.0.11)
- System.Numerics.Tensors (>= 10.0.11)
- System.Text.Json (>= 10.0.11)
-
net10.0
- Microsoft.Extensions.AI.Abstractions (>= 10.9.0)
- System.Numerics.Tensors (>= 10.0.11)
-
net8.0
- Microsoft.Extensions.AI.Abstractions (>= 10.9.0)
- System.Numerics.Tensors (>= 10.0.11)
-
net9.0
- Microsoft.Extensions.AI.Abstractions (>= 10.9.0)
- System.Numerics.Tensors (>= 10.0.11)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Mem0Sharp:
| Package | Downloads |
|---|---|
|
Mem0Sharp.PostgreSQL
PostgreSQL and pgvector persistence providers for Mem0Sharp. |
|
|
Mem0Sharp.SQLite
SQLite persistence provider for Mem0Sharp. |
GitHub repositories
This package is not used by any popular GitHub repositories.