Skip to content

Commit 62b3322

Browse files
author
AnthonyMalRivett
committed
Fixed various code issues.
1 parent 5e2070a commit 62b3322

3 files changed

Lines changed: 16 additions & 100 deletions

File tree

backend/app/models/paper.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
from typing import TYPE_CHECKING, List, Optional
55

66
from pgvector.sqlalchemy import Vector
7-
from sqlalchemy import Enum as SqlEnum
87
from sqlalchemy import (
98
JSON,
109
BigInteger,
1110
Date,
1211
DateTime,
12+
Index,
1313
String,
1414
Text,
15-
Index,
1615
)
16+
from sqlalchemy import Enum as SqlEnum
1717
from sqlalchemy.orm import Mapped, mapped_column, relationship
1818
from sqlalchemy.sql import func
1919

@@ -45,17 +45,13 @@ class Paper(Base):
4545
authors: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
4646
abstract: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
4747
published_at: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
48-
paper_id_external: Mapped[Optional[str]] = mapped_column(
49-
String(255), nullable=True
50-
) # <-- added
48+
paper_id_external: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
5149
fetched_at: Mapped[datetime] = mapped_column(
5250
DateTime(timezone=True), nullable=False, server_default=func.now()
5351
)
5452

5553
# Vector Embedding
56-
embedding: Mapped[Optional[List[float]]] = mapped_column(
57-
Vector(768), nullable=True
58-
)
54+
embedding: Mapped[Optional[List[float]]] = mapped_column(Vector(768), nullable=True)
5955

6056
# Relationships
6157
project_links: Mapped[List["ProjectPaper"]] = relationship(
@@ -72,9 +68,7 @@ class Paper(Base):
7268
"ix_paper_embedding_hnsw",
7369
"embedding",
7470
postgresql_using="hnsw",
75-
postgresql_ops={
76-
"embedding": "vector_cosine_ops"
77-
},
71+
postgresql_ops={"embedding": "vector_cosine_ops"},
7872
postgresql_with={"m": 16, "ef_construction": 64},
7973
),
8074
)

backend/app/services/arxiv_ingestion.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

backend/ingestion/arxiv_to_db.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import json
33
import logging
4+
import os
45
from datetime import datetime
56
from pathlib import Path
67
from typing import Iterable, List, Optional, Tuple
@@ -14,11 +15,11 @@
1415
logger = logging.getLogger(__name__)
1516

1617
DB_CONFIG = {
17-
"host": "inquiro-db.cxa6mocs0pr2.eu-central-1.rds.amazonaws.com",
18-
"port": 5432,
19-
"user": "postgres",
20-
"password": "TODO",
21-
"dbname": "inquiro_db",
18+
"host": os.getenv("POSTGRES_HOST"),
19+
"port": int(os.getenv("POSTGRES_PORT")),
20+
"user": os.getenv("POSTGRES_USER"),
21+
"password": os.getenv("POSTGRES_PASSWORD"),
22+
"dbname": os.getenv("POSTGRES_DB"),
2223
"sslmode": "require",
2324
}
2425

@@ -145,13 +146,17 @@ def main(data_dir: Path, batch_size: int):
145146

146147

147148
if __name__ == "__main__":
149+
script_dir = os.path.dirname(os.path.abspath(__file__))
150+
default_data_path = os.path.join(script_dir, "arxiv-vector-embeddings")
151+
148152
parser = argparse.ArgumentParser(
149153
description="Bulk ingest arXiv parquet shards into paper table."
150154
)
151155
parser.add_argument(
152156
"--data-dir",
153157
type=str,
154-
default=r"C:/Users/AnthonyMalRivett/Documents/arxiv-vector-embeddings",
158+
default=default_data_path,
159+
help="Path to the folder containing the embeddings",
155160
)
156161
parser.add_argument("--batch-size", type=int, default=1000)
157162
args = parser.parse_args()

0 commit comments

Comments
 (0)