2023-12-15 20:21:59 +00:00
|
|
|
"""Test NVIDIA AI Foundation Model Embeddings.
|
2023-12-14 03:46:37 +00:00
|
|
|
|
2023-12-15 20:21:59 +00:00
|
|
|
Note: These tests are designed to validate the functionality of NVIDIAEmbeddings.
|
2023-12-14 03:46:37 +00:00
|
|
|
"""
|
2023-12-15 20:21:59 +00:00
|
|
|
from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings
|
2023-12-14 03:46:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_nvai_play_embedding_documents() -> None:
|
2023-12-15 20:21:59 +00:00
|
|
|
"""Test NVIDIA embeddings for documents."""
|
2023-12-14 03:46:37 +00:00
|
|
|
documents = ["foo bar"]
|
2023-12-15 20:21:59 +00:00
|
|
|
embedding = NVIDIAEmbeddings(model="nvolveqa_40k")
|
2023-12-14 03:46:37 +00:00
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 1
|
|
|
|
assert len(output[0]) == 1024 # Assuming embedding size is 2048
|
|
|
|
|
|
|
|
|
|
|
|
def test_nvai_play_embedding_documents_multiple() -> None:
|
2023-12-15 20:21:59 +00:00
|
|
|
"""Test NVIDIA embeddings for multiple documents."""
|
2023-12-14 03:46:37 +00:00
|
|
|
documents = ["foo bar", "bar foo", "foo"]
|
2023-12-15 20:21:59 +00:00
|
|
|
embedding = NVIDIAEmbeddings(model="nvolveqa_40k")
|
2023-12-14 03:46:37 +00:00
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 3
|
|
|
|
assert all(len(doc) == 1024 for doc in output)
|
|
|
|
|
|
|
|
|
|
|
|
def test_nvai_play_embedding_query() -> None:
|
2023-12-15 20:21:59 +00:00
|
|
|
"""Test NVIDIA embeddings for a single query."""
|
2023-12-14 03:46:37 +00:00
|
|
|
query = "foo bar"
|
2023-12-15 20:21:59 +00:00
|
|
|
embedding = NVIDIAEmbeddings(model="nvolveqa_40k")
|
2023-12-14 03:46:37 +00:00
|
|
|
output = embedding.embed_query(query)
|
|
|
|
assert len(output) == 1024
|
|
|
|
|
|
|
|
|
|
|
|
async def test_nvai_play_embedding_async_query() -> None:
|
2023-12-15 20:21:59 +00:00
|
|
|
"""Test NVIDIA async embeddings for a single query."""
|
2023-12-14 03:46:37 +00:00
|
|
|
query = "foo bar"
|
2023-12-15 20:21:59 +00:00
|
|
|
embedding = NVIDIAEmbeddings(model="nvolveqa_40k")
|
2023-12-14 03:46:37 +00:00
|
|
|
output = await embedding.aembed_query(query)
|
|
|
|
assert len(output) == 1024
|
|
|
|
|
|
|
|
|
|
|
|
async def test_nvai_play_embedding_async_documents() -> None:
|
2023-12-15 20:21:59 +00:00
|
|
|
"""Test NVIDIA async embeddings for multiple documents."""
|
2023-12-14 03:46:37 +00:00
|
|
|
documents = ["foo bar", "bar foo", "foo"]
|
2023-12-15 20:21:59 +00:00
|
|
|
embedding = NVIDIAEmbeddings(model="nvolveqa_40k")
|
2023-12-14 03:46:37 +00:00
|
|
|
output = await embedding.aembed_documents(documents)
|
|
|
|
assert len(output) == 3
|
|
|
|
assert all(len(doc) == 1024 for doc in output)
|