Implementation:AI Northstar Tech Vector io ExportVDB
| Knowledge Sources | |
|---|---|
| Domains | Export, Vector_Database, Parquet, Metadata |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Abstract base class for all vector database export implementations, providing parquet serialization, VDF metadata generation, and the template method interface for DB-specific data retrieval.
Description
The ExportVDB class defines the contract and shared functionality for exporting vector data from any supported vector database to the VDF format. It uses the Template Method pattern: abstract methods (get_index_names, get_all_index_names, get_data, export_vdb, make_parser) are implemented by DB-specific subclasses (e.g. ExportPinecone, ExportQdrant), while concrete methods provide shared parquet serialization and metadata generation.
The __init_subclass__ hook enforces that every subclass defines a DB_NAME_SLUG class variable, which is used by the CLI for dynamic registration.
Key concrete methods:
- save_vectors_to_parquet: Merges vector and metadata dicts into a pandas DataFrame, writes to parquet, and tracks the evolving schema.
- get_namespace_meta: Builds a NamespaceMeta Pydantic model with index statistics, metric (standardized via standardize_metric), dimensions, and model mapping.
- get_basic_vdf_meta: Builds a VDFMeta Pydantic model aggregating all namespace metas with version, author, and export source.
- create_vec_dir: Creates a per-index subdirectory within the VDF export directory.
Usage
Subclass ExportVDB when adding support for a new vector database export. The subclass must:
- Define DB_NAME_SLUG class variable (registered in DBNames enum)
- Implement get_index_names(), get_all_index_names(), get_data(), export_vdb(), make_parser()
- Call save_vectors_to_parquet() during data retrieval to write batches
- Call get_namespace_meta() and get_basic_vdf_meta() to generate VDF metadata
Code Reference
Source Location
- Repository: vector-io
- File: src/vdf_io/export_vdf/vdb_export_cls.py
Signature
class ExportVDB(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:
"""
Initialize export: create timestamped VDF directory, compute data hash.
Args:
args: CLI argument dict (credentials, model_name, etc.)
"""
@abc.abstractmethod
def get_index_names(self) -> List[str]:
"""Get user-selected index names from vector database."""
@abc.abstractmethod
def get_all_index_names(self) -> List[str]:
"""Get all available index names from vector database."""
@abc.abstractmethod
def get_data(self) -> "ExportVDB":
"""Retrieve vectors and metadata from the vector database. DB-specific."""
@classmethod
@abc.abstractmethod
def export_vdb(cls, args: dict) -> "ExportVDB":
"""Factory classmethod: instantiate and run the full export."""
@classmethod
@abc.abstractmethod
def make_parser(cls, subparsers) -> None:
"""Register CLI subparser with DB-specific arguments."""
def save_vectors_to_parquet(
self,
vectors: dict,
metadata: dict,
vectors_directory: str,
) -> int:
"""
Merge vectors and metadata into a DataFrame, write to parquet, update schema.
Args:
vectors: Dict mapping {id: [float values]}
metadata: Dict mapping {id: {key: value}}
vectors_directory: Output directory path
Returns:
Number of rows written.
"""
def create_vec_dir(self, index_name: str) -> str:
"""Create a per-index subdirectory within the VDF export directory."""
def get_basic_vdf_meta(self, index_metas: dict) -> VDFMeta:
"""Build VDFMeta Pydantic model from all namespace metas."""
def get_namespace_meta(
self,
index_name: str,
vectors_directory: str,
total: int,
num_vectors_exported: int,
dim: int,
index_config: dict = None,
vector_columns: list = None,
distance: str = None,
) -> NamespaceMeta:
"""
Build NamespaceMeta Pydantic model for a single index/namespace.
Args:
index_name: Name of the index/collection
vectors_directory: Directory containing parquet files
total: Total vectors in the source index
num_vectors_exported: Number of vectors actually exported
dim: Vector dimensions
index_config: Optional DB-specific index configuration
vector_columns: List of vector column names (default: ["vector"])
distance: Source DB metric name (to be standardized)
"""
Import
from vdf_io.export_vdf.vdb_export_cls import ExportVDB
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| args | dict | Yes | CLI argument dict with credentials, model_name, library_version |
| vectors | dict | Yes (save_vectors_to_parquet) | {id: [float values]} mapping |
| metadata | dict | No (save_vectors_to_parquet) | {id: {key: value}} mapping |
| vectors_directory | str | Yes | Output directory for parquet files |
| index_name | str | Yes (get_namespace_meta) | Source index/collection name |
| total | int | Yes (get_namespace_meta) | Total vectors in source index |
| num_vectors_exported | int | Yes (get_namespace_meta) | Count of exported vectors |
| dim | int | Yes (get_namespace_meta) | Vector dimensionality |
| distance | str | No (get_namespace_meta) | Source DB metric name |
Outputs
| Name | Type | Description |
|---|---|---|
| vdf_directory | str | Timestamped export directory (vdf_<timestamp>_<hash>) |
| parquet files | Files on disk | {file_ctr}.parquet in each index subdirectory |
| parquet_schema | pyarrow.Schema | Unified schema across all parquet files |
| NamespaceMeta | NamespaceMeta | Pydantic model for a single namespace |
| VDFMeta | VDFMeta | Pydantic model aggregating all namespaces |
| save_vectors_to_parquet returns | int | Row count written |
Usage Examples
Subclassing ExportVDB
from vdf_io.export_vdf.vdb_export_cls import ExportVDB
from vdf_io.names import DBNames
class ExportMyDB(ExportVDB):
DB_NAME_SLUG = DBNames.MYDB # Must be defined or __init_subclass__ raises
@classmethod
def export_vdb(cls, args):
obj = cls(args)
obj.get_data() # DB-specific retrieval
return obj
def get_data(self):
for index_name in self.get_index_names():
vec_dir = self.create_vec_dir(index_name)
vectors, metadata = self._fetch_from_db(index_name)
self.save_vectors_to_parquet(vectors, metadata, vec_dir)
def get_index_names(self):
# Return user-selected indexes
return ["my_collection"]
def get_all_index_names(self):
# Return all available indexes
return ["my_collection", "other_collection"]
@classmethod
def make_parser(cls, subparsers):
parser = subparsers.add_parser(DBNames.MYDB)
parser.add_argument("--api_key", type=str)
Using save_vectors_to_parquet
# During data retrieval in a DB-specific get_data() implementation:
vectors = {"id_1": [0.1, 0.2, 0.3], "id_2": [0.4, 0.5, 0.6]}
metadata = {"id_1": {"category": "news"}, "id_2": {"category": "sports"}}
row_count = self.save_vectors_to_parquet(vectors, metadata, vec_dir)
# Writes {file_ctr}.parquet, updates self.parquet_schema and self.file_structure
Generating VDF Metadata
# After all data is retrieved for an index:
namespace_meta = self.get_namespace_meta(
index_name="my_collection",
vectors_directory=vec_dir,
total=10000,
num_vectors_exported=10000,
dim=1536,
distance="cosine", # Source DB metric, will be standardized
)
# Aggregate all namespace metas into VDFMeta
index_metas = {"my_collection": [namespace_meta]}
vdf_meta = self.get_basic_vdf_meta(index_metas)
# Write VDF_META.json
import json
with open(f"{self.vdf_directory}/VDF_META.json", "w") as f:
json.dump(vdf_meta.model_dump(), f, indent=4)
Related Pages
Implements Principle
- Principle:AI_Northstar_Tech_Vector_io_Index_Discovery
- Principle:AI_Northstar_Tech_Vector_io_Batched_Data_Retrieval
- Principle:AI_Northstar_Tech_Vector_io_Parquet_Serialization
- Principle:AI_Northstar_Tech_Vector_io_VDF_Metadata_Schema
Requires Environment
Uses Heuristic
Related Implementations
- Uses Implementation:AI_Northstar_Tech_Vector_io_Standardize_Metric (metric standardization in get_namespace_meta)