-
-
Notifications
You must be signed in to change notification settings - Fork 301
Welcome Embeddings 🚀 #4322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bjester
merged 11 commits into
learningequality:search-recommendations
from
vkWeb:embedds-model
Mar 12, 2024
Merged
Welcome Embeddings 🚀 #4322
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
93042ce
Welcome Embeddings :rocket:
vkWeb 2acd50c
New embedding model structure
vkWeb e003bbc
Enable extension only during pytest & docs update
vkWeb 3735b97
Use custom db backend for pytest instead of hacking migrations
vkWeb 5a4e891
Handle merge conflicts
bjester d1e38c5
Add creds to PG service in workflow and update postgres image
bjester e6dbc1a
Merge unstable again
bjester 5b097bb
Merge branch 'unstable' into embedds-model
vkWeb e3cb4c0
Return test db name, now its perfect.
vkWeb 4376391
Create and persist bucket
vkWeb c999814
Fix merge conflicts on requirements
bjester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) | ||
vkWeb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.