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

Chroma memory store - C# implementation #1634

Merged
merged 30 commits into from
Jun 26, 2023

Conversation

dmytrostruk
Copy link
Member

@dmytrostruk dmytrostruk commented Jun 21, 2023

Motivation and Context

This PR contains changes for Chroma C# memory store.
For more information about Chroma, see: https://docs.trychroma.com/getting-started.

To run integration tests, local Chroma server should be up and running.

To start local Chroma server for testing (this information is also included in README):

  1. Clone Chroma:
git clone https://github.com/chroma-core/chroma.git
cd chroma
  1. Run local Chroma server with Docker within Chroma repository root:
docker-compose up -d --build
  1. Use Semantic Kernel with Chroma, using server local endpoint http://localhost:8000:
const string endpoint = "http://localhost:8000";

ChromaMemoryStore memoryStore = new(endpoint);

IKernel kernel = Kernel.Builder
    .WithLogger(logger)
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", "OPENAI_API_KEY")
    .WithMemoryStorage(memoryStore)
    //.WithChromaMemoryStore(endpoint) // This method offers an alternative approach to registering Chroma memory store.
    .Build();

Description

Main public classes:

  1. ChromaMemoryStore - implementation of IMemoryStore interface. Uses ChromaClient to communicate with Chroma API. Throws ChromaMemoryStoreException in case of issues.
  2. ChromaClient - responsible for communication with Chroma API. Throws ChromaClientException in case of issues.

Chroma entity models:

  1. ChromaCollectionModel - defines Chroma collection.
  2. ChromaEmbeddingsModel - defines Chroma embeddings, constructed from MemoryRecord.
  3. ChromaQueryResultModel - defines Chroma search result set.

Contribution Checklist

@dmytrostruk dmytrostruk requested review from a team as code owners June 21, 2023 15:59
@github-actions github-actions bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel samples labels Jun 21, 2023
@dmytrostruk dmytrostruk added memory connector ai connector Anything related to AI connectors labels Jun 21, 2023
@dmytrostruk dmytrostruk self-assigned this Jun 21, 2023
@github-actions github-actions bot removed the samples label Jun 21, 2023
@dmytrostruk dmytrostruk added the PR: ready for review All feedback addressed, ready for reviews label Jun 21, 2023
@dmytrostruk dmytrostruk removed their assignment Jun 21, 2023
SergeyMenshykh
SergeyMenshykh previously approved these changes Jun 22, 2023
Copy link
Member

@lemillermicrosoft lemillermicrosoft left a comment

Choose a reason for hiding this comment

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

LGTM!

@lemillermicrosoft lemillermicrosoft added this pull request to the merge queue Jun 26, 2023
Merged via the queue into microsoft:main with commit 85d420f Jun 26, 2023
10 checks passed
@jeffchuber
Copy link
Contributor

@dmytrostruk awesome! 🎉

@evchaki evchaki added this to the Sprint 34 milestone Jun 30, 2023
shawncal pushed a commit to shawncal/semantic-kernel that referenced this pull request Jul 6, 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 for Chroma C# memory store. 
For more information about Chroma, see:
https://docs.trychroma.com/getting-started.

To run integration tests, local Chroma server should be up and running.

To start local Chroma server for testing (this information is also
included in
[README](https://github.com/microsoft/semantic-kernel/blob/0fb77e0c0f347e3f22d79b3c99e7f84d35340462/dotnet/src/Connectors/Connectors.Memory.Chroma/README.md)):
1. Clone Chroma:

```bash
git clone https://github.com/chroma-core/chroma.git
cd chroma
```

2. Run local Chroma server with Docker within Chroma repository root:

```bash
docker-compose up -d --build
```

3. Use Semantic Kernel with Chroma, using server local endpoint
`http://localhost:8000`:
```csharp
const string endpoint = "http://localhost:8000";

ChromaMemoryStore memoryStore = new(endpoint);

IKernel kernel = Kernel.Builder
    .WithLogger(logger)
    .WithOpenAITextEmbeddingGenerationService("text-embedding-ada-002", "OPENAI_API_KEY")
    .WithMemoryStorage(memoryStore)
    //.WithChromaMemoryStore(endpoint) // This method offers an alternative approach to registering Chroma memory store.
    .Build();
```

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Main public classes:
1. `ChromaMemoryStore` - implementation of `IMemoryStore` interface.
Uses `ChromaClient` to communicate with Chroma API. Throws
`ChromaMemoryStoreException` in case of issues.
2. `ChromaClient` - responsible for communication with Chroma API.
Throws `ChromaClientException` in case of issues.

Chroma entity models:
1. `ChromaCollectionModel` - defines Chroma collection.
2. `ChromaEmbeddingsModel` - defines Chroma embeddings, constructed from
`MemoryRecord`.
3. `ChromaQueryResultModel` - defines Chroma search result set.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [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
ai connector Anything related to AI connectors kernel Issues or pull requests impacting the core kernel memory connector .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants