Commit Graph
54 Commits
Author SHA1 Message Date
westey 58ad1a3780 .Net: Improve Milvus filtering (#14498)
### 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.
-->

### Description

Improve Milvus filtering to allow more id types to be supported

### Contribution Checklist

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

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2026-09-30 18:11:20 +00:00
Copilot 76b54649d6 remove migrated .NET MEVD providers, add redirect READMEs (#14193)
### Motivation and Context

All .NET MEVD vector store providers have been migrated to the
[CommunityToolkit/AI
repository](https://github.com/CommunityToolkit/AI). This removes the
now-redundant source code and tests from this repo and leaves
discoverable redirects in their place.

### Description

**Removed source + tests** for 12 providers (Chroma and Milvus kept
unchanged):
- **AzureAISearch, CosmosMongoDB, CosmosNoSql, InMemory, PgVector,
Qdrant, Redis, SqlServer, SqliteVec, Weaviate** → moved to
[CommunityToolkit/AI/MEVD/src/](https://github.com/CommunityToolkit/AI/tree/main/MEVD/src)
- **MongoDB** → moved to
[mongodb/mongo-mevd-provider](https://github.com/mongodb/mongo-mevd-provider)
- **Pinecone** → removed; Pinecone archived their [.NET
SDK](https://github.com/pinecone-io/pinecone-dotnet-client), no longer
supported
- **Common** → removed (was only shared by SqlServer/SqliteVec/PgVector,
all gone)

**Added `README.md`** in each removed provider directory pointing to the
new upstream location (or explaining Pinecone deprecation).

**Removed all associated test projects** including the shared
`VectorData.ConformanceTests` infrastructure (no remaining consumers
after provider removal).

**Updated `dotnet/MEVD.slnx`** — now contains only Chroma and Milvus.

### Contribution Checklist

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

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
2026-08-10 13:47:26 +00:00
westey 82f244233b .Net: Update SK to use MEVD packages and move MEVD projects out of main solution (#14117)
### Motivation and Context

- The MEVD packages are not shipped from this repo anymore.

### Description

- Moving the packages out of the main SK solution
- Update all projects to use MEVD.Abstractions package directly
- Revert some previous code changes to make the MEVD implementations
compatible with the last MEVD.Abstractions package released from this
repo.

### Contribution Checklist

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

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2026-06-24 16:51:21 +00:00
westey ba37e8e49b .Net: Add backslash escaping to redis text search values (#13902)
### Motivation and Context

### Description

- Add backslash escaping to redis text search values

### Contribution Checklist

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

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2026-04-21 14:17:31 +00:00
Shay RojanskyandCopilot bf1b19c84c .Net: Fix single-quote escaping in OBJECT_ID and dynamic SQL string literals (#13900)
In the SQL Server MEVD provider, table/schema/column names embedded
inside SQL string literals (`N'...'`) were not escaping single quotes.
This could produce broken SQL when names contain single quotes.

For example, a table named `it's` would generate:
```sql
IF OBJECT_ID(N'[dbo].[it's]', N'U') IS NULL
```
which is invalid SQL. The fix produces:
```sql
IF OBJECT_ID(N'[dbo].[it''s]', N'U') IS NULL
```

### Changes

Added `AppendTableNameInsideLiteral` and `AppendIdentifierInsideLiteral`
helper methods that escape single quotes by doubling them, and updated
the 5 call sites where identifiers appear inside string literals:

- `OBJECT_ID` in `CreateTable` (ifNotExists check)
- `OBJECT_ID` in full-text index PK lookup
- Dynamic SQL table name, column names, and catalog name for full-text
indexes

### Tests

Added unit tests for `AppendTableNameInsideLiteral`,
`AppendIdentifierInsideLiteral`, and a
`CreateTable_WithSingleQuoteInName` integration test. All 283 tests pass
(unit + conformance).

Co-authored-by: Copilot <[email protected]>
2026-04-21 12:28:39 +00:00
Shay RojanskyandCopilot 7e216a0f5c .Net: Update SQL Server vector search to latest VECTOR_SEARCH() syntax (#13863)
Updates the SQL Server vector store connector to support the latest
Azure SQL VECTOR_SEARCH() features, matching what was done in EF Core
(dotnet/efcore#38075).

## Changes

### VECTOR_SEARCH syntax update
- Replace deprecated `TOP_N` parameter with `SELECT TOP(N) WITH
APPROXIMATE`
- Enable iterative WHERE predicates are now applied during the vector
search process, not after retrievalfiltering
- Support `skip` via subquery wrapping (`TOP` and `OFFSET/FETCH` cannot
coexist in the same SELECT)

### Hybrid search
- Same VECTOR_SEARCH syntax changes in the semantic search CTE
- Filter support added in the vector search CTE (iterative filtering)

### Azure SQL runtime detection
- DiskAnn vector indexes and VECTOR_SEARCH require Azure SQL Database or
SQL database in Microsoft Fabric
- Added runtime check via `SERVERPROPERTY('EngineEdition')` at table
creation and query time
- Throws informative `NotSupportedException` when used against on-prem
SQL Server
- Result is cached per collection instance

### Test infrastructure
- Deleted `SqlServerDiskAnnVectorSearchTests.cs` (read-only table
workaround no longer tables with latest vector indexes now support full
DML)needed
- Created `SqlServerConnectionStringRequiredAttribute` to gate DiskAnn
tests on Azure SQL connection string availability
- Rewrote DiskAnn conformance test to handle 100-row minimum requirement
for vector index creation
- Updated all command builder unit tests for new SQL syntax

### Kept
- `PREVIEW_FEATURES` command in `CreateTable` (needed for future on-prem
SQL Server support)

---------

Co-authored-by: Copilot <[email protected]>
2026-04-16 07:15:46 +00:00
Copilotandadamsitnik 6ed2bb26d5 [MEVD] Fix VectorStoreKeyAttribute.IsAutoGenerated to be usable as a compile-time attribute argument (#13698)
### Motivation and Context

`VectorStoreKeyAttribute.IsAutoGenerated` was typed as `bool?`, which C#
does not permit as a compile-time attribute argument. This made the
following valid-looking code fail to compile:

```csharp
[VectorStoreKey(StorageName = "name", IsAutoGenerated = true)]
public Guid Key { get; set; }
```

### Description

- **`VectorStoreKeyAttribute.IsAutoGenerated`**: Changed from `public
bool?` to a `public bool` property. Its setter stores the value into a
new `internal bool? IsAutoGeneratedNullable` backing property. The
getter returns `IsAutoGeneratedNullable.GetValueOrDefault()` rather than
throwing; an inline comment explains this is a workaround for the C#
compiler restriction that prevents `Nullable<bool>` from being used as a
compile-time attribute argument. The `bool?` backing preserves the "not
explicitly set" vs. "explicitly set" distinction the framework relies
on.

- **`CollectionModelBuilder`**: Updated to read
`keyAttribute.IsAutoGeneratedNullable` (the `bool?` backing) instead of
the former `bool?` public property, keeping the existing `??
SupportsKeyAutoGeneration(...)` fallback behaviour intact.

- **`KernelFunctionFromMethod`**: Fixed a pre-existing operator
precedence bug in a pattern match expression (`value is not JsonElement
or JsonDocument or JsonNode`) that caused CS9336 redundant-pattern
errors on the .NET 10 compiler. Added parentheses to correctly express
the intended negation of all three types: `value is not (JsonElement or
JsonDocument or JsonNode)`.

- **`CollectionModelBuilderTests`**: Added four new unit tests covering
all `IsAutoGenerated` attribute scenarios: explicitly set to `true`,
explicitly set to `false`, omitted on a `Guid` key (fallback to
`SupportsKeyAutoGeneration` returns `true`), and omitted on an `int` key
(fallback returns `false`).

```csharp
// Now compiles and works correctly
[VectorStoreKey(IsAutoGenerated = true)]
public Guid Key { get; set; }

[VectorStoreKey(IsAutoGenerated = false)]
public Guid Key { get; set; }

[VectorStoreKey]  // IsAutoGeneratedNullable remains null, fallback to SupportsKeyAutoGeneration()
public Guid Key { get; set; }
```

### Contribution Checklist

- [x] The code builds clean without any errors or warnings
- [ ] 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
- [ ] I didn't break anyone 😄

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>[MEVD] Can't set IsAutoGenerated property of
VectorStoreKeyAttribute at compile time</issue_title>
> <issue_description>The following code fails to compile:
> 
> ```csharp
> [VectorStoreKey(StorageName = "name", IsAutoGenerated = true)]
> public Guid Key { get; set; }
> ```
> 
> Because the `IsAutoGenerated` is `bool?`:
> 
>
https://github.com/microsoft/semantic-kernel/blob/082e28e52ec2b45ad8cf287176d844150617e8b5/dotnet/src/VectorData/VectorData.Abstractions/RecordAttributes/VectorStoreKeyAttribute.cs#L30
> 
> Which in C# maps to `System.Nullable<bool>` (a struct) and can't be
set at compile time.
> 
> Could we make it just a `bool` like what it's mapped to at the end?
> 
>
https://github.com/microsoft/semantic-kernel/blob/082e28e52ec2b45ad8cf287176d844150617e8b5/dotnet/src/VectorData/VectorData.Abstractions/ProviderServices/KeyPropertyModel.cs#L18
> 
> Context:
https://github.com/dotnet/extensions/pull/7423/changes#r2974567816
> 
> cc @roji </issue_description>
> 
> <agent_instructions>1. Make
[this](https://github.com/microsoft/semantic-kernel/blob/082e28e52ec2b45ad8cf287176d844150617e8b5/dotnet/src/VectorData/VectorData.Abstractions/RecordAttributes/VectorStoreKeyAttribute.cs#L30)
property be a `bool` rather than `bool?` property.
> 2. Implement the getter and setter for it.
> 3. The setter should set an internal `bool?` property that should be
used instead of the public property everywhere in the repo.
[Example]https://github.com/microsoft/semantic-kernel/blob/082e28e52ec2b45ad8cf287176d844150617e8b5/dotnet/src/VectorData/VectorData.Abstractions/ProviderServices/CollectionModelBuilder.cs#L162)
> 3. Proof of concept code that I've used to verify it's going to get us
what we need:
> 
> ```csharp
> using System.Reflection;
> 
> namespace ConsoleApp15
> {
>     public class Program
>     {
>         static void Main()
>         {
> TestAttribute setToTrue =
typeof(Program).GetMethod(nameof(SetToTrue))!.GetCustomAttribute<TestAttribute>()!;
> Console.WriteLine($"IsAutoGenerated_Core for [Test(IsAutoGenerated =
true)]: {setToTrue.IsAutoGenerated_Core}");
> 
> TestAttribute setToFalse =
typeof(Program).GetMethod(nameof(SetToFalse))!.GetCustomAttribute<TestAttribute>()!;
> Console.WriteLine($"IsAutoGenerated_Core for [Test(IsAutoGenerated =
false)]: {setToFalse.IsAutoGenerated_Core}");
> 
> TestAttribute notSet =
typeof(Program).GetMethod(nameof(NotSet))!.GetCustomAttribute<TestAttribute>()!;
> Console.WriteLine($"IsAutoGenerated_Core for [Test]:
{notSet.IsAutoGenerated_Core}");
>         }
> 
>         [Test(IsAutoGenerated = true)]
>         public static void SetToTrue() { }
> 
>         [Test(IsAutoGenerated = false)]
>         public static void SetToFalse() { }
> 
>         [Test]
>         public static void NotSet() { }
>     }
> 
>     [AttributeUsage(AttributeTargets.All)]
>     public class TestAttribute : Attribute
>     {
>         public bool IsAutoGenerated
>         {
> get => throw new InvalidOperationException(); // provided to satisfy
compiler requirements
>             set => IsAutoGenerated_Core = value;
>         }
> 
>         internal bool? IsAutoGenerated_Core { get; set; }
>     }
> }
> ```</agent_instructions>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes microsoft/semantic-kernel#13697

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Send tasks to Copilot coding agent from
[Slack](https://gh.io/cca-slack-docs) and
[Teams](https://gh.io/cca-teams-docs) to turn conversations into code.
Copilot posts an update in your thread when it's finished.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: adamsitnik <[email protected]>
2026-03-23 19:35:05 +00:00
Shay Rojansky 082e28e52e .Net: Remove legacy filtering from MEVD providers (#13636)
Removes all legacy filtering logic from MEVD, leaving only (obsoleted)
FilterClause and subclasses, which are still needed by ITextSearch (see
conversation in
https://github.com/microsoft/semantic-kernel/pull/13384#discussion_r2867207653).

As suggested by @westey-m let's do an SK release before merging this
(see above).

Closes #10456

/cc @alzarei
2026-03-21 07:51:42 +00:00
TsengSRandwestey 41cc2487d2 .Net: Fixes Qdrant 1.17 issue with returning empty vectors (#13638)
### Motivation and Context

With Qdrant server 1.17 Embeddings stopped being returned.  

Fixes #13587



### Description

The `VectorOutput.Data` property became deprecated in `Qdrant.Client`
1.17. The alternative is to use `VectorOutput.Dense.Data` instead or
`VectorOutput.GetDenseVector()` (from `Qdrant.Client` 1.16.0 or later).

Since the `.Dense` already exyists in `Qdrant.Client` 1.15.1 that is
used by the current connector, I used these. The `.GetDenseVector()`
also returns nullable `DenseVector`, so I was unsure how to handle in
context of Semantic Kernel, as as far as I see it Semantic Kernel only
supports Dense Vectors (the other two are `.Sparse` for sparse vectors
and `.MultiDense`).

So this may need special handling in future to throw an exception, when
the server returns one of the other two vector types and not dense
vectors.

### 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

I'm currently unable (or rather I don't know how) to run the local
integration/unit tests against the qdrant database. But I validated the
change in my personal project mentioned in #13587 by directly
referencing the connector in my project and it correctly returned the
vectors on the sample code where it failed previously

```csharp
    VectorStoreCollection<ulong, VectorModels.Project> projects = await GetProjectsCollection();
    VectorModels.Project? project = await projects.GetAsync((ulong)projectId, new()
    {
        IncludeVectors = true
    });

    // project at this poind hat 0 sized Embedding property
    if (project is null)
    {
        return;
    }
    await projects.UpsertAsync(project);
```

---------

Co-authored-by: westey <[email protected]>
2026-03-18 19:35:06 +00:00
Shay Rojansky b36a327d76 .Net: Fix input checking in Cosmos NoSQL, Redis and Weaviate providers (#13629) 2026-03-04 10:52:33 +00:00
Shay Rojansky e9641a9106 .Net: Fix column nullability in SQL MEVD providers (#13622)
Closes #12560
2026-03-04 08:41:41 +00:00
Shay Rojansky 781881a34f .Net: Deduplicate embedding generation management (#13615)
Closes #12508
2026-03-02 13:15:56 +00:00
Shay Rojansky 74d4310fd4 .Net: Handle installation of pgvector on PostgreSQL (#13600) 2026-02-27 09:23:23 +00:00
Shay Rojansky f077655fd6 .Net: [MEVD] Add validation for mismatched collection key (#13594)
Closes #11355
2026-02-26 11:19:03 +00:00
Shay Rojansky f59e395230 .Net: [MEVD] Make PG schema nullable (#13593)
Closes #10853
2026-02-25 19:47:14 +00:00
Shay RojanskyandMark Wallace ea864bf697 .Net: [MEVD] Support DateTime/DateTimeOffset/DateOnly/TimeOnly across providers (#13569)
See
https://github.com/microsoft/semantic-kernel/issues/11286#issuecomment-3904027209
for some design notes.

Closes #11286
Closes #11086

---------

Co-authored-by: Mark Wallace <[email protected]>
2026-02-25 13:45:19 +00:00
Shay Rojansky c086d09442 .Net: [MEVD] SQL Server approximate vector search (#13573)
Closes #13270
2026-02-23 10:50:29 +00:00
Shay Rojansky 9f2dafca48 .Net: [TINY] [MEVD] Remove SupportsMultipleKeys (#13572)
We have the model building option SupportsMultipleKeys to allow multiple
(composite) keys, but no provider uses them at this point (note that
Cosmos NoSQL has a sort of composite key - document + partition key, but
does not go through this support in any case).

Removing this - we can always add it when we actually need to support it
(and providers aren't blocked from implementing composite keys if they
really want to).
2026-02-19 19:07:35 +00:00
Shay Rojansky 8513c2ac00 .Net: [MEVD] Cosmos NoSQL provider work on keys, partition keys and point reads (#13550)
This is a sizable cleanup/redo of large chunks of the Cosmos NoSQL
provider; I've broken it down to three commits for easier reviewing.

* Cosmos NoSQL collections can now have either string/Guid as their key,
or CosmosNoSqlKey. In the former case, this configures the partition key
to be the same as the string/Guid document key - this is a sensible
default that's common (and encouraged) in Cosmos. All other scenarios
require CosmosNoSqlKey:
    * A single partition key that isn't the document ID
    * A hierarchical partition key (more than one property)
    * No partition key (legacy/discouraged)
* Note that CosmosNoSqlKey is only passed to GetAsync and DeleteAsync;
on the user's .NET record type, the properties are there as usual (e.g.
a string document Id property, an int partition key property). This
introduces a discrepancy for the first time between the collection's
TKey (CosmosNoSqlKey) and its actual key property on the .NET type (a
string); this made some things trickier, but is the correct way to do
things for composite key cases (we'd do the same if we implement
composite keys for relational providers).
* Added support for Cosmos hierarchical partition keys (2-3 properties
instead of just one).
* GetAsync no longer does a SQL query with a WHERE clause, but rather an
efficient point read via ReadItem. The multiple-key overload does
ReadManyItemsAsync, which again is far more efficient.
* UpdateAsync and DeleteAsync now correctly supply the partition key in
the call's request options, again making it much more efficient.
* Various other cleanup and fixes all around.
2026-02-17 13:57:34 +00:00
Shay Rojansky c6f07d65f4 .Net: Implement SQL Server hybrid search (#13512)
Closes #11080
2026-02-11 10:54:47 +00:00
Shay Rojansky e8b4862d03 .Net: [MEVD] Map DateTime to timestamptz on PostgreSQL (#13514)
DateTime now maps to the PG timestamptz type by default, which
represents a UTC timestamp; this aligns with Npgsql and EF Core.

However, now that we have property annotations, I've also added a new
`WithStoreType()` that allows the user to specify a database type
explicitly. For now, this is only supported for setting `timestamp with
time zone` (short: `timestamp`), which is the other PG date/time type,
for unspecified timestamps (timezone is unknown or implicitly assumed).
This allows users who do want to store non-UTC timestamp to do so.

Closes #10641
2026-02-11 10:54:37 +00:00
Shay Rojansky b0d621f2a6 .Net: Implement PostgreSQL hybrid search (#13502)
**Note: this PR is based on top of #13501, skip first commit**

And add provider-specific annotation support

Closes #11084
Closes #10359
2026-02-05 17:52:16 +00:00
Shay Rojansky 7d7a6494e5 .Net: [MEVD] Implement support for score threshold (#13501)
For providers which don't natively support score threshold, I've gone
with applying the filter client-side - the other option would be to
throw.
* In EF we're quite strict on not bringing back database data in order
to client-evaluate; in other words, if the user wants to load database
rows from the database and then perform some post-filtering, they need
to write that explicitly in code, to avoid scenarios where tons of data
gets unintentionally transferred.
* In MEVD we already implement Skip in various providers by bringing
back the entire matching resultset and then filtering client-side. This
is potentially much worse than filtering for score threshold
client-side, as the amount of extra data brought back by threshold
post-filtering is limited to top (k), whereas with Skip/pagination
queries that amount of data grows with each page.
* Ultimately, MEVD is simpler and more high-level, and is also
explicitly designed for layers to be composed on top (e.g. MEDI). So
there does seem to be more value in features "just working" across
providers.

Closes #9566
2026-02-05 14:45:28 +00:00
Shay Rojansky d3ac002ac9 .Net: Remove old MEVD integration tests (#13484)
And port a few missing cases to the new compliance tests.

Closes #12506
2026-01-29 13:36:45 +00:00
Shay Rojansky 7918395b47 .Net: [MEVD] Implement key auto-generation (#13466)
* Adds IsAutoGenerated to key property definition and attribute.
* When auto-generation is on, saving a record where the key property is
the default (empty GUID, zero integer) triggers the auto-generation.
It's still possible to set the key property to a non-default value,
overriding the auto-generation.
* Auto-generation can happen in the database (mainly on the relational
databases), or on the cilent side (Guid.NewGuid()).
* IsAutoGenerated is null by default, meaning that the provider decides
whether to turn on autogeneration by default, based on the property
type. This means that GUID properties are always auto-generated by
default (if the key property is left unassigned), and int/long
properties are auto-generated on relational providers. This aligns with
the behavior in Entity Framework.
* All providers support GUID generation, by doing it on the client
before sending the record (Guid.NewGuid()). Some providers have special
behavior, e.g. PG generates UUIDv7 and SQL Server generates sequential
IDs in the database (much better for indexing). Universal GUID
auto-generation makes things much simpler for upper layers, specifically
Microsoft.Extensions.DataIngestion.

Closes #11485
2026-01-28 09:31:06 +00:00
Shay Rojansky fe11ab6ab5 .Net: [MEVD] Support .Any(x => x.Contains(...)) in filters (#13471)
~**NOTE: This PR is based on top of #13470, review 2nd commit only**~

Closes #13152
2026-01-27 16:53:00 +00:00
Shay Rojansky 5794549af7 .Net: [MEVD] Ensure identifiers are properly quoted (#13470)
Closes #12161
2026-01-27 07:35:52 +00:00
Shay RojanskyandMark Wallace 3ce1a84d3b .Net: Use testcontainer for SQL Server 2025 (#13465)
And allow pointing to an external database via environment variable on
SQL Server and PostgreSQL for faster iteration.

Test-only change.

---------

Co-authored-by: Mark Wallace <[email protected]>
2026-01-26 17:49:43 +00:00
4e0ccb9c43 .Net: Switch MEVD MongoDB Driver to v3.51 (#13370)
### Motivation and Context

Switches the MongoDB Driver to the latest 3.5 release which had a number
of breaking changes.

This affects both the MongoDB vector data project and the CosmosMongoDB
project.

This fixes #11652 and likely addresses  #12707 and partly #10291.

### Description

Switches the MongoDB driver to 3.5. Part of the breaking changes is that
GUIDs in BSON no longer have a default storage format specified due to
the need to switch from the C#-only format to the cross-MongoDB-driver
standard format. Setting this is achieved in this PR by way of both a
convention for the registry based mode and an alternative to
BsonValue.Create in the scenarios where we don't have access to
conventions/serialization such as key creation and using the dynamic
mapper.

### Contribution Checklist

- [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 😄


cc @roji

---------

Co-authored-by: Arthur Vickers <[email protected]>
Co-authored-by: Mark Wallace <[email protected]>
Co-authored-by: westey <[email protected]>
Co-authored-by: Roger Barreto <[email protected]>
Co-authored-by: Shay Rojansky <[email protected]>
2025-12-13 08:11:35 +00:00
Stephen Toub b50299be6d Upgrade to .NET 10 (#13395) 2025-12-01 17:08:24 +00:00
Adam SitnikandShay Rojansky de20575aee Fixes to Get/Delete for Guid keys (#13353)
This PR fixes a bug reported offline by @jeffhandley 

```log
fail: Microsoft.Extensions.DataIngestion.IngestionPipeline[6]
      An error occurred while ingesting document 'Example_GPS_Watch.md'.
      System.InvalidCastException: Unable to cast object of type 'System.Guid' to type 'System.String'.
         at System.Linq.Enumerable.CastICollectionIterator`1.MoveNext()
         at Azure.Search.Documents.Models.IndexDocumentsBatch.Delete(String keyName, IEnumerable`1 keyValues)
         at Azure.Search.Documents.SearchClient.DeleteDocumentsAsync(String keyName, IEnumerable`1 keyValues, IndexDocumentsOptions options, CancellationToken cancellationToken)
         at Microsoft.Extensions.VectorData.VectorStoreErrorHandler.RunOperationAsync[TResult,TException](VectorStoreCollectionMetadata metadata, String operationName, Func`1 operation)
         at Microsoft.Extensions.DataIngestion.VectorStoreWriter`1.WriteAsync(IAsyncEnumerable`1 chunks, CancellationToken cancellationToken)
         at Microsoft.Extensions.DataIngestion.IngestionPipeline`1.IngestAsync(IngestionDocument document, Activity parentActivity, CancellationToken cancellationToken)
         at Microsoft.Extensions.DataIngestion.IngestionPipeline`1.ProcessAsync(IEnumerable`1 files, Activity rootActivity, CancellationToken cancellationToken)+MoveNext()
```

---------

Co-authored-by: Shay Rojansky <[email protected]>
2025-11-13 11:05:42 +00:00
Shay Rojansky eab8c88983 .Net: [MEVD] Fix Guid (and other) keys for dynamic collections (#13341)
Closes #13340
2025-11-07 15:37:20 +00:00
Shay Rojansky a5810db1df .Net: Final test cleanup (#13328)
I think this completes the cleanup work I had planned on the tests.
2025-11-06 09:07:27 +00:00
Shay Rojansky 3eb869e1e8 .Net: [MEVD] More test cleanup (#13320)
Another batch of test cleanup work - this almost concludes what I have
planned for the tests.

* We no longer create any collections with GUID names; all collections
have a manually-defined name, and are deleted when a test starts
running. This ensures that no collections are left behind if a test
crashes or is stopped in the middle, and makes it easier to examine the
database.
* Removed global SimpleRecord and SimpleFixture, each test suite now has
its own record and fixture.
* Cleaned up and renamed DistanceFunctionTests to only focus on testing
the different distance functions, and added corresponding tests
elsewhere.
* Added IndexKindTests to specifically cover different index types.
2025-11-03 16:04:54 +00:00
Shay Rojanskyandwestey d595e48e14 .Net: [MEVD] Fix dynamic batching APIs for PostgreSQL (#13323)
Fixes #13303

---------

Co-authored-by: westey <[email protected]>
2025-11-03 14:58:22 +00:00
Shay Rojansky ad97c3a654 .Net: [MEVD] Support BinaryEmbedding with PostgreSQL (#13322)
The main motivation here was to ensure that our infrastructure and tests
properly support binary embeddings (and more in general, non-float/half
ones).

Closes #13321
2025-11-03 14:02:44 +00:00
Shay Rojansky a39b2ba476 .Net: [MEVD] Conformance tests for multi-vector records (#13319)
Closes #11709
2025-11-03 10:05:59 +00:00
Shay Rojansky b697358398 .Net: [MEVD] Go over all key types, add support for Guid (#13315)
* Added new KeyTypeTests to cover provider key support, alongside the
existing DataTypeTests and EmbeddingTypeTests; moved all three into
TypeTests folder.
* As discussed offline, this adds Guid-as-string key support for all
providers. From research this seems to be very standard practice across
a wide range of databases: JSON-based databases generally encode various
types (e.g. DateTime) as string, and Guids are standard there. Sqlite is
similar, with Microsoft.Data.Sqlite supporting it natively. This notably
allows upper layers to assume that they can always use Guid, which helps
MEDI ([see this
issue](https://github.com/dotnet/extensions/issues/6973)).
* Per-provider notes
* Azure AI Search: string only supported, added Guid-as-string as an
option
([docs](https://learn.microsoft.com/en-us/rest/api/searchservice/data-type-map-for-indexers-in-azure-search#bkmk_sql_search)
encouraging mapping Guid to strings)
* MongoDB/CosmosMongoDB: Added int and long support (Guid was already
supported).
    * CosmosNoSql: Added Guid-as-string (standard practice)
    * Pinecone: Added Guid-as-string
    * Redis: Added Guid-as-string
* SQL Server: removed DateTime and `byte[]` as key types (as above) and
added Guid.
* SQLite: The Microsoft.Data.Sqlite (the low-level ADO.NET provider
we're built on top of) supports GUIDs as TEXT; so it's really not us
deciding to support - it's the lower-level driver. In addition, we
support mapping boolean to INTEGER (1/0), which seems similar. Added
support as data property as well, not just key.

Closes #11784
Closes #12182
2025-10-31 12:19:34 +00:00
Shay Rojansky cc43169f44 .Net: [MEVD] Test cleanup pack (#13307)
This is an (almost) entirely test-only cleanup (I plan to do a bit more
later).

* Remove BasicQueryTests, rename BasicFilterTests to FilterTests and
move out to the root
* BasicFilterTests and BasicQueryTests both run the same filter
scenarios, the former via SearchAsync and the latter via filtering
GetAsync. Although in theory, some filter query construct could work in
one but not in the other, in practice no such example exists in the 12
providers we have (all databases use the same filter language/engine for
both APIs. So we had needless duplication for all the various test
exceptions/customizations, which had to be overridden in exactly the
same way in both test suites.
* At least for now, decided to remove BasicQueryTests as it adds
maintenance burden without any real coverage; coverage (included missing
coverage) specifically for filtered GetAsync was added separately (e.g.
we weren't testing ordering, skip/take with filtered get).
* If we do want to add back support for all query constructs (I'd want
to have a good reason to do so), I'd do that within FilterTests: just
like each scenario already exercises both static and dynamic models, it
could run GetAsync as well.
* Renamed CollectionConformanceTests to CollecitonManagementTests and
moved it out to the root.
* In general, this PR removes "Conformance" from the test type names.
* Big cleanup/refactor of all the so-called CRUD tests.
* We now have a ModelTests folder with a test suite for each different
model; BasicModelTests covers Get/Upsert/Delete (and their batching
variants) for the basic scenario (strongly-typed model with data
properties and a single vector property). Alongside that we have
DynamicModelTests, NoDataModelTests, NoVectorModelTests (I'll be added
MultipleVectorsModelTests).
* These tests no longer use random GUIDs for the collection name
(difficult to debug, the collection never gets cleaned up if the test
crashes/is stopped in the middle), but rather has fixed names per test
suite.
* The collection is created once per test suite, but cleared and
reseeded between each test run, providing full isolation (previously we
had no isolation, and documented each record in the seed data as
belonging to this scenario or that - which is brittle).
    * Many other small improvements and cleanup.

Part of #12507
2025-10-29 18:04:44 +00:00
Shay Rojansky c79c269794 .Net: [MEVD] Fix filtering by true (#13294)
Fixes #13293
2025-10-28 16:58:02 +00:00
Shay Rojansky 3bc2a64fca .Net: [MEVD] [SQL Server] Support DateTimeOffset and string arrays (#13269)
Closes #13268

/cc @yorek @uc-msft (this uses JSON and JSON_CONTAINS() to map
`string[]` to the database and perform Contains over them.
2025-10-23 13:04:22 +00:00
Shay Rojansky 7fbe0374b3 .Net: [MEVD] [SQLServer] Switch from JSON to the new binary SqlVector (#13266)
Update SqlClient to 6.1.2 and use the new `SqlVector<float>` type, which
allows efficient binary encoding of vector data (rather than the
previous JSON-basd transfer).

Closes #12220

/cc @yorek
2025-10-23 11:38:20 +00:00
Shay Rojansky 1761c6864e .Net: [MEVD] Support MemoryExtensions.Contains in LINQ filters (#13263)
This makes the provider filters compatible with C# 14 (see #12504, and
https://github.com/dotnet/runtime/issues/109757 on the runtime side).
Note that this changes the entire repo to build with dotnet SDK 10.0
(rc2) - that's probably a good idea regardless to test with the latest,
ensure compatibility etc. (but if this is problematic, let me know -
it's only truly necessary for test coverage and can be reverted).

I'm not happy to have the implementation duplicated across the
implementations: we have FilterTranslationPreprocessor for common LINQ
filter preprocessing, and that would be the ideal place for this.
However, rewriting MemoryExtensions.Contains to Enumerable.Contains
would require doing MethodInfo.MakeGenericMethod which is incompatible
with NativeAOT. I considered have a fake, non-invocable MethodInfo
implementation to represent the closed generic MethodInfo to
Enumerable.Contains (MethodInfo and Type are abstract, so we can create
custom implementations compatible with NativeAOT), but that's quite
involved/complicated. The better story here is probably to have a base
class implementation for the provider filter processors, which
recognizes specific patterns and dispatches to abstract handlers which
specific implementations override; it would take care of recognizing the
various Contains variants.

Note also that we already have duplication around Enumerable.Contains
and List.Contains (the instance method), so this just adds another
variant (for now). I'll think about cleaning this up.

Fixes #12504
2025-10-23 10:35:21 +00:00
Davide Mauriandwestey 27e8457fda .Net: Fixed sorting for negative DOT product (#13071)
### Motivation and Context

When using negative dot product scoring, the more negative the value,
the closer the vector is to the query vector.

### Description

Fixed the sorting used for negative dot product distance calculations

### Contribution Checklist

- [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 😄

---------

Co-authored-by: westey <[email protected]>
2025-09-10 11:54:36 +00:00
Damien Guard 38a7d91785 .Net: Fix MongoDB test container ready detection (#13026)
### Motivation and Context

To fix unreliable MongoDB Test Container start-up. 

Fixes #13025

### Description

TestContainers.NET is, by default checking, for the string `Waiting for
connections` to appear TWICE in the MongoDB logs before deciding the
container is available. While this can happen quite often it doesn't
**always** happen and I believe this is a mistake (introduced in a large
PR).

TestContainers clients for Go and Rust only check the message appears
once (and TestContainers for Java has a different mechanism altogether).

This introduces an alternative waiting mechanism until I can get the fix
shipped upstream that only checks the message appears once.

Note: This PR does not yet enable the MongoDB tests as I think there are
some other intermittent issues relating to the use of lock/counting
mechanism that sometimes responds with a very different error.

### Contribution Checklist

- [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 😄
2025-08-29 14:42:55 +00:00
0a98c72a37 .Net: Add support for Guid and ObjectID keys in the MongoDB Connector (#12827)
### Motivation and Context

The MongoDB connector currently only supports string key types.

### Description

Adds support for Guid and ObjectId key types to the MongoDB Connector. 

### Contribution Checklist

- [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 😄

---------

Co-authored-by: SergeyMenshykh <[email protected]>
Co-authored-by: westey <[email protected]>
2025-08-18 09:09:54 +00:00
westey 4b60913242 .Net: Fix serialization/deserialization bug in InMemory VectorStore Extensions (#12878)
### Motivation and Context

- Fixes #12826

### Description

- Fixing bug where serialized data includes updated internal storage
type but deserialization did not.

### Contribution Checklist

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

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2025-08-11 09:39:44 +00:00
Damien Guard 482ca5d774 .Net: Allow the MongoDB VectorData tests to run without an image (#12860)
### Motivation and Context

We are running the SK tests in our
https://github.com/mongodb-labs/ai-ml-pipeline-testing repo and would
like to also be able to run them against live MongoDB Atlas clusters for
further verification rather than just the Docker image.

### Description

The PR adjusts the vector data tests (only as per @roji recommendation)
so that if an environment variable named `MONGODB__CONNECTIONURL` exists
then that is used to connect to MongoDB rather than using TestContainers
to fire up a Docker image of MongoDB Atlas.

Additionally to improve reliability it was found that we need to
increase the number of attempts to wait for the data to be ready after
creating an index. (Bumped from 20 to 200). We're going to look at
adding index status helper methods in the C# Driver going forward for a
better experience.

Once this is done we should be able to fully enable the new tests on our
repo and diagnose any further instabilities and then be able to submit a
PR to fully-enable the image-based tests here.

### 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 😄
2025-08-06 10:47:36 +00:00
SergeyMenshykh bb67609a5e .Net: Prepare code for A2A SDK and AsyncEnumerable NuGet update (#12842)
### Motivation, Context and Description
This PR prepares the SK codebase for a future update of the A2A agent to
the new A2A .NET SDK and establishes the foundation for easy adoption of
the System.Linq.AsyncEnumerable package when it released. This will
completely eliminate the need for the AsyncEnumerable polyfills that SK
currently uses.

As part of this preparation, this PR stops using of the
System.Linq.Async package and replaces all SK calls to its APIs with
either equivalent calls to the AsyncEnumerable polyfills or in-place
implementations. This prevents "The call is ambiguous between..." name
conflicts that would occur when the AsyncEnumerable APIs from the A2A
.NET SDK's transitive dependency (System.Linq.AsyncEnumerable) become
available to the Agents.UnitTests project, which already contains
equivalent APIs from either AsyncEnumerable polyfills and/or the
System.Linq.Async package brought in from other projects that have the
Agents.UnitTests project specified as "InternalVisibleTo".

As a result, almost all non-production code (tests and samples) uses
AsyncEnumerable APIs from the preview version of the
System.Linq.AsyncEnumerable package, while production code uses either
AsyncEnumerable APIs from polyfills or uses in-place implementations.
2025-08-06 08:56:36 +00:00
Shay Rojansky cd34dcd591 .Net: Add MEVD TestSuiteImplementationTests (#12574)
I noticed that actual test suite implementation is a bit spotty across
providers; so this adds a test suite which tests that all other test
suites are implemented. We have this in the EF tests as well, also as a
way of letting provider maintainers know when a new test suite is
introduced which they probably want to implement. Of course, providers
can explicitly ignore specific test suites which don't make sense for
them.

Part of #10194
2025-07-24 10:52:50 +00:00