Principle:AI Northstar Tech Vector io Vector Format Normalization
| Knowledge Sources | |
|---|---|
| Domains | Vector_Database, Data_Normalization, Import |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
A data normalization pattern that converts heterogeneous vector representations (lists, numpy arrays, bytes, strings, scalars) into a canonical List[float] format for uniform database insertion.
Description
Vector Format Normalization addresses the problem that vector data stored in parquet files can have multiple representations depending on how it was originally exported:
- Python list: The ideal format — a list of floats with length > 1. No conversion needed.
- NumPy ndarray: May be a 1-D or 2-D array. 2-D arrays are indexed into the first row. Conversion via ndarray.tolist().
- Bytes: A UTF-8 encoded string representation of a list. Decoded and parsed via ast.literal_eval.
- String: A string-encoded list (e.g. "[0.1, 0.2, 0.3]"). Parsed via ast.literal_eval.
- Scalar: A single float value. Passed through as-is.
When conversion is needed (any format other than a plain list), the pattern sets a flag (abnormal_vector_format) to alert the system that the source data was not in the ideal format. This flag can be used for diagnostics or to warn the user.
After conversion, all elements are coerced to float to ensure numeric consistency regardless of the source type (int, float, numpy scalar).
Usage
Use this principle when designing systems that need to process vector data from heterogeneous sources where the storage format may vary. It is suited for:
- Import tools that read parquet files produced by different exporters
- Data pipeline tools that aggregate vectors from multiple sources
- Systems where vector format consistency is critical for downstream operations
Theoretical Basis
The normalization decision tree:
# Abstract algorithm (NOT real implementation)
def extract_vector(v):
if isinstance(v, list) and len(v) > 1:
return [float(x) for x in v] # Already a list
elif isinstance(v, np.ndarray):
if v.shape[0] > 1:
return [float(x) for x in v.tolist()] # 1-D array
elif v.shape[0] == 1:
return [float(x) for x in v[0].tolist()] # 2-D array, take first row
elif isinstance(v, bytes):
return [float(x) for x in ast.literal_eval(v.decode("utf-8"))]
elif isinstance(v, str):
return [float(x) for x in ast.literal_eval(v)]
else:
return float(v) # Scalar passthrough