mem0.NET 0.1.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package mem0.NET --version 0.1.8                
NuGet\Install-Package mem0.NET -Version 0.1.8                
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="0.1.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add mem0.NET --version 0.1.8                
#r "nuget: mem0.NET, 0.1.8"                
#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.
// Install mem0.NET as a Cake Addin
#addin nuget:?package=mem0.NET&version=0.1.8

// Install mem0.NET as a Cake Tool
#tool nuget:?package=mem0.NET&version=0.1.8                

简单入门教程

安装mem0.NET

dotnet add package mem0.NET
dotnet add package mem0.EntityFrameworkCore
dotnet add mem0.NET.Qdrant

集成到项目

打开appsettings.json文件,添加以下配置

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "Default": "Host=localhost;Port=5432;Database=test;Username=token;Password=dd666666"
  },
  "Mem0": {
    "OpenAIEndpoint": "https://api.token-ai.cn",
    "OpenAIKey": "sk-666666",
    "OpenAIChatCompletionModel": "gpt-4o-mini",
    "OpenAITextEmbeddingModel": "text-embedding-ada-002",
    "CollectionName": "mem0-test"
  },
  "Qdrant": {
    "Host": "127.0.0.1",
    "Port": 6334,
    "Https": false,
    "ApiKey": "dd666666"
  }
}

创建一个EFCore的DbContext,需要继承Mem0DbContext类,如下所示 MasterDbContext.cs

using mem0.NET.Service.DataAccess;
using Microsoft.EntityFrameworkCore;

namespace mem0.NET.Service;

public class MasterDbContext(DbContextOptions<MasterDbContext> options) : Mem0DbContext<MasterDbContext>(options)
{
}

然后打开Program.cs文件,添加以下代码

builder.Services.AddOptions<Mem0Options>()
    .Bind(builder.Configuration.GetSection("Mem0"));

builder.Services.AddOptions<QdrantOptions>()
    .Bind(builder.Configuration.GetSection("Qdrant"));

var options = builder.Configuration.GetSection("Mem0")
    .Get<Mem0Options>();

var qdrantOptions = builder.Configuration.GetSection("Qdrant")
    .Get<QdrantOptions>();

builder.Services.AddMem0DotNet(options)
    .WithMem0EntityFrameworkCore<MasterDbContext>(optionsBuilder =>
        {
            optionsBuilder.UseNpgsql(builder.Configuration.GetConnectionString("Default"));
        })
    .WithVectorQdrant(qdrantOptions);

然后使用,如下所示,创建缓存到向量数据库

public TestService(MemoryService memoryService)
{
    public async Task CreateAsync(CreateMemoryInput input)
    {
    }
}

搜索向量服务,


public TestService(MemoryService memoryService)
{
    public async Task SearchAsync(string query, string? userId,
        string? agentId, string? runId, uint limit = 10)
    {
        memoryService.SearchMemory(query, userId, agentId, runId, limit);
    }
}

安装Qdrant

docker run -d --name qdrant -p 6334:6334 -v /path/to/data:/data qdrant/qdrant
Product Compatible and additional computed target framework versions.
.NET 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. 
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
0.2.0 151 8/18/2024
0.1.91 122 8/18/2024
0.1.9 128 8/18/2024
0.1.8 132 8/18/2024
0.1.7 103 8/4/2024
0.1.6 81 8/3/2024
0.1.5 99 8/2/2024
0.1.3 86 7/30/2024
0.1.2 89 7/30/2024
0.1.1 90 7/30/2024
0.1.0 90 7/30/2024