File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1075,6 +1075,27 @@ def generate_embeddings(db_url: str) -> None:
10751075 database = db_connect (path = db_url )
10761076 prompt_client .PromptHandler (database , load_all_embeddings = True )
10771077
1078+ def parse_file (filename : str , yamldocs : List [Any ], scollection ) -> Optional [List [defs .Document ]]:
1079+ """
1080+ Parse a list of dictionaries (YAML/JSON documents) into defs.Document objects.
1081+ Returns None and logs a critical error if any element is not a dict.
1082+ """
1083+ if not all (isinstance (doc , dict ) for doc in yamldocs ):
1084+ logger .critical ("Malformed file %s, skipping" , filename )
1085+ return None
1086+
1087+ def normalize_links (doc : dict ) -> dict :
1088+ """Make sure link dicts use 'ltype' key instead of 'type'."""
1089+ if "links" in doc :
1090+ for link in doc ["links" ]:
1091+ if "type" in link and "ltype" not in link :
1092+ link ["ltype" ] = link .pop ("type" )
1093+ # Recursively normalize nested documents (if any)
1094+ if "document" in link and isinstance (link ["document" ], dict ):
1095+ normalize_links (link ["document" ])
1096+ return doc
1097+
1098+ return [defs .Document .from_dict (normalize_links (dict (doc ))) for doc in yamldocs ]
10781099
10791100def populate_neo4j_db (cache : str ):
10801101 if (
You can’t perform that action at this time.
0 commit comments