Skip to content

Commit ad5b5df

Browse files
Fixed kb records upload and indexing (#886)
1 parent c7ded4c commit ad5b5df

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

backend/python/app/connectors/services/base_arango_service.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7038,6 +7038,23 @@ async def update_knowledge_base(
70387038
self.logger.error(f"❌ Failed to update knowledge base: {str(e)}")
70397039
raise
70407040

7041+
async def get_folder_record_by_id(self, folder_id: str, transaction: Optional[TransactionDatabase] = None) -> Optional[Dict]:
7042+
try:
7043+
db = transaction if transaction else self.db
7044+
query = """
7045+
FOR file IN @@files
7046+
FILTER file._key == @folder_id
7047+
RETURN file
7048+
"""
7049+
cursor = db.aql.execute(query, bind_vars={
7050+
"folder_id": folder_id,
7051+
"@files": CollectionNames.FILES.value,
7052+
})
7053+
return next(cursor, None)
7054+
except Exception as e:
7055+
self.logger.error(f"❌ Failed to fetch folder record {folder_id}: {str(e)}")
7056+
return None
7057+
70417058
async def find_folder_by_name_in_parent(
70427059
self,
70437060
kb_id: str,
@@ -7141,7 +7158,7 @@ async def navigate_to_folder_by_path(
71417158
current_parent_id = folder["_key"]
71427159

71437160
# Return the final folder if we successfully navigated the entire path
7144-
return await self.get_file_record_by_id(current_parent_id, transaction)
7161+
return await self.get_folder_record_by_id(current_parent_id, transaction)
71457162

71467163
except Exception as e:
71477164
self.logger.error(f"❌ Failed to navigate to folder by path: {str(e)}")
@@ -7180,7 +7197,7 @@ async def create_folder(
71807197
try:
71817198
# Step 1: Validate parent folder exists (if nested)
71827199
if parent_folder_id:
7183-
parent_folder = await self.get_file_record_by_id(parent_folder_id, transaction)
7200+
parent_folder = await self.get_folder_record_by_id(parent_folder_id, transaction)
71847201
if not parent_folder:
71857202
raise ValueError(f"Parent folder {parent_folder_id} not found")
71867203
if parent_folder.get("isFile") is not False:
@@ -12378,13 +12395,8 @@ async def get_file_record_by_id(
1237812395
db = transaction if transaction else self.db
1237912396
cursor = db.aql.execute(query, bind_vars={"id": id})
1238012397
result = next(cursor, None)
12381-
print("!!!!!!!!!!!!!!!!!!! result:", result)
1238212398
if result and result.get("file") and result.get("record"):
1238312399
self.logger.info("✅ Successfully retrieved file record for id %s", id)
12384-
print("!!!!!!!!!!!!!!!!!!! FileRecord.from_arango_base_file_record:", FileRecord.from_arango_base_file_record(
12385-
arango_base_file_record=result["file"],
12386-
arango_base_record=result["record"]
12387-
))
1238812400
return FileRecord.from_arango_base_file_record(
1238912401
arango_base_file_record=result["file"],
1239012402
arango_base_record=result["record"]

backend/python/app/utils/converters/docling_doc_to_blocks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import uuid
3-
from typing import List, Tuple, Union
3+
from typing import List, Optional, Tuple, Union
44

55
from docling.datamodel.document import DoclingDocument
66
from jinja2 import Template
@@ -149,7 +149,8 @@ def _enrich_metadata(block: Block|BlockGroup, item: dict, doc_dict: dict) -> Non
149149
block.citation_metadata = CitationMetadata(page_number=page_no)
150150

151151

152-
async def _handle_text_block(item: dict, doc_dict: dict, parent_index: int, ref_path: str,level: int,doc: DoclingDocument) -> Block:
152+
async def _handle_text_block(item: dict, doc_dict: dict, parent_index: int, ref_path: str,level: int,doc: DoclingDocument) -> Optional[Block]:
153+
block = None
153154
if item.get("text") != "":
154155
block = Block(
155156
id=str(uuid.uuid4()),

0 commit comments

Comments
 (0)