mirror of
https://github.com/hwchase17/langchain.git
synced 2026-01-24 05:50:18 +00:00
Compare commits
1 Commits
langchain-
...
isaac/more
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3392ab24ed |
@@ -1,24 +1,15 @@
|
||||
"""Test AI21 embeddings."""
|
||||
|
||||
from langchain_ai21.embeddings import AI21Embeddings
|
||||
from typing import Type
|
||||
import pytest
|
||||
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
|
||||
def test_langchain_ai21_embedding_documents() -> None:
|
||||
"""Test AI21 embeddings."""
|
||||
documents = ["foo bar"]
|
||||
embedding = AI21Embeddings()
|
||||
output = embedding.embed_documents(documents)
|
||||
assert len(output) == 1
|
||||
assert len(output[0]) > 0
|
||||
|
||||
|
||||
def test_langchain_ai21_embedding_query() -> None:
|
||||
"""Test AI21 embeddings."""
|
||||
document = "foo bar"
|
||||
embedding = AI21Embeddings()
|
||||
output = embedding.embed_query(document)
|
||||
assert len(output) > 0
|
||||
|
||||
class TestAI21Embeddings(EmbeddingsIntegrationTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[AI21Embeddings]:
|
||||
return AI21Embeddings
|
||||
|
||||
def test_langchain_ai21_embedding_documents__with_explicit_chunk_size() -> None:
|
||||
"""Test AI21 embeddings with chunk size passed as an argument."""
|
||||
@@ -28,7 +19,6 @@ def test_langchain_ai21_embedding_documents__with_explicit_chunk_size() -> None:
|
||||
assert len(output) == 2
|
||||
assert len(output[0]) > 0
|
||||
|
||||
|
||||
def test_langchain_ai21_embedding_query__with_explicit_chunk_size() -> None:
|
||||
"""Test AI21 embeddings with chunk size passed as an argument."""
|
||||
documents = "foo bar"
|
||||
|
||||
@@ -2,19 +2,14 @@
|
||||
|
||||
from langchain_fireworks.embeddings import FireworksEmbeddings
|
||||
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
from typing import Type
|
||||
|
||||
def test_langchain_fireworks_embedding_documents() -> None:
|
||||
"""Test Fireworks hosted embeddings."""
|
||||
documents = ["foo bar"]
|
||||
embedding = FireworksEmbeddings(model="nomic-ai/nomic-embed-text-v1.5")
|
||||
output = embedding.embed_documents(documents)
|
||||
assert len(output) == 1
|
||||
assert len(output[0]) > 0
|
||||
class TestFireworksEmbeddings(EmbeddingsIntegrationTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[FireworksEmbeddings]:
|
||||
return FireworksEmbeddings
|
||||
|
||||
|
||||
def test_langchain_fireworks_embedding_query() -> None:
|
||||
"""Test Fireworks hosted embeddings."""
|
||||
document = "foo bar"
|
||||
embedding = FireworksEmbeddings(model="nomic-ai/nomic-embed-text-v1.5")
|
||||
output = embedding.embed_query(document)
|
||||
assert len(output) > 0
|
||||
@property
|
||||
def embedding_model_params(self) -> dict:
|
||||
return {"model": "nomic-ai/nomic-embed-text-v1.5"}
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
|
||||
from langchain_fireworks.embeddings import FireworksEmbeddings
|
||||
|
||||
from langchain_standard_tests.unit_tests import EmbeddingsUnitTests
|
||||
from typing import Type
|
||||
|
||||
def test_initialization() -> None:
|
||||
"""Test embedding model initialization."""
|
||||
FireworksEmbeddings(model="nomic-ai/nomic-embed-text-v1.5")
|
||||
class TestOllamaEmbeddings(EmbeddingsUnitTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[FireworksEmbeddings]:
|
||||
return FireworksEmbeddings
|
||||
|
||||
@property
|
||||
def embedding_model_params(self) -> dict:
|
||||
return {"model": "nomic-ai/nomic-embed-text-v1.5"}
|
||||
|
||||
@@ -2,53 +2,10 @@
|
||||
|
||||
from langchain_mistralai import MistralAIEmbeddings
|
||||
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
from typing import Type
|
||||
|
||||
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
|
||||
|
||||
|
||||
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."""
|
||||
documents = ["foo bar " * 1000, "test document " * 1000] * 5
|
||||
embedding = MistralAIEmbeddings()
|
||||
output = embedding.embed_documents(documents)
|
||||
assert len(output) == 10
|
||||
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
|
||||
class TestOllamaEmbeddings(EmbeddingsIntegrationTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[MistralAIEmbeddings]:
|
||||
return MistralAIEmbeddings
|
||||
@@ -3,21 +3,17 @@
|
||||
from langchain_nomic.embeddings import NomicEmbeddings
|
||||
|
||||
|
||||
def test_langchain_nomic_embedding_documents() -> None:
|
||||
"""Test nomic embeddings."""
|
||||
documents = ["foo bar"]
|
||||
embedding = NomicEmbeddings(model="nomic-embed-text-v1")
|
||||
output = embedding.embed_documents(documents)
|
||||
assert len(output) == 1
|
||||
assert len(output[0]) > 0
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
from typing import Type
|
||||
|
||||
class TestNomicEmbeddings(EmbeddingsIntegrationTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[NomicEmbeddings]:
|
||||
return NomicEmbeddings
|
||||
|
||||
def test_langchain_nomic_embedding_query() -> None:
|
||||
"""Test nomic embeddings."""
|
||||
document = "foo bar"
|
||||
embedding = NomicEmbeddings(model="nomic-embed-text-v1")
|
||||
output = embedding.embed_query(document)
|
||||
assert len(output) > 0
|
||||
@property
|
||||
def embedding_model_params(self) -> dict:
|
||||
return {"model": "llama3:latest"}
|
||||
|
||||
|
||||
def test_langchain_nomic_embedding_dimensionality() -> None:
|
||||
|
||||
@@ -3,7 +3,14 @@
|
||||
|
||||
from langchain_nomic.embeddings import NomicEmbeddings
|
||||
|
||||
from langchain_standard_tests.unit_tests import EmbeddingsUnitTests
|
||||
from typing import Type
|
||||
|
||||
def test_initialization() -> None:
|
||||
"""Test embedding model initialization."""
|
||||
NomicEmbeddings(model="nomic-embed-text-v1")
|
||||
class TestNomicEmbeddings(EmbeddingsUnitTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[NomicEmbeddings]:
|
||||
return NomicEmbeddings
|
||||
|
||||
@property
|
||||
def embedding_model_params(self) -> dict:
|
||||
return {"model": "nomic-embed-text-v1"}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
"""Test Ollama embeddings."""
|
||||
|
||||
from typing import Type
|
||||
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
|
||||
from langchain_ollama.embeddings import OllamaEmbeddings
|
||||
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
from typing import Type
|
||||
|
||||
class TestOllamaEmbeddings(EmbeddingsIntegrationTests):
|
||||
@property
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
from langchain_ollama.embeddings import OllamaEmbeddings
|
||||
|
||||
|
||||
def test_initialization() -> None:
|
||||
"""Test embedding model initialization."""
|
||||
OllamaEmbeddings(model="llama3")
|
||||
from langchain_standard_tests.unit_tests import EmbeddingsUnitTests
|
||||
from typing import Type
|
||||
|
||||
class TestOllamaEmbeddings(EmbeddingsUnitTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[OllamaEmbeddings]:
|
||||
return OllamaEmbeddings
|
||||
|
||||
@property
|
||||
def embedding_model_params(self) -> dict:
|
||||
return {"model": "llama3:latest"}
|
||||
|
||||
@@ -6,22 +6,17 @@ import pytest
|
||||
|
||||
from langchain_openai.embeddings.base import OpenAIEmbeddings
|
||||
|
||||
from langchain_standard_tests.integration_tests import EmbeddingsIntegrationTests
|
||||
from typing import Type
|
||||
|
||||
def test_langchain_openai_embedding_documents() -> None:
|
||||
"""Test openai embeddings."""
|
||||
documents = ["foo bar"]
|
||||
embedding = OpenAIEmbeddings()
|
||||
output = embedding.embed_documents(documents)
|
||||
assert len(output) == 1
|
||||
assert len(output[0]) > 0
|
||||
class TestOpenAIEmbeddings(EmbeddingsIntegrationTests):
|
||||
@property
|
||||
def embeddings_class(self) -> Type[OpenAIEmbeddings]:
|
||||
return OpenAIEmbeddings
|
||||
|
||||
|
||||
def test_langchain_openai_embedding_query() -> None:
|
||||
"""Test openai embeddings."""
|
||||
document = "foo bar"
|
||||
embedding = OpenAIEmbeddings()
|
||||
output = embedding.embed_query(document)
|
||||
assert len(output) > 0
|
||||
@property
|
||||
def embedding_model_params(self) -> dict:
|
||||
return {"model": "text-embedding-3-small"}
|
||||
|
||||
|
||||
def test_langchain_openai_embeddings_dimensions() -> None:
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import List
|
||||
from langchain_core.embeddings import Embeddings
|
||||
|
||||
from langchain_standard_tests.unit_tests.embeddings import EmbeddingsTests
|
||||
|
||||
import pytest
|
||||
|
||||
class EmbeddingsIntegrationTests(EmbeddingsTests):
|
||||
def test_embed_query(self, model: Embeddings) -> None:
|
||||
@@ -27,6 +27,7 @@ class EmbeddingsIntegrationTests(EmbeddingsTests):
|
||||
assert len(embeddings[0]) > 0
|
||||
assert all(len(embedding) == len(embeddings[0]) for embedding in embeddings)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_aembed_query(self, model: Embeddings) -> None:
|
||||
embedding_1 = await model.aembed_query("foo")
|
||||
|
||||
@@ -37,7 +38,8 @@ class EmbeddingsIntegrationTests(EmbeddingsTests):
|
||||
|
||||
assert len(embedding_1) > 0
|
||||
assert len(embedding_1) == len(embedding_2)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_aembed_documents(self, model: Embeddings) -> None:
|
||||
documents = ["foo", "bar", "baz"]
|
||||
embeddings = await model.aembed_documents(documents)
|
||||
@@ -47,3 +49,39 @@ class EmbeddingsIntegrationTests(EmbeddingsTests):
|
||||
assert all(isinstance(embedding[0], float) for embedding in embeddings)
|
||||
assert len(embeddings[0]) > 0
|
||||
assert all(len(embedding) == len(embeddings[0]) for embedding in embeddings)
|
||||
|
||||
def test_embed_documents_long(self, model: Embeddings) -> None:
|
||||
documents = ["foo bar " * 1000, "test document " * 1000] * 5
|
||||
|
||||
embeddings = model.embed_documents(documents)
|
||||
assert len(embeddings) == 10
|
||||
|
||||
|
||||
def test_embed_query_character(self, model: Embeddings) -> None:
|
||||
document = "😳"
|
||||
embedding = model.embed_query(document)
|
||||
assert len(embedding) > 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_aembed_documents_long(self, model: Embeddings) -> None:
|
||||
documents = ["foo bar " * 1000, "test document " * 1000] * 5
|
||||
|
||||
embeddings = await model.aembed_documents(documents)
|
||||
assert len(embeddings) == 10
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_aembed_query_character(self, model: Embeddings) -> None:
|
||||
document = "😳"
|
||||
embedding = await model.aembed_query(document)
|
||||
assert len(embedding) > 0
|
||||
|
||||
|
||||
def test_embed_chinese_character(self, model: Embeddings) -> None:
|
||||
document = "意"
|
||||
embedding = model.embed_query(document)
|
||||
assert len(embedding) > 0
|
||||
@pytest.mark.asyncio
|
||||
async def test_aembed_query_character(self, model: Embeddings) -> None:
|
||||
document = "意"
|
||||
embedding = await model.aembed_query(document)
|
||||
assert len(embedding) > 0
|
||||
@@ -13,5 +13,6 @@ for module in modules:
|
||||
pytest.register_assert_rewrite(f"langchain_standard_tests.unit_tests.{module}")
|
||||
|
||||
from langchain_standard_tests.unit_tests.chat_models import ChatModelUnitTests
|
||||
from langchain_standard_tests.unit_tests.embeddings import EmbeddingsUnitTests
|
||||
|
||||
__all__ = ["ChatModelUnitTests", "EmbeddingsUnitTests"]
|
||||
|
||||
Reference in New Issue
Block a user