Giter Club home page Giter Club logo

semantic-memory's Introduction

Semantic Memory

Semantic Memory is an open-source library and service specializing in the efficient indexing of datasets through custom continuous data pipelines.

image

Utilizing advanced embeddings and LLMs, the system enables natural language querying for obtaining answers from the indexed data, complete with citations and links to the original sources.

image

Designed for seamless integration with Semantic Kernel, Semantic Memory enhances data-driven features in applications built using SK.

ℹī¸ NOTE: the documentation below is work in progress, will evolve quickly as is not fully functional yet.

Examples

Importing memory, locally, without deployments

Importing files into your Semantic Memory can be as simple as this:

var memory = new MemoryPipelineClient();

await memory.ImportFileAsync("file1.docx",
    new ImportFileOptions("user-id-1", "memory-collection"));

await memory.ImportFilesAsync(new[] { "file2.docx", "file3.pdf" },
    new ImportFileOptions("user-id-1", "memory-collection"));

The code leverages the default data ingestion pipeline:

  1. Extract text
  2. Partition the text in small chunks
  3. Extract embedding
  4. Save embedding into a vector index

Import memory using Semantic Memory Web Service

Depending on the configuration, the code above can run locally, inside your process, or remotely through a service.

If you're importing small files, and need only C# or Python, and can block the process during the import, local execution can be fine.

However, if you are in one of these scenarios:

  • I'd just like a web service to import data and send queries to answer
  • My app is written in TypeScript, Java, Rust, or some other language
  • I want to define custom pipelines mixing multiple languages like Python, TypeScript, etc
  • I'm importing big documents that can require minutes to process, and I don't want to block the user interface
  • I need memory import to run independently, supporting failures and retry logic

then you can deploy Semantic Memory as a web service, plugging in the default handlers or your custom Python/TypeScript/Java/etc. handlers, leveraging the asynchronous queues automatically available.

If you deploy the default web service available in the repo, you only need to change the configuration, and use the same code above.

To import files using Semantic Memory web service, simply use SemanticMemoryWebClient:

var memory = new MemoryWebClient("http://127.0.0.1:9001"); // <== URL where the web service is running

await memory.ImportFileAsync("file1.docx",
    new ImportFileOptions("user-id-1", "memory-collection"));

await memory.ImportFilesAsync(new[] { "file2.docx", "file3.pdf" },
    new ImportFileOptions("user-id-1", "memory-collection"));

Custom import pipelines

On the other hand, if you need a custom data pipeline, you can also customize the steps, which will be handled by your custom business logic:

var app = AppBuilder.Build();
var storage = app.Services.GetService<IContentStorage>();

// Use a local, synchronous, orchestrator
var orchestrator = new InProcessPipelineOrchestrator(storage);

// Define custom .NET handlers
var step1 = new MyHandler1("step1", orchestrator);
var step2 = new MyHandler2("step2", orchestrator);
var step3 = new MyHandler3("step3", orchestrator);
await orchestrator.AddHandlerAsync(step1);
await orchestrator.AddHandlerAsync(step2);
await orchestrator.AddHandlerAsync(step3);

// Instantiate a custom pipeline
var pipeline = orchestrator
    .PrepareNewFileUploadPipeline("mytest", "user-id-1", new[] { "memory-collection" })
    .AddUploadFile("file1", "file1.docx", "file1.docx")
    .AddUploadFile("file2", "file2.pdf", "file2.pdf")
    .Then("step1")
    .Then("step2")
    .Then("step3")
    .Build();

// Execute in process, process all files with all the handlers
await orchestrator.RunPipelineAsync(pipeline);

semantic-memory's People

Contributors

dluc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.