MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / process_normal_path

Function process_normal_path

AskAgent/python/data_loading/db_load.py:1073–1112  ·  view source on GitHub ↗
(input_file_path: str, site: str, batch_size: int = 100, delete_site: bool = False, force_recompute: bool = False, database: str | None = None)

Source from the content-addressed store, hash-verified

1071 print(f"Deleted {count} entries for site '{site}'")
1072
1073async def process_normal_path(input_file_path: str, site: str, batch_size: int = 100, delete_site: bool = False, force_recompute: bool = False, database: str | None = None):
1074 # Check if file exists at the specified path
1075 if not await is_url(input_file_path) and not os.path.exists(input_file_path):
1076 print(f"Warning: File not found at '{input_file_path}'. Will try to resolve or download it.")
1077
1078 # Determine if the file is a URL
1079 is_url_path = await is_url(input_file_path)
1080 temp_path = None
1081 file_path = input_file_path
1082
1083 # If it's a URL, fetch the content
1084 if is_url_path:
1085 print(f"Fetching content from URL: {input_file_path}")
1086 temp_path, _ = await save_url_content(input_file_path)
1087 file_path = temp_path
1088
1089 try:
1090 # Detect file type and if it contains embeddings
1091 if os.path.exists(file_path):
1092 file_type, has_embeddings = await detect_file_type(file_path)
1093 print(f"Detected file type: {file_type}, contains embeddings: {'Yes' if has_embeddings else 'No'}")
1094
1095 # Process based on whether the file has embeddings
1096 if has_embeddings and not force_recompute:
1097 print("File already contains embeddings, loading directly...")
1098 await loadJsonWithEmbeddingsToDB(file_path, site, batch_size, delete_site, database)
1099 else:
1100 print("Computing embeddings for file...")
1101 await loadJsonToDB(file_path, site, batch_size, delete_site, force_recompute, database)
1102 else:
1103 print(f"Error: File not found at '{file_path}'")
1104 sys.exit(1)
1105 finally:
1106 # Clean up temporary file if needed
1107 if temp_path and os.path.exists(temp_path):
1108 try:
1109 os.unlink(temp_path)
1110 print(f"Cleaned up temporary file: {temp_path}")
1111 except Exception:
1112 pass
1113
1114
1115async def main():

Callers 1

mainFunction · 0.85

Calls 5

is_urlFunction · 0.85
save_url_contentFunction · 0.85
detect_file_typeFunction · 0.85
loadJsonToDBFunction · 0.85

Tested by

no test coverage detected