MCPcopy Create free account
hub / github.com/MinishLab/vicinity / load_from_hub

Function load_from_hub

vicinity/integrations/huggingface.py:101–132  ·  view source on GitHub ↗

Load a Vicinity instance from the Hugging Face Hub. :param repo_id: The repository ID on the Hugging Face Hub. :param token: Optional authentication token for private repositories. :param **kwargs: Additional arguments passed to load_dataset. :return: A Vicinity instance loaded

(
    repo_id: str, token: str | None = None, **kwargs: Any
)

Source from the content-addressed store, hash-verified

99
100
101def load_from_hub(
102 repo_id: str, token: str | None = None, **kwargs: Any
103) -> tuple[list[dict[str, Any]], BasicVectorStore | None, AbstractBackend, dict[str, Any]]:
104 """
105 Load a Vicinity instance from the Hugging Face Hub.
106
107 :param repo_id: The repository ID on the Hugging Face Hub.
108 :param token: Optional authentication token for private repositories.
109 :param **kwargs: Additional arguments passed to load_dataset.
110 :return: A Vicinity instance loaded from the Hub.
111 """
112 # Load dataset and extract items and vectors
113 dataset = load_dataset(repo_id, token=token, split="train", **kwargs)
114 has_vectors = "vectors" in dataset.column_names
115 if has_vectors:
116 vectors = dataset["vectors"]
117 if _VICINITY_ITEM_COLUMN in dataset.column_names:
118 items = dataset[_VICINITY_ITEM_COLUMN]
119 else:
120 # Remove the vectors column (if it exists) and then convert to a list.
121 if has_vectors:
122 dataset = dataset.remove_columns("vectors")
123 items = dataset.to_list()
124 vector_store = BasicVectorStore(vectors=vectors) if has_vectors else None
125
126 # Download and load config and backend
127 repo_path = Path(snapshot_download(repo_id=repo_id, token=token, repo_type="dataset"))
128 with open(repo_path / "config.json") as f:
129 config = json.load(f)
130 backend_type = Backend(config["backend_type"])
131 backend = get_backend_class(backend_type).load(repo_path / "backend")
132 return items, vector_store, backend, config

Callers 1

load_from_hubMethod · 0.90

Calls 4

BasicVectorStoreClass · 0.90
BackendClass · 0.90
get_backend_classFunction · 0.90
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…