sumobot_ml / vdb /query_actions.py
arbyazra123
add vdb
d1a85d8
raw
history blame contribute delete
890 Bytes
import numpy as np
from pymilvus import connections, Collection
connections.connect("default", host="127.0.0.1", port="19530")
col = Collection("sumobot_states")
col.load()
def encode_state(angle, angle_score, dist_score, near_score, facing):
return np.array([angle / 180.0, angle_score, dist_score, near_score, facing], dtype=np.float32)
def query_action(angle, angle_score, dist_score, near_score, facing, top_k=1):
vec = encode_state(angle, angle_score, dist_score, near_score, facing)
result = col.search(
data=[vec],
anns_field="state_vec",
param={"nprobe": 16},
limit=top_k,
output_fields=["action"],
)
actions = [hit.entity.get("action") for hit in result[0]]
return actions[0] if top_k == 1 else actions
# Example use
action = query_action(63.55, 0.45, 0.81, 0.18, -0.48)
print(f"🎮 Suggested Action: {action}")