Skip to content

Commit

Permalink
.Net: Fixing up new projects merged from main. (#9208)
Browse files Browse the repository at this point in the history
### Description

Fixing up latest changes from main to match refactoring in branch.

### 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 😄
  • Loading branch information
westey-m authored Oct 11, 2024
1 parent 13f953e commit ba7725a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dotnet/samples/Demos/VectorStoreRAG/DataLoader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.Data;
using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel.Embeddings;
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/Demos/VectorStoreRAG/TextSnippet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.Data;
using Microsoft.Extensions.VectorData;

namespace VectorStoreRAG;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.Memory.InMemory\Connectors.Memory.InMemory.csproj" />
<ProjectReference Include="..\..\src\Extensions\PromptTemplates.Handlebars\PromptTemplates.Handlebars.csproj" />
<ProjectReference Include="..\..\src\Plugins\Plugins.Web\Plugins.Web.csproj" />
<ProjectReference Include="..\..\src\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.

namespace GettingStartedWithTextSearch;

[CollectionDefinition("InMemoryVectorStoreCollection")]
public class InMemoryVectorStoreCollectionFixture : ICollectionFixture<InMemoryVectorStoreFixture>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@

using System.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel.Connectors.InMemory;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Data;
using Microsoft.SemanticKernel.Embeddings;

namespace GettingStartedWithTextSearch;

/// <summary>
/// Helper class for setting up and tearing down a <see cref="VolatileVectorStore"/> for testing purposes.
/// Helper class for setting up and tearing down a <see cref="InMemoryVectorStore"/> for testing purposes.
/// </summary>
public class VolatileVectorStoreFixture : IAsyncLifetime
public class InMemoryVectorStoreFixture : IAsyncLifetime
{
public ITextEmbeddingGenerationService TextEmbeddingGenerationService { get; private set; }

public VolatileVectorStore VolatileVectorStore { get; private set; }
public InMemoryVectorStore InMemoryVectorStore { get; private set; }

public IVectorStoreRecordCollection<Guid, DataModel> VectorStoreRecordCollection { get; private set; }

public string CollectionName => "records";

/// <summary>
/// Initializes a new instance of the <see cref="VolatileVectorStoreFixture"/> class.
/// Initializes a new instance of the <see cref="InMemoryVectorStoreFixture"/> class.
/// </summary>
public VolatileVectorStoreFixture()
public InMemoryVectorStoreFixture()
{
IConfigurationRoot configRoot = new ConfigurationBuilder()
.AddJsonFile("appsettings.Development.json", true)
Expand All @@ -33,8 +35,8 @@ public VolatileVectorStoreFixture()
.Build();
TestConfiguration.Initialize(configRoot);

// Create a volatile vector store.
this.VolatileVectorStore = new VolatileVectorStore();
// Create an InMemory vector store.
this.InMemoryVectorStore = new InMemoryVectorStore();

// Create an embedding generation service.
this.TextEmbeddingGenerationService = new OpenAITextEmbeddingGenerationService(
Expand Down Expand Up @@ -100,7 +102,7 @@ static DataModel CreateRecord(int index, string text, ReadOnlyMemory<float> embe

/// <summary>
/// Create a <see cref="IVectorStoreRecordCollection{TKey, TRecord}"/> from a list of strings by:
/// 1. Creating an instance of <see cref="VolatileVectorStoreRecordCollection{TKey, TRecord}"/>
/// 1. Creating an instance of <see cref="IVectorStoreRecordCollection{TKey, TRecord}"/>
/// 2. Generating embeddings for each string.
/// 3. Creating a record with a valid key for each string and it's embedding.
/// 4. Insert the records into the collection.
Expand All @@ -114,7 +116,7 @@ private async Task<IVectorStoreRecordCollection<TKey, TRecord>> CreateCollection
where TRecord : class
{
// Get and create collection if it doesn't exist.
var collection = this.VolatileVectorStore.GetCollection<TKey, TRecord>(this.CollectionName);
var collection = this.InMemoryVectorStore.GetCollection<TKey, TRecord>(this.CollectionName);
await collection.CreateCollectionIfNotExistsAsync().ConfigureAwait(false);

// Create records and generate embeddings for them.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Data;
using Microsoft.SemanticKernel.PromptTemplates.Handlebars;
using static GettingStartedWithTextSearch.VolatileVectorStoreFixture;
using static GettingStartedWithTextSearch.InMemoryVectorStoreFixture;

namespace GettingStartedWithTextSearch;

/// <summary>
/// This example shows how to create a <see cref="ITextSearch"/> from a
/// <see cref="IVectorStore"/>.
/// </summary>
[Collection("VolatileVectorStoreCollection")]
public class Step4_Search_With_VectorStore(ITestOutputHelper output, VolatileVectorStoreFixture fixture) : BaseTest(output)
[Collection("InMemoryVectorStoreCollection")]
public class Step4_Search_With_VectorStore(ITestOutputHelper output, InMemoryVectorStoreFixture fixture) : BaseTest(output)
{
/// <summary>
/// Show how to create a <see cref="VectorStoreTextSearch{TRecord}"/> and use it to perform a search.
/// </summary>
[Fact]
public async Task UsingVolatileVectorStoreRecordTextSearchAsync()
public async Task UsingInMemoryVectorStoreRecordTextSearchAsync()
{
// Use embedding generation service and record collection for the fixture.
var textEmbeddingGeneration = fixture.TextEmbeddingGenerationService;
var vectorizedSearch = fixture.VectorStoreRecordCollection;

// Create a text search instance using the volatile vector store.
// Create a text search instance using the InMemory vector store.
var textSearch = new VectorStoreTextSearch<DataModel>(vectorizedSearch, textEmbeddingGeneration);

// Search and return results as TextSearchResult items
Expand All @@ -45,7 +46,7 @@ public async Task UsingVolatileVectorStoreRecordTextSearchAsync()
/// add grounding context to a Handlebars prompt.
/// </summary>
[Fact]
public async Task RagWithVolatileVectorStoreTextSearchAsync()
public async Task RagWithInMemoryVectorStoreTextSearchAsync()
{
// Create a kernel with OpenAI chat completion
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
Expand All @@ -58,7 +59,7 @@ public async Task RagWithVolatileVectorStoreTextSearchAsync()
var textEmbeddingGeneration = fixture.TextEmbeddingGenerationService;
var vectorizedSearch = fixture.VectorStoreRecordCollection;

// Create a text search instance using the volatile vector store.
// Create a text search instance using the InMemory vector store.
var textSearch = new VectorStoreTextSearch<DataModel>(vectorizedSearch, textEmbeddingGeneration);

// Build a text search plugin with vector store search and add to the kernel
Expand Down Expand Up @@ -96,7 +97,7 @@ Include citations to the relevant information where it is referenced in the resp
/// function calling to have the LLM include grounding context in it's response.
/// </summary>
[Fact]
public async Task FunctionCallingWithVolatileVectorStoreTextSearchAsync()
public async Task FunctionCallingWithInMemoryVectorStoreTextSearchAsync()
{
// Create a kernel with OpenAI chat completion
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
Expand All @@ -109,7 +110,7 @@ public async Task FunctionCallingWithVolatileVectorStoreTextSearchAsync()
var textEmbeddingGeneration = fixture.TextEmbeddingGenerationService;
var vectorizedSearch = fixture.VectorStoreRecordCollection;

// Create a text search instance using the volatile vector store.
// Create a text search instance using the InMemory vector store.
var textSearch = new VectorStoreTextSearch<DataModel>(vectorizedSearch, textEmbeddingGeneration);

// Build a text search plugin with vector store search and add to the kernel
Expand Down

This file was deleted.

0 comments on commit ba7725a

Please sign in to comment.