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
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: 'Release'
uses: ./.github/workflows/release.yml
with:
solution: 'Couchbase.SemanticKernel.sln'
solution: 'Couchbase.VectorData.sln'
release_tag: ${{ github.event.release.tag_name }}
release_body: ${{ github.event.release.body }}
secrets: 'inherit'
4 changes: 1 addition & 3 deletions .github/workflows/ci_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
uses: actions/setup-dotnet@v5
with:
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: false


- name: Get Changed Files
Expand All @@ -47,7 +46,7 @@ jobs:
restore-keys: ${{ runner.os }}-nuget-

- name: .NET Restore
run: dotnet restore ${{ inputs.path != '' && inputs.path || 'Couchbase.SemanticKernel.sln' }}
run: dotnet restore ${{ inputs.path != '' && inputs.path || 'Couchbase.VectorData.sln' }}

- name: Install latest .NET Format tool
shell: bash
Expand Down Expand Up @@ -97,7 +96,6 @@ jobs:
uses: actions/setup-dotnet@v5
with:
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: false

- name: .NET Cache Packages
uses: actions/cache@v5
Expand Down
141 changes: 0 additions & 141 deletions Couchbase.SemanticKernel/CouchbaseCollectionSearchMapping.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Couchbase.SemanticKernel.sln → Couchbase.VectorData.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Couchbase.SemanticKernel", "Couchbase.SemanticKernel\Couchbase.SemanticKernel.csproj", "{5D02D3E3-356F-4F12-B532-3FAD33A9836B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Couchbase.VectorData", "Couchbase.VectorData\Couchbase.VectorData.csproj", "{5D02D3E3-356F-4F12-B532-3FAD33A9836B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CouchbaseVectorSearchDemo", "CouchbaseVectorSearchDemo\CouchbaseVectorSearchDemo.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net10.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>CouchbaseConnector.SemanticKernel</PackageId>
<PackageId>CouchbaseConnector.VectorData</PackageId>
<Version>0.2.5</Version>
<Authors>Couchbase and contributors</Authors>
<Company>Couchbase</Company>
<Description>Couchbase connector for Microsoft Semantic Kernel.</Description>
<PackageTags>Couchbase;SemanticKernel;VectorSearch</PackageTags>
<Description>Couchbase provider for Microsoft.Extensions.VectorData.</Description>
<PackageTags>Couchbase;VectorData;VectorSearch</PackageTags>
<RepositoryUrl>https://github.com/Couchbase-Ecosystem/couchbase-semantic-kernel</RepositoryUrl>
<PackageOutputPath>bin\Release</PackageOutputPath>
<PackageIcon>logo.png</PackageIcon>
Expand All @@ -26,12 +26,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CouchbaseNetClient" Version="3.8.0" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.10.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.7.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.66.0" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.66.0" />
<PackageReference Include="CouchbaseNetClient" Version="3.9.4" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="10.8.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.10" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="10.8.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using Couchbase.Core.IO.Transcoders;
using Couchbase.KeyValue;
using Couchbase.Management.Collections;
using Couchbase.SemanticKernel.Diagnostics;
using Couchbase.VectorData.Diagnostics;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData;
using Microsoft.Extensions.VectorData.ProviderServices;

namespace Couchbase.SemanticKernel;
namespace Couchbase.VectorData;

/// <summary>
/// Abstract base class for Couchbase vector store collections with shared functionality.
Expand Down Expand Up @@ -77,7 +77,7 @@ protected CouchbaseCollectionBase(
// Build the collection model
_model = typeof(TRecord) == typeof(Dictionary<string, object?>)
? new CouchbaseModelBuilder().BuildDynamic(_options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections."), _options.EmbeddingGenerator)
: new CouchbaseModelBuilder().Build(typeof(TRecord), _options.Definition, _options.EmbeddingGenerator);
: new CouchbaseModelBuilder().Build(typeof(TRecord), typeof(TKey), _options.Definition, _options.EmbeddingGenerator);

// Initialize mapper directly (no InitializeMapper method needed)
_mapper = typeof(TRecord) == typeof(Dictionary<string, object?>)
Expand Down Expand Up @@ -272,16 +272,10 @@ public override async Task UpsertAsync(TRecord record, CancellationToken cancell
// We have a vector property whose type isn't natively supported - we need to generate embeddings.
Debug.Assert(vectorProperty.EmbeddingGenerator is not null);

if (vectorProperty.TryGenerateEmbedding<TRecord, Embedding<float>>(record, cancellationToken, out var task))
{
generatedEmbeddings ??= new Embedding<float>?[vectorPropertyCount];
generatedEmbeddings[i] = await task.ConfigureAwait(false);
}
else
{
throw new InvalidOperationException(
$"The embedding generator configured on property '{vectorProperty.ModelName}' cannot produce an embedding of type '{typeof(Embedding<float>).Name}' for the given input type.");
}
var sourceValue = vectorProperty.GetValueAsObject(record);
var embedding = await vectorProperty.GenerateEmbeddingAsync(sourceValue, cancellationToken).ConfigureAwait(false);
generatedEmbeddings ??= new Embedding<float>?[vectorPropertyCount];
generatedEmbeddings[i] = (Embedding<float>)embedding;
}

// Convert the data model to the storage model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Couchbase.SemanticKernel;
namespace Couchbase.VectorData;

internal static class CouchbaseConstants
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData.ProviderServices;

namespace Couchbase.SemanticKernel;
namespace Couchbase.VectorData;

/// <summary>
/// A mapper that maps between a dynamic Dictionary&lt;string, object?&gt; data model and the Couchbase storage model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Couchbase.SemanticKernel;
namespace Couchbase.VectorData;

/// <summary>
/// Represents the different types of indexes supported by Couchbase for vector operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData.ProviderServices;

namespace Couchbase.SemanticKernel;
namespace Couchbase.VectorData;

/// <summary>
/// A mapper that maps between the generic Semantic Kernel data model and the model that the data is stored under,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Extensions.VectorData;
using Microsoft.Extensions.VectorData.ProviderServices;

namespace Couchbase.SemanticKernel;
namespace Couchbase.VectorData;

/// <summary>
/// Customized Couchbase model builder that adds specialized configuration of property storage names
Expand All @@ -28,7 +28,6 @@ internal class CouchbaseModelBuilder : CollectionModelBuilder
private static readonly CollectionModelBuildingOptions s_validationOptions = new()
{
RequiresAtLeastOneVector = false,
SupportsMultipleKeys = false,
SupportsMultipleVectors = true,
UsesExternalSerializer = true,
};
Expand All @@ -52,37 +51,36 @@ public override CollectionModel BuildDynamic(VectorStoreCollectionDefinition def
}

/// <summary>
/// Process the properties of the given type and customize storage names based on JsonPropertyName attributes.
/// Processes a single property and customizes its storage name based on the JsonPropertyName attribute.
/// </summary>
/// <param name="type">The type to process.</param>
/// <param name="definition">The collection definition.</param>
/// <param name="clrProperty">The CLR property to process.</param>
/// <param name="definitionProperty">The property from the record definition, if any.</param>
[RequiresUnreferencedCode("Traverses the CLR type's properties with reflection, so not compatible with trimming")]
protected override void ProcessTypeProperties(Type type, VectorStoreCollectionDefinition? definition)
protected override void ProcessProperty(PropertyInfo? clrProperty, VectorStoreProperty? definitionProperty)
{
base.ProcessTypeProperties(type, definition);
base.ProcessProperty(clrProperty, definitionProperty);

// Customize storage names based on JsonPropertyName attributes
foreach (var property in this.Properties)
// Customize storage name based on the JsonPropertyName attribute
if (clrProperty?.GetCustomAttribute<JsonPropertyNameAttribute>() is { } jsonPropertyNameAttribute
&& this.PropertyMap.TryGetValue(clrProperty.Name, out var property))
{
if (property.PropertyInfo?.GetCustomAttribute<JsonPropertyNameAttribute>() is { } jsonPropertyNameAttribute)
{
property.StorageName = jsonPropertyNameAttribute.Name;
}
property.StorageName = jsonPropertyNameAttribute.Name;
}
}

/// <summary>
/// Validates whether the given type is supported as a key property type.
/// Validates the key property, ensuring it is a supported type for Couchbase document IDs.
/// </summary>
/// <param name="type">The type to validate.</param>
/// <param name="supportedTypes">The supported types if validation fails.</param>
/// <returns>True if the type is supported, false otherwise.</returns>
protected override bool IsKeyPropertyTypeValid(Type type, [NotNullWhen(false)] out string? supportedTypes)
/// <param name="keyProperty">The key property to validate.</param>
protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
supportedTypes = "string";
base.ValidateKeyProperty(keyProperty);

// Couchbase primarily supports string keys for document IDs
return type == typeof(string);
if (keyProperty.Type != typeof(string))
{
throw new NotSupportedException($"Property '{keyProperty.ModelName}' has unsupported type '{keyProperty.Type.Name}'. Key properties must be of type string.");
}
}

/// <summary>
Expand Down
Loading
Loading