2022-11-27 08:24:59 +00:00
|
|
|
"""Test HuggingFaceHub embeddings."""
|
2022-11-27 21:03:09 +00:00
|
|
|
import pytest
|
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.embeddings import HuggingFaceHubEmbeddings
|
2022-11-27 08:24:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_huggingfacehub_embedding_documents() -> None:
|
|
|
|
"""Test huggingfacehub embeddings."""
|
|
|
|
documents = ["foo bar"]
|
|
|
|
embedding = HuggingFaceHubEmbeddings()
|
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 1
|
|
|
|
assert len(output[0]) == 768
|
|
|
|
|
|
|
|
|
2024-01-12 05:52:55 +00:00
|
|
|
async def test_huggingfacehub_embedding_async_documents() -> None:
|
|
|
|
"""Test huggingfacehub embeddings."""
|
|
|
|
documents = ["foo bar"]
|
|
|
|
embedding = HuggingFaceHubEmbeddings()
|
|
|
|
output = await embedding.aembed_documents(documents)
|
|
|
|
assert len(output) == 1
|
|
|
|
assert len(output[0]) == 768
|
|
|
|
|
|
|
|
|
2022-11-27 08:24:59 +00:00
|
|
|
def test_huggingfacehub_embedding_query() -> None:
|
|
|
|
"""Test huggingfacehub embeddings."""
|
|
|
|
document = "foo bar"
|
|
|
|
embedding = HuggingFaceHubEmbeddings()
|
|
|
|
output = embedding.embed_query(document)
|
|
|
|
assert len(output) == 768
|
2022-11-27 21:03:09 +00:00
|
|
|
|
|
|
|
|
2024-01-12 05:52:55 +00:00
|
|
|
async def test_huggingfacehub_embedding_async_query() -> None:
|
|
|
|
"""Test huggingfacehub embeddings."""
|
|
|
|
document = "foo bar"
|
|
|
|
embedding = HuggingFaceHubEmbeddings()
|
|
|
|
output = await embedding.aembed_query(document)
|
|
|
|
assert len(output) == 768
|
|
|
|
|
|
|
|
|
2022-11-27 21:03:09 +00:00
|
|
|
def test_huggingfacehub_embedding_invalid_repo() -> None:
|
|
|
|
"""Test huggingfacehub embedding repo id validation."""
|
|
|
|
# Only sentence-transformers models are currently supported.
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
HuggingFaceHubEmbeddings(repo_id="allenai/specter")
|