Skip to content

Commit

Permalink
Improved GORM example
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jan 19, 2024
1 parent 804b307 commit 0dbe778
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ db.Clauses(clause.OrderBy{
}).Limit(5).Find(&items)
```

Add an approximate index

```go
db.Exec("CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)")
// or
db.Exec("CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)")
```

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](gorm_test.go)

## History
Expand Down
2 changes: 2 additions & 0 deletions gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func TestGorm(t *testing.T) {

db.AutoMigrate(&GormItem{})

db.Exec("CREATE INDEX ON gorm_items USING hnsw (embedding vector_l2_ops)")

CreateGormItems(db)

var items []GormItem
Expand Down

0 comments on commit 0dbe778

Please sign in to comment.