Skip to content

Fix type mismatches for nullable dimensions and context_limit fields#20

Merged
awagner-mainz merged 5 commits intomainfrom
copilot/fix-compilation-errors
Feb 10, 2026
Merged

Fix type mismatches for nullable dimensions and context_limit fields#20
awagner-mainz merged 5 commits intomainfrom
copilot/fix-compilation-errors

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Migration 004 made dimensions and context_limit nullable in the definitions table, but generated models still used int32 instead of pgtype.Int4, causing compilation errors when assigning values.

Changes

  • Migration: Added 005_make_dimensions_nullable.sql to make instances.dimensions nullable (was only done for definitions)
  • Models: Regenerated with sqlc to reflect nullable schema: dimensions and context_limit are now pgtype.Int4 in both Definition and Instance structs
  • Type conversions: Updated 8 locations across handlers to properly convert between API layer (int32) and database layer (pgtype.Int4)
  • Null safety: Added validation checks before accessing .Int32 on nullable fields in critical paths (embedding validation, similarity search)

Pattern

// Before (compilation error)
Dimensions: int32(input.Body.Dimensions)

// After (nullable-aware)
Dimensions: pgtype.Int4{Int32: int32(input.Body.Dimensions), Valid: input.Body.Dimensions != 0}

// Reading back (with null check where required)
if !instance.Dimensions.Valid {
    return huma.Error500InternalServerError("dimensions not configured")
}
dimension := instance.Dimensions.Int32

Enables database migration from v003 schemas where these fields may be unset.

Original prompt

With the current code, there are errors in compiling:

# github.com/mpilhlt/embapi/internal/handlers
internal/handlers/llm_services.go:77:22: cannot use int32(input.Body.Dimensions) (value of type int32) as pgtype.Int4 value in struct literal
internal/handlers/llm_services.go:78:22: cannot use int32(input.Body.ContextLimit) (value of type int32) as pgtype.Int4 value in struct literal
internal/handlers/llm_services.go:180:21: cannot use def.Dimensions (variable of struct type pgtype.Int4) as int32 value in struct literal
internal/handlers/llm_services.go:181:21: cannot use def.ContextLimit (variable of struct type pgtype.Int4) as int32 value in struct literal
internal/handlers/llm_services.go:595:28: cannot use definition.Dimensions (variable of struct type pgtype.Int4) as int32 value in assignment
internal/handlers/llm_services.go:598:30: cannot use definition.ContextLimit (variable of struct type pgtype.Int4) as int32 value in assignment
internal/handlers/llm_services.go:612:21: cannot use int32(input.Body.ContextLimit) (value of type int32) as pgtype.Int4 value in struct literal
internal/handlers/llm_services.go:719:17: cannot use llm.ContextLimit (variable of struct type pgtype.Int4) as int32 value in struct literal

I need the dimensions and context_limit fields to be nullable (because I want to migrate existing databases from an earlier versions that might not have these fields), but that produces these errors. Please either fix the errors or add a function to the migration script that takes care of unset fields. Thank you.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 10, 2026 09:21
Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compilation errors in llm_services.go Fix type mismatches for nullable dimensions and context_limit fields Feb 10, 2026
Copilot AI requested a review from awagner-mainz February 10, 2026 09:30
@awagner-mainz
Copy link
Contributor

Code looks good, tests pass.

@awagner-mainz awagner-mainz marked this pull request as ready for review February 10, 2026 11:42
@awagner-mainz awagner-mainz merged commit 1e0d33d into main Feb 10, 2026
1 check passed
@awagner-mainz awagner-mainz deleted the copilot/fix-compilation-errors branch February 10, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants