Skip to content

Commit 9c0c00f

Browse files
committed
Added test and docs for HNSW
1 parent a7ce7bb commit 9c0c00f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class Item(models.Model):
9898
fields=['embedding'],
9999
lists=100,
100100
opclasses=['vector_l2_ops']
101+
),
102+
# or
103+
HnswIndex(
104+
name='my_index',
105+
fields=['embedding'],
106+
m=16,
107+
ef_construction=64,
108+
opclasses=['vector_l2_ops']
101109
)
102110
]
103111
```
@@ -151,6 +159,13 @@ index = Index('my_index', Item.embedding,
151159
postgresql_with={'lists': 100},
152160
postgresql_ops={'embedding': 'vector_l2_ops'}
153161
)
162+
# or
163+
index = Index('my_index', Item.embedding,
164+
postgresql_using='hnsw',
165+
postgresql_with={'m': 16, 'ef_construction': 64},
166+
postgresql_ops={'embedding': 'vector_l2_ops'}
167+
)
168+
154169
index.create(engine)
155170
```
156171

tests/test_sqlalchemy.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,23 @@ def test_core(self):
5555
metadata.drop_all(engine)
5656
metadata.create_all(engine)
5757

58-
index = Index(
59-
'my_core_index',
58+
ivfflat_index = Index(
59+
'ivfflat_core_index',
6060
item_table.c.embedding,
6161
postgresql_using='ivfflat',
6262
postgresql_with={'lists': 1},
6363
postgresql_ops={'embedding': 'vector_l2_ops'}
6464
)
65-
index.create(engine)
65+
ivfflat_index.create(engine)
66+
67+
hnsw_index = Index(
68+
'hnsw_core_index',
69+
item_table.c.embedding,
70+
postgresql_using='hnsw',
71+
postgresql_with={'m': 16, 'ef_construction': 64},
72+
postgresql_ops={'embedding': 'vector_l2_ops'}
73+
)
74+
hnsw_index.create(engine)
6675

6776
def test_orm(self):
6877
item = Item(embedding=np.array([1.5, 2, 3]))

0 commit comments

Comments
 (0)