Skip to content

Commit

Permalink
Update embedded_at datetime filed after success embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Jan 28, 2024
1 parent b7fef59 commit 0390963
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/routers/v1/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ def run_notion_embedding(db: Session = Depends(get_db)):
if notion_object.embedded_at is None or notion_object.embedded_at < notion_object.updated_at:
chunks = split_files(data=notion_object.content)
save_to_pinecone(chunks)
ns.update_notion_embedding(
session=db,
page_id=notion_object.page_id
)
print("Updated")
else:
print(f"Skip embedding for page {notion_object.page_id}")
continue
Expand Down
5 changes: 3 additions & 2 deletions app/services/notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Type, List
from config.database import NotFoundError
from models.notion import Notion
from datetime import datetime


def create_notion_object(session: Session, data: NotionCreateSchema) -> NotionCreateSchema:
Expand Down Expand Up @@ -40,9 +41,9 @@ def update_notion_content(session: Session, page_id: str, data: NotionUpdateSche
return notion


def update_notion_embedding(session: Session, page_id: str, data: NotionEmbeddUpdateSchema) -> Type[NotionSchema]:
def update_notion_embedding(session: Session, page_id: str) -> Type[NotionSchema]:
notion = get_notion_object_by_page_id(session, page_id)
notion.embedding = data.embedded_at
notion.embedded_at = datetime.now()
session.commit()
session.refresh(notion)
return notion

0 comments on commit 0390963

Please sign in to comment.