@@ -106,6 +106,34 @@ def insert_rows(conn: connection, rows: List[Tuple[Any, ...]]) -> None:
106106 conn .commit ()
107107
108108
109+ def build_row (row : Any ) -> Optional [Tuple [Any , ...]]:
110+ """Build a single row tuple for DB insertion."""
111+ doi = getattr (row , "doi" , None )
112+ title : str = (getattr (row , "title" , "" ) or "" ).strip ()
113+ abstract : str = (getattr (row , "abstract" , "" ) or "" ).strip ()
114+ published_at = parse_date (getattr (row , "update_date" , None ))
115+ raw_authors = getattr (row , "authors_parsed" , None )
116+ authors_json = authors_to_json (raw_authors )
117+ arxiv_id = getattr (row , "id" , None )
118+ paper_id_external = arxiv_id or None
119+ embedding = getattr (row , "embedding" , None )
120+ if embedding is None :
121+ return None
122+ embedding_literal = embedding_to_literal (embedding )
123+
124+ return (
125+ doi ,
126+ "ARXIV" ,
127+ "PREPRINT" ,
128+ title ,
129+ authors_json ,
130+ abstract ,
131+ published_at ,
132+ paper_id_external ,
133+ embedding_literal ,
134+ )
135+
136+
109137def ingest_shard (conn : connection , shard_path : Path , batch_size : int ) -> None :
110138 """Ingest a single parquet shard into the database."""
111139 logger .info ("Ingesting %s" , shard_path .name )
@@ -114,44 +142,14 @@ def ingest_shard(conn: connection, shard_path: Path, batch_size: int) -> None:
114142 rows : List [Tuple [Any , ...]] = []
115143
116144 for row in df .itertuples (index = False ):
117- doi = getattr (row , "doi" , None )
118- title : str = (getattr (row , "title" , "" ) or "" ).strip ()
119- abstract : str = (getattr (row , "abstract" , "" ) or "" ).strip ()
120- published_at = parse_date (getattr (row , "update_date" , None ))
121-
122- raw_authors = getattr (row , "authors_parsed" , None )
123- authors_json = authors_to_json (raw_authors )
124-
125- arxiv_id = getattr (row , "id" , None )
126- paper_id_external = arxiv_id or None
127-
128- embedding = getattr (row , "embedding" , None )
129- if embedding is None :
145+ row_tuple = build_row (row )
146+ if row_tuple is None :
130147 continue
131-
132- embedding_literal = embedding_to_literal (embedding )
133-
134- rows .append (
135- (
136- doi ,
137- "ARXIV" ,
138- "PREPRINT" ,
139- title ,
140- authors_json ,
141- abstract ,
142- published_at ,
143- paper_id_external ,
144- embedding_literal ,
145- )
146- )
147-
148+ rows .append (row_tuple )
148149 if len (rows ) >= batch_size :
149150 insert_rows (conn , rows )
150151 rows .clear ()
151152
152- if rows :
153- insert_rows (conn , rows )
154-
155153
156154def main (data_dir : Path , batch_size : int ) -> None :
157155 """Main entrypoint for bulk ingestion."""
0 commit comments