Environment:AI Northstar Tech Vector io HuggingFace Hub
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Data_Sharing |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Python environment with HuggingFace Hub integration for uploading and downloading vector datasets in VDF format.
Description
This environment provides the HuggingFace Hub client context for sharing vector datasets. It uses the `huggingface_hub` library's `HfApi` for dataset repository creation and file uploads, and `HfFileSystem` for reading parquet files directly from HuggingFace datasets. The environment supports both public and private dataset repositories and handles authentication via the HuggingFace API token. It is layered on top of the Python_CLI environment.
Usage
Use this environment when running the Push_To_Hub implementation to upload exported VDF datasets to the HuggingFace Hub. Also required when importing datasets directly from HuggingFace (via the `--hf_dataset` flag in `import_vdf`). The `HUGGING_FACE_TOKEN` must have write access for pushing datasets.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, or Windows | Cross-platform Python environment |
| Hardware | CPU only | No GPU required; network I/O bound |
| Disk | Variable | Sufficient for the dataset being uploaded or downloaded |
| Python | Python 3.8+ | Required by huggingface_hub |
| Network | Internet access | Required to reach huggingface.co APIs |
Dependencies
System Packages
- Python 3.8+ runtime
Python Packages
- `huggingface_hub`
- `datasets` ~= 2.16, >= 2.19.0 (for HuggingFace dataset streaming)
- `pyarrow` (for parquet file handling)
Credentials
The following environment variables must be set:
- `HUGGING_FACE_TOKEN`: HuggingFace API token with write access (for pushing datasets). If not set in environment, the CLI will prompt via `getpass`.
- `HF_USERNAME`: HuggingFace username for the dataset repository namespace. Can also be passed via `--HF_USERNAME` CLI argument. If not set, the CLI will prompt interactively.
Quick Install
# Install HuggingFace Hub dependencies
pip install huggingface_hub datasets pyarrow
# Set credentials
export HUGGING_FACE_TOKEN="hf_your_write_token_here"
export HF_USERNAME="your_hf_username"
# Or use a .env file
echo "HUGGING_FACE_TOKEN=hf_your_write_token_here" >> .env
echo "HF_USERNAME=your_hf_username" >> .env
Code Evidence
Token check and interactive prompt from `push_to_hub_vdf.py:14-21`:
if (
"HUGGING_FACE_TOKEN" not in os.environ
or os.environ["HUGGING_FACE_TOKEN"] is None
):
os.environ["HUGGING_FACE_TOKEN"] = getpass(
prompt="Enter your HuggingFace API token (with write access): "
)
Username resolution from `push_to_hub_vdf.py:23-31`:
if (
"HF_USERNAME" not in args
or args["HF_USERNAME"] is None
or args["HF_USERNAME"] == ""
):
if "HF_USERNAME" not in os.environ or os.environ["HF_USERNAME"] is None:
os.environ["HF_USERNAME"] = input("Enter your HuggingFace username: ")
else:
os.environ["HF_USERNAME"] = args["HF_USERNAME"]
Repository creation and folder upload from `push_to_hub_vdf.py:42-54`:
dataset_url = hf_api.create_repo(
token=os.environ["HUGGING_FACE_TOKEN"],
repo_id=repo_id,
private=(not args["public"]),
repo_type="dataset",
exist_ok=True,
)
hf_api.upload_folder(
repo_id=repo_id,
folder_path=data_path,
repo_type="dataset",
)
HuggingFace filesystem read from `util.py:333-341`:
from huggingface_hub import HfFileSystem
fs = HfFileSystem()
return [
"hf://" + x
for x in fs.glob(
f"datasets/{args.get('hf_dataset')}/{data_path if data_path!='.' else ''}/**.parquet"
)
]
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `HfApi HTTP 401 Unauthorized` | Invalid or expired HuggingFace token | Regenerate token at huggingface.co/settings/tokens with write access |
| `Repository Not Found` | Dataset repo does not exist or is private without auth | Ensure `HF_USERNAME` and `HUGGING_FACE_TOKEN` are set correctly |
| `ValueError: Cannot upload to a repo without write access` | Token lacks write permission | Create a token with `write` permission scope |
| `HfFileSystem glob returns empty` | Dataset path or name is incorrect | Verify dataset name format: `username/dataset_name` |
Compatibility Notes
- Private datasets: Default is private (`--public` flag must be set explicitly for public datasets).
- Large datasets: The `upload_folder` method handles chunked uploads automatically, but large datasets may take significant time.
- Token types: Must use a token with write access, not just read access, for pushing datasets.
- Dataset naming: The script auto-prefixes dataset names with `vdf_` if a name is provided; otherwise uses the directory name.