Initial commit: TrueRecall v2.2 with 30b curator and timer-based curation
This commit is contained in:
85
tr-continuous/migrate_add_curated.py
Executable file
85
tr-continuous/migrate_add_curated.py
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Migration: Add 'curated: false' to existing memories_tr entries.
|
||||
|
||||
Run once to update all existing memories for the new timer curator.
|
||||
Uses POST /collections/{name}/points/payload with {"points": [ids], "payload": {...}}
|
||||
"""
|
||||
|
||||
import requests
|
||||
import time
|
||||
import sys
|
||||
|
||||
QDRANT_URL = "http://10.0.0.40:6333"
|
||||
COLLECTION = "memories_tr"
|
||||
|
||||
def update_existing_memories():
|
||||
"""Add curated=false to all memories that don't have the field."""
|
||||
print("🔧 Migrating existing memories...")
|
||||
|
||||
offset = None
|
||||
updated = 0
|
||||
batch_size = 100
|
||||
max_iterations = 200
|
||||
iterations = 0
|
||||
|
||||
while iterations < max_iterations:
|
||||
iterations += 1
|
||||
|
||||
scroll_data = {
|
||||
"limit": batch_size,
|
||||
"with_payload": True
|
||||
}
|
||||
if offset:
|
||||
scroll_data["offset"] = offset
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{QDRANT_URL}/collections/{COLLECTION}/points/scroll",
|
||||
json=scroll_data,
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=30
|
||||
)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
points = result.get("result", {}).get("points", [])
|
||||
|
||||
if not points:
|
||||
break
|
||||
|
||||
# Collect IDs that need curated=false
|
||||
ids_to_update = []
|
||||
for point in points:
|
||||
payload = point.get("payload", {})
|
||||
if "curated" not in payload:
|
||||
ids_to_update.append(point["id"])
|
||||
|
||||
if ids_to_update:
|
||||
# POST /points/payload with {"points": [ids], "payload": {...}}
|
||||
update_response = requests.post(
|
||||
f"{QDRANT_URL}/collections/{COLLECTION}/points/payload",
|
||||
json={
|
||||
"points": ids_to_update,
|
||||
"payload": {"curated": False}
|
||||
},
|
||||
timeout=30
|
||||
)
|
||||
update_response.raise_for_status()
|
||||
updated += len(ids_to_update)
|
||||
print(f" Updated batch: {len(ids_to_update)} memories (total: {updated})")
|
||||
time.sleep(0.05)
|
||||
|
||||
offset = result.get("result", {}).get("next_page_offset")
|
||||
if not offset:
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
break
|
||||
|
||||
print(f"✅ Migration complete: {updated} memories updated with curated=false")
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_existing_memories()
|
||||
Reference in New Issue
Block a user