Skip to content

Commit 441b26e

Browse files
committed
Updated example [skip ci]
1 parent afcd67a commit 441b26e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@ from django.contrib.postgres.indexes import OpClass
142142
from django.db.models.functions import Cast
143143
from pgvector.django import HalfVectorField
144144

145-
index = HnswIndex(
146-
OpClass(Cast('embedding', HalfVectorField(dimensions=3)), name='halfvec_l2_ops'),
147-
name='my_index',
148-
m=16,
149-
ef_construction=64
150-
)
145+
class Item(models.Model):
146+
class Meta:
147+
indexes = [
148+
HnswIndex(
149+
OpClass(Cast('embedding', HalfVectorField(dimensions=3)), name='halfvec_l2_ops'),
150+
name='my_index',
151+
m=16,
152+
ef_construction=64
153+
)
154+
]
151155
```
152156

153157
Note: Add `'django.contrib.postgres'` to `INSTALLED_APPS` to use `OpClass`

0 commit comments

Comments
 (0)