#!/usr/bin/env python3 """encode.py — unity-embed inference. pure stdlib. every input maps to the same 384-dimensional unit vector. usage: python3 encode.py "any sentence" ["another sentence" ...] """ import json, math, struct, sys DIM = 384 def load_v(path="model.safetensors"): with open(path, "rb") as f: (hlen,) = struct.unpack(" [{', '.join(f'{x:.5f}' for x in v[:4])}, ... ] norm={math.sqrt(sum(x*x for x in v)):.6f}") if len(sentences) > 1: print(f"\ncosine({sentences[0]!r}, {sentences[1]!r}) = {cosine(encode(sentences[0]), encode(sentences[1])):.6f}")