Skip to content

Commit

Permalink
fix legacy embed progression code throwing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
latekvo committed Jun 16, 2024
1 parent 5d843e0 commit 7ea2bb0
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions core/databases/db_crawl_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
update,
select,
ForeignKey,
insert,
)
from sqlalchemy.orm import Mapped, mapped_column, Session, relationship

Expand Down Expand Up @@ -189,23 +190,37 @@ def db_are_crawl_tasks_fully_embedded(uuid_list: str, model_name: str):

def db_increment_task_embedding_progression(uuid: str, model_name: str):
with Session(engine) as session:
query = select(CrawlTask).where(CrawlTask.uuid == uuid)
crawl_task = session.scalars(query).one()
query = (
select(EmbeddingProgression)
.where(EmbeddingProgression.crawl_uuid == uuid)
.where(EmbeddingProgression.embedder_name == model_name)
)

embedding_progression = session.scalars(query).one_or_none()

current_progression = crawl_task.embedding_progression
current_count = current_progression[model_name]
# no prior progression records found, add them
if embedding_progression is None:
session.execute(
insert(EmbeddingProgression).values(
uuid=utils.gen_uuid(),
crawl_uuid=uuid,
embedder_name=model_name,
embedding_amount=1,
timestamp=utils.gen_unix_time(),
)
)

if current_count is not None:
current_count += 1
else:
current_count = 1
session.commit()
return

current_progression[model_name] = current_count
current_count = embedding_progression.embedding_amount
new_count = current_count + 1

session.execute(
update(CrawlTask)
.where(CrawlTask.uuid == crawl_task.uuid)
.values(embedding_progression=current_progression)
update(EmbeddingProgression)
.where(EmbeddingProgression.crawl_uuid == uuid)
.where(EmbeddingProgression.embedder_name == model_name)
.values(embedding_amount=new_count)
)

session.commit()

0 comments on commit 7ea2bb0

Please sign in to comment.