langchain/libs/partners/voyageai/tests/integration_tests/test_embeddings.py
Erick Friis 7ce81eb6f4
voyageai[patch]: init package (#19098)
Co-authored-by: fodizoltan <zoltan@conway.expert>
Co-authored-by: Yujie Qian <thomasq0809@gmail.com>
Co-authored-by: fzowl <160063452+fzowl@users.noreply.github.com>
2024-03-15 00:56:10 +00:00

54 lines
1.7 KiB
Python

"""Test VoyageAI embeddings."""
from langchain_voyageai import VoyageAIEmbeddings
# Please set VOYAGE_API_KEY in the environment variables
MODEL = "voyage-2"
def test_langchain_voyageai_embedding_documents() -> None:
"""Test voyage embeddings."""
documents = ["foo bar"]
embedding = VoyageAIEmbeddings(model=MODEL)
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 1024
def test_langchain_voyageai_embedding_documents_multiple() -> None:
"""Test voyage embeddings."""
documents = ["foo bar", "bar foo", "foo"]
embedding = VoyageAIEmbeddings(model=MODEL, batch_size=2)
output = embedding.embed_documents(documents)
assert len(output) == 3
assert len(output[0]) == 1024
assert len(output[1]) == 1024
assert len(output[2]) == 1024
def test_langchain_voyageai_embedding_query() -> None:
"""Test voyage embeddings."""
document = "foo bar"
embedding = VoyageAIEmbeddings(model=MODEL)
output = embedding.embed_query(document)
assert len(output) == 1024
async def test_langchain_voyageai_async_embedding_documents_multiple() -> None:
"""Test voyage embeddings."""
documents = ["foo bar", "bar foo", "foo"]
embedding = VoyageAIEmbeddings(model=MODEL, batch_size=2)
output = await embedding.aembed_documents(documents)
assert len(output) == 3
assert len(output[0]) == 1024
assert len(output[1]) == 1024
assert len(output[2]) == 1024
async def test_langchain_voyageai_async_embedding_query() -> None:
"""Test voyage embeddings."""
document = "foo bar"
embedding = VoyageAIEmbeddings(model=MODEL)
output = await embedding.aembed_query(document)
assert len(output) == 1024