Skip to content

WHIZ071: Missing Pgvector Package

Verified by tests

VectorFieldPackageReferenceAnalyzerTests — library CI run #31657041675 (2026-08-13)

Severity: Error Category: Package Reference

Description

This error is reported by the VectorFieldPackageReferenceAnalyzer (in Whizbang.Data.EFCore.Postgres.Generators) when a perspective model property has the [VectorField] attribute but the project does not reference the base Pgvector package. This package is required for NpgsqlDataSourceBuilder.UseVector() support.

The check fires when a non-abstract class implements IPerspectiveFor<TModel, TEvent...> (or IPerspectiveWithActionsFor/IPerspectiveBase) whose model type has a [VectorField] property. It is reported once per compilation, at compilation end, with no source location. A [VectorField] on a model that no perspective uses does not trigger it.

Diagnostic Message

Perspective model uses [VectorField] but Pgvector package is not referenced. Add <PackageReference Include="Pgvector" /> to your project.

Updated

The diagnostic ID WHIZ071 is also used by Whizbang.Generators for an unrelated Info diagnostic, "Polymorphic Base Type Discovered" (see Polymorphic Serialization). If you see WHIZ071 as an informational build message rather than an error, it is that diagnostic, not this one.

Common Causes

  1. Forgot to add package reference - Added [VectorField] attribute but didn't install the required NuGet package
  2. Only installed EF Core package - Installed Pgvector.EntityFrameworkCore but not the base Pgvector package
  3. Package accidentally removed - Package reference was removed during dependency cleanup

How to Fix

Add the Pgvector package reference to your project:

Using .NET CLI

Using .NET CLI

dotnet add package Pgvector

Using Package Manager Console

Using Package Manager Console

Install-Package Pgvector

Using PackageReference in .csproj

Using PackageReference in .csproj

<ItemGroup>
  <PackageReference Include="Pgvector" Version="0.3.0" />
</ItemGroup>

Using Central Package Management

In Directory.Packages.props:

Using Central Package Management

<ItemGroup>
  <PackageVersion Include="Pgvector" Version="0.3.0" />
</ItemGroup>

In your project file:

Using Central Package Management (2)

<ItemGroup>
  <PackageReference Include="Pgvector" />
</ItemGroup>

Required Packages

When using [VectorField], you typically need both packages:

Required Packages

<ItemGroup>
  <!-- Base package for NpgsqlDataSourceBuilder.UseVector() -->
  <PackageReference Include="Pgvector" Version="0.3.0" />

  <!-- EF Core integration for type mapping and queries -->
  <PackageReference Include="Pgvector.EntityFrameworkCore" Version="0.3.0" />
</ItemGroup>

Code Example

Before (causes WHIZ071)

Before (causes WHIZ071)

// Missing: <PackageReference Include="Pgvector" />

public record ProductDto {
  [StreamId]
  public Guid Id { get; init; }
  public string Name { get; init; } = string.Empty;

  [VectorField(1536)]  // WHIZ071: Package not referenced
  public float[]? Embedding { get; init; }
}

// The model must be used by a perspective for the check to fire
public class ProductPerspective : IPerspectiveFor<ProductDto, ProductCreatedEvent> {
  public ProductDto Apply(ProductDto currentData, ProductCreatedEvent @event) => /* ... */;
}

After (compiles successfully)

After (compiles successfully)

// Added: <PackageReference Include="Pgvector" />

public record ProductDto {
  [StreamId]
  public Guid Id { get; init; }
  public string Name { get; init; } = string.Empty;

  [VectorField(1536)]  // Works - package is referenced
  public float[]? Embedding { get; init; }
}

Suppressing This Diagnostic

If you intentionally want to use [VectorField] without the Pgvector package (e.g., for testing or code generation scenarios), add the assembly-level suppression attribute (defined in Whizbang.Core.Perspectives). It disables this analyzer entirely (both WHIZ070 and WHIZ071):

Suppressing This Diagnostic

[assembly: SuppressVectorPackageCheck]

Pragma suppression does not work for this diagnostic — it is reported at compilation end with no source location, which #pragma warning regions cannot reach. To suppress it without the attribute, set the severity to none in a global analyzer config file:

Suppressing This Diagnostic (2)

# .globalconfig
is_global = true
dotnet_diagnostic.WHIZ071.severity = none

Why This Matters

The base Pgvector package provides:

  • Npgsql type handler - Enables Npgsql to read/write PostgreSQL vector types
  • UseVector() extension - Configures NpgsqlDataSourceBuilder for vector support
  • Vector type - The Pgvector.Vector type for direct vector manipulation

Without this package, Npgsql cannot serialize or deserialize vector data, leading to runtime errors when reading or writing vector columns.

  • WHIZ070 - Missing Pgvector.EntityFrameworkCore package (for EF Core integration)

See Also