Implementation:AI Northstar Tech Vector io ImportVDB
| Knowledge Sources | |
|---|---|
| Domains | Import, Vector_Database, Parquet, Metadata |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Abstract base class for all vector database import implementations, providing VDF metadata validation, parquet file loading, vector format normalization, dimension resolution, and the template method interface for DB-specific data upsertion.
Description
The ImportVDB class defines the contract and shared functionality for importing vector data from a VDF dataset into any supported vector database. It uses the Template Method pattern: the abstract upsert_data() method is implemented by DB-specific subclasses (e.g. ImportPinecone, ImportQdrant), while concrete methods provide shared data processing.
Key concrete methods:
- __init__: Loads and validates VDF_META.json from local disk or HuggingFace Hub. Checks version compatibility using packaging.version.Version. Sets self.vdf_meta, self.id_column, and self.temp_file_paths.
- extract_vector: Normalizes heterogeneous vector formats (list, numpy array, bytes, string-encoded) into a standard List[float]. Sets self.abnormal_vector_format = True when conversion is needed.
- resolve_dims: When dimensions are unknown (-1), inspects the first non-null vector in parquet files to determine dimensionality.
- get_parquet_files: Delegates to the shared get_parquet_files utility, with lru_cache to avoid redundant scans.
- create_new_name: Generates a unique index name by appending incremental suffixes (e.g. "my_index-2", "my_index-3") when --create_new is set.
- get_vector_column_name: Extracts vector column names from namespace metadata, warning when multiple columns exist and the target DB doesn't support multi-vectors.
The __init_subclass__ hook enforces that every subclass defines a DB_NAME_SLUG class variable.
Usage
Subclass ImportVDB when adding support for importing into a new vector database. The subclass must:
- Define DB_NAME_SLUG class variable (registered in DBNames enum)
- Implement upsert_data(), import_vdb(), make_parser()
- Use get_parquet_files(), extract_vector(), and resolve_dims() for data processing
Code Reference
Source Location
- Repository: vector-io
- File: src/vdf_io/import_vdf/vdf_import_cls.py
Signature
class ImportVDB(abc.ABC):
# Enforced via __init_subclass__: every subclass must define DB_NAME_SLUG
DB_NAME_SLUG: str # e.g. "pinecone", "qdrant"
def __init__(self, args: dict) -> None:
"""
Load and validate VDF_META.json from local dir or HuggingFace Hub.
Check version compatibility. Set self.vdf_meta, self.id_column.
Args:
args: CLI argument dict. Must contain 'dir' (str) or 'hf_dataset' (str),
and 'library_version' (str).
"""
@abc.abstractmethod
def upsert_data(self) -> None:
"""Import vectors from parquet files into the target vector database. DB-specific."""
def get_vector_column_name(
self, index_name: str, namespace_meta: dict, multi_vector_supported: bool = False
) -> Tuple[List[str], str]:
"""Extract vector column names from namespace metadata."""
@lru_cache(maxsize=1)
def get_parquet_files(self, data_path: str) -> List[str]:
"""Delegate to shared get_parquet_files utility. Cached."""
def resolve_dims(self, namespace_meta: dict, index_name: str) -> int:
"""
When dimensions are -1 (unknown), inspect first non-null vector
in parquet files to determine dimensionality.
"""
def extract_vector(self, v: Any) -> Optional[List[float]]:
"""
Normalize heterogeneous vector formats to List[float].
Handles: list, np.ndarray, bytes (decoded as utf-8 literal),
str (parsed as literal), scalar.
Sets self.abnormal_vector_format = True when conversion is needed.
"""
def create_new_name(
self, index_name: str, indexes: List[str], delimiter: str = "-"
) -> str:
"""
Generate a unique index name by appending incremental numeric suffixes.
Args:
index_name: Desired index name
indexes: Existing index names in target DB
delimiter: Suffix delimiter (default: "-")
Returns:
Unique index name (e.g. "my_index-2") if --create_new is set,
otherwise the original index_name.
"""
def cleanup(self) -> None:
"""Remove temporary parquet files downloaded from HuggingFace."""
def set_dims(self, namespace_meta: dict, index_name: str) -> None:
"""Resolve dimensions if unknown and update namespace_meta in place."""
Import
from vdf_io.import_vdf.vdf_import_cls import ImportVDB
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| args | dict | Yes | CLI args with 'dir' or 'hf_dataset', 'library_version' |
| v | Any | Yes (extract_vector) | Raw vector (list, ndarray, bytes, str, or scalar) |
| namespace_meta | dict | Yes (resolve_dims) | Per-namespace metadata from VDF_META.json |
| index_name | str | Yes (resolve_dims) | Name of the index |
| index_name | str | Yes (create_new_name) | Desired index name |
| indexes | List[str] | Yes (create_new_name) | Existing index names in target DB |
Outputs
| Name | Type | Description |
|---|---|---|
| self.vdf_meta | dict | Parsed VDF_META.json content |
| self.id_column | str | ID column name from VDF metadata |
| extract_vector returns | Optional[List[float]] | Normalized vector or None |
| resolve_dims returns | int | Resolved dimension count (-1 if failed) |
| create_new_name returns | str | Unique index name |
| total_imported_count | int | Count of vectors upserted (set by subclass) |
Usage Examples
Subclassing ImportVDB
from vdf_io.import_vdf.vdf_import_cls import ImportVDB
from vdf_io.names import DBNames
from vdf_io.util import divide_into_batches
from tqdm import tqdm
class ImportMyDB(ImportVDB):
DB_NAME_SLUG = DBNames.MYDB
@classmethod
def import_vdb(cls, args):
obj = cls(args)
obj.upsert_data()
return obj
def upsert_data(self):
for index_name, namespace_list in self.vdf_meta["indexes"].items():
for namespace_meta in namespace_list:
self.set_dims(namespace_meta, index_name)
data_path = namespace_meta["data_path"]
final_path = self.get_final_data_path(data_path)
parquet_files = self.get_parquet_files(final_path)
_, vec_col = self.get_vector_column_name(index_name, namespace_meta)
for file in parquet_files:
df = self.read_parquet_progress(file)
for batch in divide_into_batches(df, self.args["batch_size"]):
vectors = {}
metadata = {}
for _, row in batch.iterrows():
vec = self.extract_vector(row[vec_col])
if vec is not None:
vectors[row[self.id_column]] = vec
self._upsert_batch(index_name, vectors, metadata)
Vector Format Normalization
# extract_vector handles multiple input formats:
self.extract_vector([0.1, 0.2, 0.3]) # list -> [0.1, 0.2, 0.3]
self.extract_vector(np.array([0.1, 0.2, 0.3])) # ndarray -> [0.1, 0.2, 0.3]
self.extract_vector(b"[0.1, 0.2, 0.3]") # bytes -> [0.1, 0.2, 0.3]
self.extract_vector("[0.1, 0.2, 0.3]") # str -> [0.1, 0.2, 0.3]
# abnormal_vector_format is set True for non-list inputs
Creating Unique Index Names
# If --create_new is set and "my_index" already exists:
new_name = self.create_new_name("my_index", ["my_index", "my_index-2", "other"])
# Returns: "my_index-3" (next available suffix)
Related Pages
Implements Principle
- Principle:AI_Northstar_Tech_Vector_io_VDF_Metadata_Schema
- Principle:AI_Northstar_Tech_Vector_io_Parquet_Discovery_Loading
- Principle:AI_Northstar_Tech_Vector_io_Vector_Format_Normalization
- Principle:AI_Northstar_Tech_Vector_io_Index_Collection_Creation
- Principle:AI_Northstar_Tech_Vector_io_Batched_Data_Upsertion
Requires Environment
Uses Heuristic
Related Implementations
- Uses Implementation:AI_Northstar_Tech_Vector_io_Get_Parquet_Files (parquet discovery and loading)
- Uses Implementation:AI_Northstar_Tech_Vector_io_Standardize_Metric (metric resolution)