Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Memory Plugin extraction - Part 2 #3092

Merged
merged 9 commits into from
Oct 9, 2023

Conversation

dmytrostruk
Copy link
Member

@dmytrostruk dmytrostruk commented Oct 6, 2023

Motivation and Context

This PR contains changes to mark Memory-related functionality in Kernel as Obsolete and create alternative methods in Plugins.Memory and Connectors projects.

Note: Obsolete methods and properties will be removed in future releases.

ADR: 0011-memory-as-plugin.md

Main change: helper methods for Memory were moved from KernelBuilder to MemoryBuilder. Previously, it was possible to configure only one Memory instance per Kernel instance. Now, Memory functionality is decoupled from Kernel and should be configured separately.

Previous Memory usage:

var kernel = Kernel.Builder
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", TestConfiguration.OpenAI.ApiKey)
    .WithMemoryStorage(new AzureCognitiveSearchMemoryStore(TestConfiguration.ACS.Endpoint, TestConfiguration.ACS.ApiKey))
    .Build();

kernel.Memory.SaveInformationAsync(...);

New Memory usage:

var memory = new MemoryBuilder()
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", TestConfiguration.OpenAI.ApiKey)
    .WithMemoryStore(new AzureCognitiveSearchMemoryStore(TestConfiguration.ACS.Endpoint, TestConfiguration.ACS.ApiKey))
    .Build();

memory.SaveInformationAsync(...);

Description

  1. Added MemoryBuilder as equivalent to KernelBuilder to initialize the logic related to Memory.
  2. Added unit tests for MemoryBuilder.
  3. Added extension methods for MemoryBuilder related to Memory and AI Connectors.
  4. Marked Memory-related methods and properties in Kernel/KernelBuilder as obsolete.

Contribution Checklist

@dmytrostruk dmytrostruk requested a review from a team as a code owner October 6, 2023 17:39
@shawncal shawncal added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core memory connector labels Oct 6, 2023
@dmytrostruk dmytrostruk added the PR: ready for review All feedback addressed, ready for reviews label Oct 6, 2023
@dmytrostruk dmytrostruk self-assigned this Oct 6, 2023
@markwallace-microsoft markwallace-microsoft added the PR: breaking change Pull requests that introduce breaking changes label Oct 6, 2023
Copy link
Member

@markwallace-microsoft markwallace-microsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the breaking change tag to this PR as we expect developers to make a code change and this will get the PR listed in the release notes accordingly.

We want to make it easy for developers to understand and adopt the new pattern. Can you:

  1. Update the PR description to that includes some instructions on how developers should change their code. It should read like a step by step migration guide.
  2. Add sufficient information to the obsolete message so developers know what they need to change. We don't have a good pattern here but maybe a link to a sample, we may even want dedicated samples that show how to change the code i.e. with before and after sample code.

dotnet/src/SemanticKernel.Abstractions/IKernel.cs Outdated Show resolved Hide resolved
dotnet/src/SemanticKernel.Abstractions/IKernel.cs Outdated Show resolved Hide resolved
@dmytrostruk dmytrostruk added this pull request to the merge queue Oct 9, 2023
Merged via the queue into microsoft:main with commit 30967db Oct 9, 2023
18 checks passed
@dmytrostruk dmytrostruk deleted the memory-plugin-part2 branch October 9, 2023 14:13
SOE-YoungS pushed a commit to SOE-YoungS/semantic-kernel that referenced this pull request Nov 1, 2023
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

This PR contains changes to mark Memory-related functionality in Kernel
as Obsolete and create alternative methods in `Plugins.Memory` and
Connectors projects.

Note: Obsolete methods and properties will be removed in future
releases.

ADR:
[0011-memory-as-plugin.md](https://github.com/microsoft/semantic-kernel/blob/main/docs/decisions/0011-memory-as-plugin.md)

**Main change**: helper methods for Memory were moved from
`KernelBuilder` to `MemoryBuilder`. Previously, it was possible to
configure only one Memory instance per Kernel instance. Now, Memory
functionality is decoupled from Kernel and should be configured
separately.

Previous Memory usage:
```csharp
var kernel = Kernel.Builder
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", TestConfiguration.OpenAI.ApiKey)
    .WithMemoryStorage(new AzureCognitiveSearchMemoryStore(TestConfiguration.ACS.Endpoint, TestConfiguration.ACS.ApiKey))
    .Build();

kernel.Memory.SaveInformationAsync(...);
```

New Memory usage:
```csharp
var memory = new MemoryBuilder()
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", TestConfiguration.OpenAI.ApiKey)
    .WithMemoryStore(new AzureCognitiveSearchMemoryStore(TestConfiguration.ACS.Endpoint, TestConfiguration.ACS.ApiKey))
    .Build();

memory.SaveInformationAsync(...);
```


### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Added `MemoryBuilder` as equivalent to `KernelBuilder` to initialize
the logic related to Memory.
2. Added unit tests for `MemoryBuilder`.
3. Added extension methods for `MemoryBuilder` related to Memory and AI
Connectors.
4. Marked Memory-related methods and properties in Kernel/KernelBuilder
as obsolete.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel memory connector .NET Issue or Pull requests regarding .NET code PR: breaking change Pull requests that introduce breaking changes PR: ready for review All feedback addressed, ready for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants