rmi-backend/scripts/ingest_sigmod_pnd.py
opencode c762564d40 style(rmi-backend): complete lint cleanup — 1175→0 ruff errors
- Fix 71 invalid-syntax files (class-body newline-broken assignments)
- Add from/None chain to 307 B904 raise-without-from sites
- Add B008 ignore to ruff.toml (already in pyproject.toml)
- Noqa F401 on __init__.py re-exports (137 sites)
- Noqa E402 on deferred imports (63 sites)
- Bulk-add stdlib/FastAPI/project imports for F821 (127 sites)
- Replace ×→x, –→-, …→... in docstrings (4093 chars)
- Manual refactor of 5 SIM103/SIM116 patterns

Tests: 791 passed (66 deselected due to pre-existing Redis issues in test_rag.py)
Co-authored-by: opencode <opencode@rugmunch.io>
2026-07-06 15:43:20 +02:00

62 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Ingest SIGMOD 2023 Pump & Dump dataset into RAG known_scams.
36,696 labeled messages from Telegram pump channels - ground truth training data.
"""
import asyncio
import csv
import sys
import httpx
sys.path.insert(0, "/root/backend")
CSV_PATH = "/root/tools/dark-collection/sigmod-pnd/Data/Telegram/Labeled/pred_pump_message.csv"
RAG_URL = "http://localhost:8000/api/v1/rag/ingest"
BATCH = 100 # Ingest in batches to avoid overwhelming the API
async def ingest():
with open(CSV_PATH) as f:
reader = csv.DictReader(f, delimiter="\t")
rows = list(reader)
print(f"Loading {len(rows)} P&D messages...")
count = 0
async with httpx.AsyncClient(timeout=30) as client:
for i, row in enumerate(rows):
# Build a searchable document
msg = row.get("message", "")[:1000]
channel = row.get("channel_id", "unknown")
date = row.get("date", "")
label = row.get("pred_label", "0")
payload = {
"collection": "known_scams",
"content": f"[SIGMOD P&D] Channel {channel} - {date}: {msg}",
"metadata": {
"source": "sigmod_pnd_2023",
"channel_id": channel,
"date": date,
"pred_label": float(label),
"scam_type": "pump_and_dump",
"dataset": "SIGMOD 2023",
},
}
try:
r = await client.post(RAG_URL, json=payload, headers={"X-RMI-Key": "rmi-internal-2026"})
if r.status_code == 200:
count += 1
except Exception:
pass
if (i + 1) % 500 == 0:
print(f" Progress: {i + 1}/{len(rows)} ({count} ingested)")
print(f"Done: {count}/{len(rows)} ingested into known_scams")
if __name__ == "__main__":
asyncio.run(ingest())