dotnet / dotnet/extensions

aichatweb template: generated project throws "generic key type is 'String', but the key property 'Key' has type 'Guid'"

Open
#7,734 0 comments 0 reactions 0 assignees View on GitHub
bug untriaged
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Description

A project scaffolded with `dotnet new aichatweb --provider azureopenai` (template `Microsoft.Extensions.AI.Templates` `10.9.0-preview.3.26411.16`, default `--vector-store local`, which now maps to `CommunityToolkit.VectorData.SqliteVec`) throws on the first chat/search request:

```
System.InvalidOperationException: The collection's generic key type is 'String', but the key property 'Key' has type 'Guid'. The generic key type must match the key property type.
```

The generated code is internally inconsistent about the vector-store key type:

| Generated file | Key type used |
| --- | --- |
| `Services/IngestedChunk.cs` | `public required Guid Key { get; set; }` |
| `Program.cs` | `builder.Services.AddSqliteCollection(...)` |
| `Services/SemanticSearch.cs` | `VectorStoreCollection` |
| `Services/Ingestion/DataIngestor.cs` | `new VectorStoreWriter(...)`, `new IngestionPipeline(...)` |

The record's `[VectorStoreKey]` property is `Guid`; everything that binds the collection uses `string` as `TKey`. SqliteVec validates that these match (`SqliteModelBuilder.ValidateKeyProperty`) and throws when building the model.

Image

### Reproduction Steps

### Reproduce via the template

1. `dotnet new install Microsoft.Extensions.AI.Templates::10.9.0-preview.3.26411.16`
2. `dotnet new aichatweb --provider azureopenai -o ReproGuid`
3. Set `AzureOpenAI:Endpoint` + chat/embedding deployment names, then `dotnet run`
4. Send any chat message. The exception is thrown from `SemanticSearch` the first
time the collection is resolved. (`dotnet build` succeeds — this is runtime only.)

```
Unhandled exception. System.InvalidOperationException: The collection's generic key type is 'String', but the key property 'Key' has type 'Guid'. The generic key type must match the key property type.
at Microsoft.Extensions.VectorData.ProviderServices.CollectionModelBuilder.ValidateKeyProperty(KeyPropertyModel keyProperty)
at CommunityToolkit.VectorData.SqliteVec.SqliteModelBuilder.ValidateKeyProperty(KeyPropertyModel keyProperty) in /home/runner/work/AI/AI/MEVD/src/SqliteVec/SqliteModelBuilder.cs:line 25
at Microsoft.Extensions.VectorData.ProviderServices.CollectionModelBuilder.ValidateProperty(PropertyModel propertyModel, VectorStoreCollectionDefinition definition)
at Microsoft.Extensions.VectorData.ProviderServices.CollectionModelBuilder.Validate(Type type, VectorStoreCollectionDefinition definition)
at Microsoft.Extensions.VectorData.ProviderServices.CollectionModelBuilder.Build(Type recordType, Type keyType, VectorStoreCollectionDefinition definition, IEmbeddingGenerator defaultEmbeddingGenerator)
at CommunityToolkit.VectorData.SqliteVec.SqliteCollection`2..ctor(...)
at CommunityToolkit.VectorData.SqliteVec.SqliteVectorStore.GetCollection[TKey,TRecord](String name, VectorStoreCollectionDefinition definition) in /home/runner/work/AI/AI/MEVD/src/SqliteVec/SqliteVectorStore.cs:line 69
at Program.$(String[] args)
```

Image

### Expected behavior

The scaffolded project builds and runs; document ingestion and semantic search work out of the box.

### Actual behavior

`InvalidOperationException` the first time the `IngestedChunk` collection is built, because the `[VectorStoreKey]` property is `Guid` while the collection is bound with `string` as `TKey`.

### Regression?

Appears to be fallout from the DataIngestion key-type migration from `string` to auto-generated `Guid` keys (#7410, #7396, #7557). `Services/IngestedChunk.cs` was updated to `Guid Key`, but `Program.cs` / `SemanticSearch.cs` / `DataIngestor.cs` and the pinned `Microsoft.Extensions.DataIngestion` version were not.

### Known Workarounds

Make the key type consistent. The only variant that compiles against the pinned
package set is `string` — change `IngestedChunk.Key` back to `string`:

```csharp
[VectorStoreKey(StorageName = "key")]
[JsonPropertyName("key")]
public required string Key { get; set; }
```

Going the other way (`AddSqliteCollection`, `VectorStoreCollection`, `VectorStoreWriter`, `IngestionPipeline`) does **not** compile with `Microsoft.Extensions.DataIngestion` `10.9.0-preview.1.26411.16`, because `SemanticSimilarityChunker` is `IngestionChunker` there:

```
error CS1503: Argument 2: cannot convert from
'Microsoft.Extensions.DataIngestion.Chunkers.SemanticSimilarityChunker' to
'Microsoft.Extensions.DataIngestion.IngestionChunker'
```

### Configuration

- Template: `Microsoft.Extensions.AI.Templates` `10.9.0-preview.3.26411.16`
- .NET SDK: `10.0.400`
- `--provider azureopenai`, `--vector-store local` (SqliteVec), no Aspire
- Generated package references:
- `Microsoft.Extensions.AI` / `Microsoft.Extensions.AI.OpenAI` `10.9.0`
- `Microsoft.Extensions.DataIngestion` / `.Markdig` `10.9.0-preview.1.26411.16`
- `CommunityToolkit.VectorData.SqliteVec` `1.0.1-preview`
- `Microsoft.Extensions.VectorData.Abstractions` `10.7.0` (transitive)
- OS: macOS 12.7.6 (x64). Isolated repro is OS-independent.

### Other information

`dotnet build` on the generated project succeeds; the failure is purely at runtime when the SqliteVec model is built (eagerly in `GetCollection`, or lazily via `SemanticSearch` in the template).

Contributor guide

Open the contributing guide

Research direction

Start with the generated Services/IngestedChunk.cs, Program.cs, Services/SemanticSearch.cs, and Services/Ingestion/DataIngestor.cs, then check the pinned Microsoft.Extensions.DataIngestion version and its SemanticSimilarityChunker type. Reproduce with the listed dotnet new and runtime steps, and verify that the generated project builds, starts, ingests documents, and completes a semantic search without the key-type exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sqlite
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.