Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## vNext
## v2.1.3

Add:

- Added `IBatchEmbeddingsGenerator` and `.AddTextsAsync` to support batch adding of texts to database.
- Added OpenAI support for `IBatchEmbeddingsGenerator`
- Added `IVectorTextResultItem.Similarity` and marked `IVectorTextResultItem.VectorComparison` obsolete. `VectorComparison` will be removed in the future.
- Added more comment metadata to code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageId>Build5Nines.SharpVector.OpenAI</PackageId>
<PackageProjectUrl>https://sharpvector.build5nines.com</PackageProjectUrl>
<RepositoryUrl>https://github.com/Build5Nines/SharpVector</RepositoryUrl>
<Version>2.0.3</Version>
<Version>2.0.4</Version>
<Description>Lightweight In-memory Vector Database to embed in any .NET Applications that integrates with OpenAI Embedding model for vector generation.</Description>
<Copyright>Copyright (c) 2025 Build5Nines LLC</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Build5Nines.SharpVector" Version="[2.0.3,3.0.0)" />
<PackageReference Include="Build5Nines.SharpVector" Version="[2.1.3,3.0.0)" />
<PackageReference Include="OpenAI" Version="[2.1.0,3.0.0]" />
<!-- <ProjectReference Include="..\Build5Nines.SharpVector\Build5Nines.SharpVector.csproj" /> -->
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Build5Nines.SharpVector.OpenAI.Embeddings;

public class OpenAIEmbeddingsGenerator : IEmbeddingsGenerator //IBatchEmbeddingsGenerator
public class OpenAIEmbeddingsGenerator : IBatchEmbeddingsGenerator
{
protected EmbeddingClient EmbeddingClient { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion src/OpenAIConsoleTest/OpenAIConsoleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Build5Nines.SharpVector" Version="[2.0.3,3.0.0)" />
<PackageReference Include="Build5Nines.SharpVector" Version="[2.1.3,3.0.0)" />
<PackageReference Include="OpenAI" Version="2.1.0" />
</ItemGroup>

Expand Down
47 changes: 47 additions & 0 deletions src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@
It.IsAny<EmbeddingGenerationOptions?>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(clientResult);

_mockEmbeddingClient
.Setup(c => c.GenerateEmbeddingsAsync(
It.IsAny<IEnumerable<string>>(),
It.IsAny<EmbeddingGenerationOptions?>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync((List<string> inputs, EmbeddingGenerationOptions? options, CancellationToken token) =>
{
// return OpenAIEmbeddingCollection with same embedding for each input
var embeddings = new List<OpenAIEmbedding>();
for (int i = 0; i < inputs.Count; i++)
{
embeddings.Add(OpenAIEmbeddingsModelFactory.OpenAIEmbedding(index: i, vector: embeddingVector));
}
var collection = OpenAIEmbeddingsModelFactory.OpenAIEmbeddingCollection(embeddings);
return ClientResult.FromValue(collection, new TestPipelineResponse());
});

_database = new BasicOpenAIMemoryVectorDatabase(_mockEmbeddingClient.Object);
}
Expand Down Expand Up @@ -86,7 +103,7 @@
[TestMethod]
public async Task Test_SaveLoad_TestIds_01()
{
_database.AddText("Sample text for testing IDs.", "111");

Check warning on line 106 in src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs

View workflow job for this annotation

GitHub Actions / performance

Dereference of a possibly null reference.

Check warning on line 106 in src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs

View workflow job for this annotation

GitHub Actions / tests

Dereference of a possibly null reference.
_database.AddText("Another sample text for testing IDs.", "222");

var results = _database.Search("testing IDs");
Expand All @@ -112,7 +129,7 @@
[TestMethod]
public async Task Test_SaveLoad_TestIds_02()
{
_database.AddText("Sample text for testing IDs.", "111");

Check warning on line 132 in src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs

View workflow job for this annotation

GitHub Actions / performance

Dereference of a possibly null reference.

Check warning on line 132 in src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs

View workflow job for this annotation

GitHub Actions / tests

Dereference of a possibly null reference.
_database.AddText("Another sample text for testing IDs.", "222");

var results = _database.Search("testing IDs");
Expand All @@ -123,7 +140,7 @@
await _database.SaveToFileAsync(filename);
#pragma warning restore CS8604 // Possible null reference argument.

var newdb = new BasicOpenAIMemoryVectorDatabase(_mockEmbeddingClient.Object);

Check warning on line 143 in src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs

View workflow job for this annotation

GitHub Actions / performance

Dereference of a possibly null reference.

Check warning on line 143 in src/SharpVectorOpenAITest/BasicOpenAIMemoryVectorDatabaseTest.cs

View workflow job for this annotation

GitHub Actions / tests

Dereference of a possibly null reference.
await newdb.LoadFromFileAsync(filename);

newdb.AddText("A new text after loading to check ID assignment.", "333");
Expand All @@ -135,5 +152,35 @@
Assert.AreEqual("222", texts[1].Metadata);
Assert.AreEqual("333", texts[2].Metadata);
}

[TestMethod]
public async Task Test_SaveLoad_TestIds_Batch_02()
{
await _database.AddTextsAsync(new (string text, string? metadata)[]
{
("Sample text for testing IDs.", "111"),
("Another sample text for testing IDs.", "222")
});

var results = _database.Search("testing IDs");
Assert.AreEqual(2, results.Texts.Count());

var filename = "openai_test_saveload_testids_batch_02.b59vdb";
#pragma warning disable CS8604 // Possible null reference argument.
await _database.SaveToFileAsync(filename);
#pragma warning restore CS8604 // Possible null reference argument.

var newdb = new BasicOpenAIMemoryVectorDatabase(_mockEmbeddingClient.Object);
await newdb.LoadFromFileAsync(filename);

newdb.AddText("A new text after loading to check ID assignment.", "333");

var newResults = newdb.Search("testing IDs");
Assert.AreEqual(3, newResults.Texts.Count());
var texts = newResults.Texts.OrderBy(x => x.Metadata).ToArray();
Assert.AreEqual("111", texts[0].Metadata);
Assert.AreEqual("222", texts[1].Metadata);
Assert.AreEqual("333", texts[2].Metadata);
}
}
}
Loading