go-gorm / go-gorm/cli

[BUG] 当使用 vector 类型存储向量数据时,生成的泛型结构体错误

Open
#45 0 comments 1 reaction 1 assignee Claimed by @jinzhu View on GitHub
Dominant language
Go
Stars
108
Forks
15
PR merge metrics
No merged PRs in 30d

Description

## GORM Playground Link

https://github.com/go-gorm/playground/pull/1

## Description

SQL

```sql
CREATE TABLE app_embeddings
(
id UUID PRIMARY KEY NOT NULL DEFAULT uuidv7(),

-- 向量嵌入(语义匹配)
embedding VECTOR(1536), -- OpenAI text-embedding-3-small


created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMPTZ
);
```

模型定义

```go
// AppEmbeddings mapped from table < app_embeddings >
type AppEmbeddings struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primaryKey" json:"id" bson:"_id" dc:"id"`
Embedding *[]float64 `gorm:"column:embedding;type:vector(1536);comment:向量嵌入" json:"embedding" bson:"embedding" dc:"向量嵌入"` // 向量嵌入
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;autoCreateTime" json:"createdAt" bson:"createdAt" dc:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;autoUpdateTime" json:"updatedAt" bson:"updatedAt" dc:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deletedAt" bson:"deletedAt" dc:"deleted_at"`
}
```

生成了如下结构体

```go
var AppEmbeddings = struct {
ID field.Field[uuid.UUID]
Embedding field.Slice[float64]
CreatedAt field.Field[time.Time]
UpdatedAt field.Field[time.Time]
DeletedAt field.Field[gorm.DeletedAt]
}{
ID: field.Field[uuid.UUID]{}.WithColumn("id"),
Embedding: field.Slice[float64]{}.WithName("Embedding"),
CreatedAt: field.Field[time.Time]{}.WithColumn("created_at"),
UpdatedAt: field.Field[time.Time]{}.WithColumn("updated_at"),
DeletedAt: field.Field[gorm.DeletedAt]{}.WithColumn("deleted_at"),
}

```

`embedding` 被当前模型关联了,设置为 `field.Slice[float64]` ,实际应该使用 `field.Field` 包装。

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.