HuggingFaceModelLoader#

class langchain_community.document_loaders.hugging_face_model.HuggingFaceModelLoader(*, search: str | None = None, author: str | None = None, filter: str | None = None, sort: str | None = None, direction: str | None = None, limit: int | None = 3, full: bool | None = None, config: bool | None = None)[source]#

Load model information from Hugging Face Hub, including README content.

This loader interfaces with the Hugging Face Models API to fetch and load model metadata and README files. The API allows you to search and filter models based on specific criteria such as model tags, authors, and more.

API URL: https://huggingface.co/api/models DOC URL: https://huggingface.co/docs/hub/en/api

Examples

from langchain_community.document_loaders import HuggingFaceModelLoader

# Initialize the loader with search criteria
loader = HuggingFaceModelLoader(search="bert", limit=10)

# Load models
documents = loader.load()

# Iterate through the fetched documents
for doc in documents:
    print(doc.page_content)  # README content of the model
    print(doc.metadata)      # Metadata of the model

Initialize the HuggingFaceModelLoader.

Parameters:
  • search (str | None) – Filter based on substrings for repos and their usernames.

  • author (str | None) – Filter models by an author or organization.

  • filter (str | None) – Filter based on tags.

  • sort (str | None) – Property to use when sorting.

  • direction (str | None) – Direction in which to sort.

  • limit (int | None) – Limit the number of models fetched.

  • full (bool | None) – Whether to fetch most model data.

  • config (bool | None) – Whether to also fetch the repo config.

Attributes

BASE_URL

README_BASE_URL

Methods

__init__(*[,Β search,Β author,Β filter,Β sort,Β ...])

Initialize the HuggingFaceModelLoader.

alazy_load()

A lazy loader for Documents.

aload()

Load data into Document objects.

fetch_models()

Fetch model information from Hugging Face Hub.

fetch_readme_content(model_id)

Fetch the README content for a given model.

lazy_load()

Load model information lazily, including README content.

load()

Load data into Document objects.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(*, search: str | None = None, author: str | None = None, filter: str | None = None, sort: str | None = None, direction: str | None = None, limit: int | None = 3, full: bool | None = None, config: bool | None = None)[source]#

Initialize the HuggingFaceModelLoader.

Parameters:
  • search (str | None) – Filter based on substrings for repos and their usernames.

  • author (str | None) – Filter models by an author or organization.

  • filter (str | None) – Filter based on tags.

  • sort (str | None) – Property to use when sorting.

  • direction (str | None) – Direction in which to sort.

  • limit (int | None) – Limit the number of models fetched.

  • full (bool | None) – Whether to fetch most model data.

  • config (bool | None) – Whether to also fetch the repo config.

async alazy_load() β†’ AsyncIterator[Document]#

A lazy loader for Documents.

Return type:

AsyncIterator[Document]

async aload() β†’ List[Document]#

Load data into Document objects.

Return type:

List[Document]

fetch_models() β†’ List[dict][source]#

Fetch model information from Hugging Face Hub.

Return type:

List[dict]

fetch_readme_content(model_id: str) β†’ str[source]#

Fetch the README content for a given model.

Parameters:

model_id (str) –

Return type:

str

lazy_load() β†’ Iterator[Document][source]#

Load model information lazily, including README content.

Return type:

Iterator[Document]

load() β†’ List[Document]#

Load data into Document objects.

Return type:

List[Document]

load_and_split(text_splitter: TextSplitter | None = None) β†’ List[Document]#

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters:

text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns:

List of Documents.

Return type:

List[Document]