-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support building vector index with django_tidb>=5.0.1 (#64)
- Loading branch information
1 parent
cd238bc
commit d34d3b9
Showing
5 changed files
with
22 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,5 @@ django_tests_dir | |
*.swp | ||
|
||
.vscode/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Django==4.2.4 | ||
django-tidb>=4.2.4 | ||
django-tidb>=5.0.1 | ||
mysqlclient==2.2.0 | ||
python-dotenv==1.0.0 | ||
tidb-vector>=0.0.9 | ||
tidb-vector>=0.0.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
from django.db import models | ||
from django_tidb.fields.vector import VectorField | ||
from django_tidb.fields.vector import VectorField, VectorIndex, CosineDistance, L2Distance | ||
|
||
|
||
class Document(models.Model): | ||
content = models.TextField() | ||
embedding = VectorField(dimensions=3) | ||
|
||
|
||
class DocumentWithIndex(models.Model): | ||
content = models.TextField() | ||
# Note: | ||
# - Using comment to add hnsw index is a temporary solution. In the future it will use `CREATE INDEX` syntax. | ||
# - Currently the HNSW index cannot be changed after the table has been created. | ||
# - Only Django >= 4.2 supports `db_comment`. | ||
embedding = VectorField(dimensions=3, db_comment="hnsw(distance=cosine)") | ||
class Meta: | ||
indexes = [ | ||
VectorIndex(L2Distance("embedding"), name='idx_l2'), | ||
VectorIndex(CosineDistance("embedding"), name='idx_cos'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,4 @@ def list_routes(request): | |
'/get_nearest_neighbors_documents', | ||
'/get_documents_within_distance' | ||
] | ||
}) | ||
}) |