Implementation:AI Northstar Tech Vector io Reembed
| Knowledge Sources | |
|---|---|
| Domains | Re_embedding, CLI, Metadata, Parquet |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Concrete CLI script for re-embedding text data in a VDF dataset using a new embedding model, provided by the vector-io library.
Description
The reembed.py module is the command-line entry point for the reembed_vdf command. It reads an existing VDF dataset (or bootstraps metadata for a directory of parquet files), identifies text columns, generates new embeddings via LiteLLM or Sentence Transformers, updates parquet files in place with new vector columns, and updates VDF_META.json with the new model information.
Key functions:
- reembed(): Main entry point — parses CLI args, loads or bootstraps VDF metadata, then delegates to reembed_impl.
- reembed_impl(args, reembed_count): Core implementation — iterates over indexes and namespaces, loads parquet files, identifies text columns, batches text for embedding, generates new vector columns, writes updated parquet files, and updates VDF metadata.
- handle_new_dataset(args): Bootstraps VDF_META.json for a directory of parquet files that lack VDF metadata. Scans parquet schemas for list-type columns (vector columns), prompts for model names, and creates a VDFMeta.
- ask_for_text_column(args, file_path, df): Interactively prompts the user to select text column(s) from the parquet DataFrame. Supports pipe-separated multi-column selection and combines them into a single text column.
- take_input_from_cli_prompt(args): Prompts for model name, dimensions, OpenAI API key, text column, and directory.
- add_arguments_to_parser(parser): Defines CLI arguments: --dir, --new_model_name, --text_column, --dimensions, --batch_size, --overwrite, --quantize, --input_type, --disable_mlx, --env_file_path.
- valid_json(file_path): Validates that a file contains parseable JSON.
Usage
Import and invoke this module when you need to regenerate embeddings for an existing VDF dataset using a different embedding model. It is the standard entry point for the reembed_vdf console script.
Code Reference
Source Location
- Repository: vector-io
- File: src/vdf_io/scripts/reembed.py
Signature
def reembed() -> None:
"""Main entry point: parse CLI args, load/bootstrap metadata, run reembedding."""
def reembed_impl(args: dict, reembed_count: int) -> None:
"""
Core reembedding implementation.
Iterates over VDF indexes and namespaces, loads parquet files, generates
new embeddings for text columns, writes updated parquet files in place,
and updates VDF_META.json with new model and vector column info.
Args:
args: CLI argument dict with 'dir', 'new_model_name', 'text_column', etc.
reembed_count: Initial count of re-embedded vectors (usually 0)
"""
def handle_new_dataset(args: dict) -> None:
"""
Bootstrap VDF_META.json for a directory of parquet files without VDF metadata.
Scans parquet schemas for list-type columns, prompts for model names,
and creates a VDFMeta with NamespaceMeta.
Args:
args: CLI args with 'dir' (directory path)
"""
def ask_for_text_column(args: dict, file_path: str, df: pd.DataFrame) -> None:
"""
Interactively prompt user to select text column(s) from a DataFrame.
Supports pipe-separated multi-column selection. Combines selected columns
into a single text column by joining with spaces.
Args:
args: CLI args dict (updates 'text_column' key)
file_path: Parquet file path (for error messages)
df: Loaded parquet DataFrame
"""
def add_arguments_to_parser(parser: argparse.ArgumentParser) -> None:
"""Add all CLI arguments to the reembed parser."""
def take_input_from_cli_prompt(args: dict) -> None:
"""Prompt for model name, dimensions, API key, text column, directory."""
Import
from vdf_io.scripts.reembed import reembed, reembed_impl, handle_new_dataset, ask_for_text_column
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --dir | str (CLI) | Yes | VDF dataset directory |
| --new_model_name | str (CLI) | No | Embedding model name (default: "text-embedding-3-small") |
| --text_column | str (CLI) | No | Text column name (default: "text") |
| --dimensions | int (CLI) | No | Output dimensions |
| --batch_size | int (CLI) | No | Batch size (default: 96) |
| --overwrite | bool (CLI) | No | Overwrite existing vector columns (default: False) |
| --quantize | str (CLI) | No | Quantization: int8/binary/float32/uint8/ubinary (default: float32) |
| --input_type | str (CLI) | No | Input type hint for model |
| --disable_mlx | bool (CLI) | No | Disable MLX backend (default: False) |
| OPENAI_API_KEY | str (env) | No | For LiteLLM-based embedding |
Outputs
| Name | Type | Description |
|---|---|---|
| parquet files | Files on disk | Updated with new vector column |
| VDF_META.json | File on disk | Updated with new model_map, vector_columns, dimensions |
| new_vector_column | str | Auto-generated name: vec_{text_column}_{model}_dim{N} |
Usage Examples
Command-Line Re-embedding
# Re-embed a VDF dataset with text-embedding-3-small
reembed_vdf --dir ./vdf_20240125_130746_ac5a6 \
--new_model_name text-embedding-3-small \
--text_column text \
--dimensions 1536 \
--batch_size 96
# Re-embed with a HuggingFace model (uses Sentence Transformers)
reembed_vdf --dir ./vdf_data \
--new_model_name huggingface/TaylorAI/bge-micro-v2 \
--text_column title|body
# Re-embed with quantization
reembed_vdf --dir ./vdf_data \
--new_model_name text-embedding-3-large \
--dimensions 3072 \
--quantize int8
Bootstrapping a New Dataset
# If VDF_META.json doesn't exist, handle_new_dataset bootstraps it
reembed_vdf --dir ./my_parquet_dir --new_model_name text-embedding-3-small
# Scans parquet files, detects vector columns, prompts for model info
Programmatic Usage
import argparse
from vdf_io.scripts.reembed import reembed, add_arguments_to_parser
# Build parser and run reembedding
parser = argparse.ArgumentParser(description="Reembed a vector dataset")
add_arguments_to_parser(parser)
# args would be set from CLI or programmatically
Related Pages
Implements Principle
- Principle:AI_Northstar_Tech_Vector_io_Re_embedding
- Principle:AI_Northstar_Tech_Vector_io_VDF_Metadata_Schema
Requires Environment
Uses Heuristic
Related Implementations
- Uses Implementation:AI_Northstar_Tech_Vector_io_Call_Litellm (embedding generation)
- Uses Implementation:AI_Northstar_Tech_Vector_io_Get_Parquet_Files (parquet loading)
- Uses Implementation:AI_Northstar_Tech_Vector_io_Set_Arg_From_Input (interactive prompting)