-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4322 from vkWeb/embedds-model
Welcome Embeddings 🚀
- Loading branch information
Showing
12 changed files
with
231 additions
and
68 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
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
36 changes: 36 additions & 0 deletions
36
contentcuration/contentcuration/migrations/0147_embeddings_embeddingscontentnode.py
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 3.2.19 on 2023-11-08 09:55 | ||
import uuid | ||
|
||
import django.db.models.deletion | ||
import pgvector.django | ||
from django.conf import settings | ||
from django.db import migrations | ||
from django.db import models | ||
|
||
import contentcuration.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contentcuration', '0146_drop_taskresult_fields'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EmbeddingsContentNode', | ||
fields=[ | ||
('cid', models.CharField(max_length=64, primary_key=True, serialize=False)), | ||
('contentnode', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='node_cid', to='contentcuration.contentnode')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Embeddings', | ||
fields=[ | ||
('embedding_id', contentcuration.models.UUIDField(default=uuid.uuid4, max_length=32, primary_key=True, serialize=False)), | ||
('model', models.CharField(db_index=True, max_length=64)), | ||
('embedding', pgvector.django.VectorField()), | ||
('embedded_node', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='embeddings', to='contentcuration.embeddingscontentnode')), | ||
], | ||
), | ||
] |
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
34 changes: 34 additions & 0 deletions
34
contentcuration/contentcuration/tests/custom_pytest_db_backend/base.py
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from django.db.backends.postgresql.base import DatabaseWrapper as PostgresDatabaseWrapper | ||
from django.db.backends.postgresql.creation import DatabaseCreation as PostgresDatabaseCreation | ||
|
||
|
||
class CustomDBCreationForPytest(PostgresDatabaseCreation): | ||
""" | ||
Overriding creation module to enable postgres pgvector extension before | ||
pytest runs migration. Because embeddings table rely on pgvector | ||
extension to work. | ||
""" | ||
|
||
def _create_test_db(self, verbosity, autoclobber, keepdb=False): | ||
from contentcuration.management.commands.setup import enable_pgvector_extension | ||
|
||
# Create test database and get its name. | ||
test_db_name = super()._create_test_db(verbosity, autoclobber, keepdb) | ||
|
||
# Close current nodb_cursor connection and point connection to the | ||
# newly created test database. | ||
self.connection.close() | ||
self.connection.settings_dict["NAME"] = test_db_name | ||
|
||
# Enable pgvector extension. | ||
enable_pgvector_extension(self.connection) | ||
|
||
return self.connection.settings_dict["NAME"] | ||
|
||
|
||
class DatabaseWrapper(PostgresDatabaseWrapper): | ||
""" | ||
A database wrapper to customise creation module. Rest everything is same as | ||
Postgres. | ||
""" | ||
creation_class = CustomDBCreationForPytest |
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
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
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 |
---|---|---|
|
@@ -35,3 +35,4 @@ pillow==10.2.0 | |
python-dateutil>=2.8.1 | ||
jsonschema>=3.2.0 | ||
django-celery-results | ||
pgvector |
Oops, something went wrong.