File size: 1,263 Bytes
d1a85d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9c2363
d1a85d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import json
import numpy as np
from tqdm import tqdm
from pymilvus import connections, Collection

connections.connect("default", host="127.0.0.1", port="19530")
col = Collection("sumobot_states")

def encode_state(state_str):
    # Parse numeric values from your formatted string
    parts = dict(item.split('=') for item in state_str.strip('.').split(', '))
    return np.array([
        float(parts["AngleToEnemy"]) / 180.0,  # normalize angle
        float(parts["AngleToEnemyScore"]),
        float(parts["DistanceToEnemyScore"]),
        float(parts["NearBorderArenaScore"]),
        float(parts["FacingToArena"]),
    ], dtype=np.float32)

BATCH_SIZE = 5000
DATA_PATH = "cleaned_dataset.jsonl"

batch_vecs, batch_actions = [], []
with open(DATA_PATH, "r") as f:
    for line in tqdm(f, desc="Reading dataset"):
        item = json.loads(line)
        vec = encode_state(item["state"])
        batch_vecs.append(vec.tolist())
        batch_actions.append(item["action"])

        if len(batch_vecs) >= BATCH_SIZE:
            col.insert([batch_vecs, batch_actions])
            batch_vecs, batch_actions = [], []

# Insert remainder
if batch_vecs:
    col.insert([batch_vecs, batch_actions])

col.flush()
print("✅ All data inserted & flushed to Milvus.")