-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/update cropus name embeddings model lang #16
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
Open
lpi-tn
wants to merge
3
commits into
main
Choose a base branch
from
Fix/update-cropus-name-embeddings-model-lang
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
93 changes: 93 additions & 0 deletions
93
welearn_database/alembic/versions/b049924f7067_modify_corpus_name_embedding_model_lang_.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,93 @@ | ||
| """modify corpus_name_embedding_model_lang view | ||
|
|
||
| Revision ID: b049924f7067 | ||
| Revises: f8602200fa99 | ||
| Create Date: 2026-03-31 16:09:12.085443 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "b049924f7067" | ||
| down_revision: Union[str, None] = "f8602200fa99" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.execute( | ||
| """ | ||
| DROP MATERIALIZED VIEW corpus_related.corpus_name_embedding_model_lang; | ||
| """ | ||
| ) | ||
| op.execute( | ||
| """ | ||
|
|
||
| CREATE MATERIALIZED VIEW corpus_related.corpus_name_embedding_model_lang | ||
| TABLESPACE pg_default | ||
| AS WITH ranked AS ( | ||
| SELECT | ||
| c.source_name, | ||
| cem.corpus_id, | ||
| cem.embedding_model_id, | ||
| em.title, | ||
| em.lang, | ||
| cem.used_since, | ||
| c.category_id, | ||
| ROW_NUMBER() OVER ( | ||
| PARTITION BY cem.corpus_id, | ||
| em.lang | ||
| ORDER BY | ||
| cem.used_since DESC | ||
| ) AS rn | ||
| FROM | ||
| corpus_related.corpus_embedding_model cem | ||
| JOIN corpus_related.corpus c ON | ||
| c.id = cem.corpus_id | ||
| JOIN corpus_related.embedding_model em ON | ||
| em.id = cem.embedding_model_id | ||
| WHERE | ||
| c.is_active | ||
| ) | ||
| SELECT | ||
| source_name, | ||
| corpus_id, | ||
| embedding_model_id, | ||
| title, | ||
| lang, | ||
| used_since, | ||
| category_id | ||
| FROM | ||
| ranked | ||
| WHERE | ||
| rn = 1 | ||
|
|
||
| WITH DATA; | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.execute( | ||
| """ | ||
| DROP MATERIALIZED VIEW corpus_related.corpus_name_embedding_model_lang; | ||
| """ | ||
| ) | ||
| op.execute( | ||
| """ | ||
| CREATE MATERIALIZED VIEW corpus_related.corpus_name_embedding_model_lang | ||
| TABLESPACE pg_default | ||
| AS SELECT corpus.source_name, | ||
| embedding_model.title, | ||
| embedding_model.lang | ||
| FROM corpus_related.corpus | ||
| JOIN corpus_related.corpus_embedding_model ON corpus_embedding_model.corpus_id = corpus.id | ||
| JOIN corpus_related.embedding_model ON embedding_model.id = corpus_embedding_model.embedding_model_id | ||
| WHERE corpus.is_active | ||
| WITH DATA; | ||
| """ | ||
| ) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_nameis declared as the sole primary key, but the materialized view returns one row per(corpus_id, lang)(latestused_since), which can produce multiple rows for the samesource_nameacross different languages. Withsource_namealone as the ORM PK, SQLAlchemy’s identity map can collapse/overwrite rows and return incomplete/incorrect results. Consider using a composite primary key that matches the view’s uniqueness (e.g., includelangand/orcorpus_id).