Implementation:AI Northstar Tech Vector io Import CLI
| Knowledge Sources | |
|---|---|
| Domains | CLI, Import, Plugin_Architecture |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Concrete CLI entry point for importing VDF format data into a target vector database, provided by the vector-io library.
Description
The import_vdf_cli module is the command-line entry point for the import_vdf command. It dynamically discovers all ImportVDB subclasses via pkgutil.walk_packages, builds an argparse-based CLI with subparsers for each supported vector database, and orchestrates the import pipeline. Telemetry is initialized via Sentry and OpenTelemetry (opt-out via DISABLE_TELEMETRY_VECTORIO env var).
The load_subclasses function scans the vdf_io.import_vdf package, imports every module, and collects all classes that subclass ImportVDB. Each subclass is registered by its DB_NAME_SLUG class variable, mapping to its import_vdb classmethod (factory) and make_parser classmethod (CLI subparser setup).
The run_import function constructs the top-level parser, attaches per-DB subparsers, parses CLI args, prompts for the VDF directory if not provided, instantiates the appropriate ImportVDB subclass, and runs cleanup after import completes.
Usage
Import and invoke this module when you need to import a VDF dataset into a vector database from the command line. It is the standard entry point for the import_vdf console script defined in setup.py.
Code Reference
Source Location
- Repository: vector-io
- File: src/vdf_io/import_vdf_cli.py
Signature
def load_subclasses(package_dir: str) -> Tuple[Dict[str, Callable], Dict[str, Callable]]:
"""
Dynamically import all modules in package_dir and collect ImportVDB subclasses.
Args:
package_dir: Dotted package path to scan (e.g. "vdf_io.import_vdf")
Returns:
Tuple of (slug_to_import_func, slug_to_parser_func) dicts mapping
DB_NAME_SLUG -> import_vdb classmethod and DB_NAME_SLUG -> make_parser classmethod.
"""
def run_import(span) -> None:
"""
Build CLI parser with per-DB subparsers, parse args, prompt for VDF directory
if not provided, instantiate the selected ImportVDB subclass, run import,
and clean up temp files.
Args:
span: OpenTelemetry span for telemetry tracing.
"""
def make_common_options(parser: argparse.ArgumentParser) -> None:
"""
Add shared CLI arguments: --dir, --hf_dataset, --subset, --max_num_rows,
--create_new, --vector_columns, --metric, --id_column, --batch_size.
"""
Import
from vdf_io.import_vdf_cli import load_subclasses, run_import, make_common_options
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| package_dir | str | Yes | Dotted package path to scan for ImportVDB subclasses |
| span | trace.Span | Yes | OpenTelemetry span for telemetry |
| --vector_database | str (CLI) | Yes | Subcommand selecting target vector database |
| --dir | str (CLI) | Yes* | Local VDF dataset directory (*required if --hf_dataset not given) |
| --hf_dataset | str (CLI) | Yes* | HuggingFace dataset name (*required if --dir not given) |
| --subset | bool (CLI) | No | Import a subset of data (default: False) |
| --max_num_rows | int (CLI) | No | Maximum number of rows to import |
| --create_new | bool (CLI) | No | Create a new index (default: False) |
| --vector_columns | str (CLI) | No | Vector column names, comma-separated (default: "vector") |
| --metric | str (CLI) | No | Distance metric (default: "Cosine") |
| --id_column | str (CLI) | No | ID column name (default: "id") |
| --batch_size | int (CLI) | No | Batch size for import |
| DB-specific args | varies | Varies | Per-DB credentials and options via subparser |
Outputs
| Name | Type | Description |
|---|---|---|
| slug_to_import_func | Dict[str, Callable] | Maps DB_NAME_SLUG to import_vdb classmethod |
| slug_to_parser_func | Dict[str, Callable] | Maps DB_NAME_SLUG to make_parser classmethod |
| import_obj | ImportVDB | Instantiated import subclass with total_imported_count |
Usage Examples
Command-Line Usage
# Import from local VDF directory into Pinecone
import_vdf pinecone --dir ./vdf_20240125_130746_ac5a6 --create_new
# Import from HuggingFace dataset into Qdrant
import_vdf qdrant --hf_dataset aintech/vdf_20240125_130746_ac5a6_medium_articles
# Import a subset into Milvus
import_vdf milvus --dir ./vdf_data --subset --max_num_rows 1000 --batch_size 500
Programmatic Subclass Discovery
from vdf_io.import_vdf_cli import load_subclasses
# Discover all available import backends
slug_to_import, slug_to_parser = load_subclasses("vdf_io.import_vdf")
print(f"Supported target databases: {list(slug_to_import.keys())}")
# e.g. ['pinecone', 'qdrant', 'milvus', 'vertexai_vector_search', ...]
Related Pages
Implements Principle
Requires Environment
Related Implementations
- Uses Implementation:AI_Northstar_Tech_Vector_io_ImportVDB (instantiates import subclasses)
- Uses Implementation:AI_Northstar_Tech_Vector_io_Set_Arg_From_Input (directory prompting)