2024-01-17 01:48:37 +00:00
|
|
|
"""Test MistralAI Embedding"""
|
2024-02-06 23:59:08 +00:00
|
|
|
|
2024-01-17 01:48:37 +00:00
|
|
|
from langchain_mistralai import MistralAIEmbeddings
|
|
|
|
|
|
|
|
|
|
|
|
def test_mistralai_embedding_documents() -> None:
|
|
|
|
"""Test MistralAI embeddings for documents."""
|
|
|
|
documents = ["foo bar", "test document"]
|
|
|
|
embedding = MistralAIEmbeddings()
|
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 2
|
|
|
|
assert len(output[0]) == 1024
|
|
|
|
|
|
|
|
|
|
|
|
def test_mistralai_embedding_query() -> None:
|
|
|
|
"""Test MistralAI embeddings for query."""
|
|
|
|
document = "foo bar"
|
|
|
|
embedding = MistralAIEmbeddings()
|
|
|
|
output = embedding.embed_query(document)
|
|
|
|
assert len(output) == 1024
|
2024-01-18 17:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_mistralai_embedding_documents_async() -> None:
|
|
|
|
"""Test MistralAI embeddings for documents."""
|
|
|
|
documents = ["foo bar", "test document"]
|
|
|
|
embedding = MistralAIEmbeddings()
|
|
|
|
output = await embedding.aembed_documents(documents)
|
|
|
|
assert len(output) == 2
|
|
|
|
assert len(output[0]) == 1024
|
|
|
|
|
|
|
|
|
|
|
|
async def test_mistralai_embedding_query_async() -> None:
|
|
|
|
"""Test MistralAI embeddings for query."""
|
|
|
|
document = "foo bar"
|
|
|
|
embedding = MistralAIEmbeddings()
|
|
|
|
output = await embedding.aembed_query(document)
|
|
|
|
assert len(output) == 1024
|
|
|
|
|
|
|
|
|
|
|
|
def test_mistralai_embedding_documents_long() -> None:
|
|
|
|
"""Test MistralAI embeddings for documents."""
|
2024-02-06 23:59:08 +00:00
|
|
|
documents = ["foo bar " * 1000, "test document " * 1000] * 5
|
2024-01-18 17:45:44 +00:00
|
|
|
embedding = MistralAIEmbeddings()
|
|
|
|
output = embedding.embed_documents(documents)
|
2024-02-06 23:59:08 +00:00
|
|
|
assert len(output) == 10
|
2024-01-18 17:45:44 +00:00
|
|
|
assert len(output[0]) == 1024
|
|
|
|
|
|
|
|
|
|
|
|
def test_mistralai_embed_query_character() -> None:
|
|
|
|
"""Test MistralAI embeddings for query."""
|
|
|
|
document = "😳"
|
|
|
|
embedding = MistralAIEmbeddings()
|
|
|
|
output = embedding.embed_query(document)
|
|
|
|
assert len(output) == 1024
|