Semantic Kernel Neo4j 集成(预览版)

通过 Microsoft Kernel Memory,将 Neo4j 图数据库与 Microsoft 的 Semantic Kernel 集成。Neo4j 的向量搜索索引用于存储文档嵌入和密集检索。

该库允许使用 Neo4j 作为 IMemoryDb。它提供了一种简单的方法来存储和检索来自 Neo4j 的数据。

安装

Hello world 示例

# dotnet add package Neo4j.KernelMemory.Core
# dotnet add package Neo4j.Driver

using Microsoft.KernelMemory;
using Neo4j.KernelMemory.MemoryStorage;
using Neo4j.Driver;

var env = System.Environment.GetEnvironmentVariables();

var neo4jConfig = new Neo4jConfig
{
    Uri = env["NEO4J_URI"],
    Username = env["NEO4J_USERNAME"],
    Password = env["NEO4J_PASSWORD"]
};

var kernelMemory = new KernelMemoryBuilder()
    .WithOpenAIDefaults(env["OPENAI_API_KEY"])
    .WithNeo4j(neo4jConfig)
    .Build<MemoryServerless>();

// First, provide some text to the Kernel Memory, which will be indexed and stored in Neo4j
await kernelMemory.ImportTextAsync("""
The "Hello, World!" program, often attributed to Brian Kernighan's work in the 1970s, serves as the quintessential introduction to programming languages, demonstrating basic syntax with a simple output function. Originating as a test phrase in Bell Laboratories for the B programming language, it has evolved into a universal starter program for beginners in coding, symbolizing the initiation into software development. Its simplicity makes it an ideal tool for education and system testing, illustrating the minimal requirements to execute a program across various computing environments. As a cultural staple in the tech community, "Hello, World!" represents both a rite of passage for new programmers and the universal joy of creating with code. This tradition showcases the evolution of programming languages and the shared beginnings of developers worldwide.
""",
    documentId: "HelloWorld");

// Now ask a question
var question = "Who wrote the first Hello World?";

var answer = await kernelMemory.AskAsync(question);

Console.WriteLine($"Question: {question}\n\nAnswer: {answer.Result}");

功能包括

  • Neo4jMemory - IMemoryDb 的实现。

  • WithNeo4j - KernelMemoryBuilder 的扩展。

  • 与 Semantic Kernel 集成

  • 在无服务器环境中开发,作为服务器部署

视频和教程