Skip to content
Notifications
Clear all

Step-by-step: Setting up automated PDF ingestion from our shared drive

1 Posts
1 Users
0 Reactions
4 Views
(@latency_lucy)
Trusted Member
Joined: 3 months ago
Posts: 49
Topic starter   [#4218]

Our research team's shared drive currently holds over 2,300 PDFs, and manual upload to SciSpace for literature review was introducing significant latency in our workflow startup time. I've successfully automated the ingestion process using SciSpace's API, reducing the initial dataset synchronization time from an estimated 40 person-hours to approximately 90 minutes of unattended runtime.

The core of the automation is a Python script that polls a designated directory, validates PDFs, and pushes them via the `literature` endpoint. Key performance considerations for the setup:

* **Batch Size:** The API accepts individual files. To avoid connection overhead and respect rate limits, I implemented a 1-second delay between requests. A batch of 100 files completes in ~1 minute 40 seconds.
* **Error Handling:** The script must handle corrupted PDFs gracefully. A malformed file shouldn't halt the entire pipeline.
* **State Tracking:** Maintaining a simple log of processed files is essential for idempotence and resuming after interruptions.

Here is the basic configuration and loop logic:

```python
import os
import time
import requests
from pathlib import Path

SCISPACE_API_KEY = "your_api_key_here"
BASE_URL = "https://api.scispace.com/v3/literature"
SOURCE_DIR = Path("/mnt/team_share/literature")

headers = {"Authorization": f"Bearer {SCISPACE_API_KEY}"}

def upload_pdf(file_path):
with open(file_path, 'rb') as f:
files = {'file': f}
response = requests.post(BASE_URL, headers=headers, files=files)
return response.status_code == 200

for pdf_file in SOURCE_DIR.glob("*.pdf"):
print(f"Processing {pdf_file.name}...")
success = upload_pdf(pdf_file)
log_entry = f"{pdf_file.name}, {success}n"
# ... write log entry ...
time.sleep(1) # Conservative throttle
```

The primary bottleneck is the sequential upload. While you could implement threading, the current rate limit makes the gains marginal and risks 429 errors. The process is I/O-bound, not CPU-bound.

For teams considering this, profile your network latency to SciSpace's API endpoint first. In our AWS environment, average round-trip time was 220ms, making the 1-second delay reasonable. The next optimization phase will involve pre-extracting text for faster SciSpace processing post-upload, but that's a separate benchmark.


sub-10ms or bust


   
Quote