mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-10 20:35:17 +02:00
use document_id instead of page_id for kb sync lookup
This commit is contained in:
parent
bd3bd701a7
commit
2f65536c6d
2 changed files with 13 additions and 17 deletions
|
|
@ -108,6 +108,7 @@ def create_update_notion_page_tool(
|
|||
}
|
||||
|
||||
page_id = context.get("page_id")
|
||||
document_id = context.get("document_id")
|
||||
connector_id_from_context = context.get("account", {}).get("id")
|
||||
|
||||
logger.info(
|
||||
|
|
@ -222,13 +223,13 @@ def create_update_notion_page_tool(
|
|||
if result.get("status") == "success":
|
||||
from app.services.notion import NotionKBSyncService
|
||||
|
||||
logger.info(f"Updating knowledge base for page {final_page_id}...")
|
||||
logger.info(f"Updating knowledge base for document {document_id}...")
|
||||
kb_service = NotionKBSyncService(db_session)
|
||||
kb_result = await kb_service.sync_after_update(
|
||||
page_id=final_page_id,
|
||||
search_space_id=search_space_id,
|
||||
document_id=document_id,
|
||||
appended_content=final_content,
|
||||
user_id=user_id,
|
||||
search_space_id=search_space_id,
|
||||
)
|
||||
|
||||
if kb_result["status"] == "success":
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import String, cast, delete
|
||||
from sqlalchemy import delete
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.future import select
|
||||
|
||||
from app.config import config
|
||||
from app.db import Chunk, Document
|
||||
|
|
@ -23,10 +22,10 @@ class NotionKBSyncService:
|
|||
|
||||
async def sync_after_update(
|
||||
self,
|
||||
page_id: str,
|
||||
search_space_id: int,
|
||||
document_id: int,
|
||||
appended_content: str,
|
||||
user_id: str,
|
||||
search_space_id: int,
|
||||
) -> dict:
|
||||
from app.tasks.connector_indexers.base import (
|
||||
get_current_timestamp,
|
||||
|
|
@ -34,13 +33,7 @@ class NotionKBSyncService:
|
|||
)
|
||||
|
||||
try:
|
||||
result = await self.db_session.execute(
|
||||
select(Document).filter(
|
||||
Document.search_space_id == search_space_id,
|
||||
cast(Document.document_metadata["page_id"], String) == page_id,
|
||||
)
|
||||
)
|
||||
document = result.scalars().first()
|
||||
document = await self.db_session.get(Document, document_id)
|
||||
|
||||
if not document:
|
||||
return {"status": "not_indexed"}
|
||||
|
|
@ -54,7 +47,7 @@ class NotionKBSyncService:
|
|||
if user_llm:
|
||||
document_metadata_for_summary = {
|
||||
"page_title": document.document_metadata.get("page_title"),
|
||||
"page_id": page_id,
|
||||
"page_id": document.document_metadata.get("page_id"),
|
||||
"document_type": "Notion Page",
|
||||
"connector_type": "Notion",
|
||||
}
|
||||
|
|
@ -85,9 +78,11 @@ class NotionKBSyncService:
|
|||
|
||||
await self.db_session.commit()
|
||||
|
||||
logger.info(f"Successfully synced KB for Notion page {page_id}")
|
||||
logger.info(f"Successfully synced KB for document {document_id}")
|
||||
return {"status": "success"}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to sync KB for page {page_id}: {e}", exc_info=True)
|
||||
logger.error(
|
||||
f"Failed to sync KB for document {document_id}: {e}", exc_info=True
|
||||
)
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue