2023-09-13 23:23:49 +00:00
|
|
|
"""Test Baidu Qianfan Embedding Endpoint."""
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.embeddings.baidu_qianfan_endpoint import (
|
|
|
|
QianfanEmbeddingsEndpoint,
|
|
|
|
)
|
2023-09-13 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_embedding_multiple_documents() -> None:
|
|
|
|
documents = ["foo", "bar"]
|
2024-05-13 18:55:07 +00:00
|
|
|
embedding = QianfanEmbeddingsEndpoint() # type: ignore[call-arg]
|
2023-09-13 23:23:49 +00:00
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 2
|
|
|
|
assert len(output[0]) == 384
|
|
|
|
assert len(output[1]) == 384
|
|
|
|
|
|
|
|
|
|
|
|
def test_embedding_query() -> None:
|
|
|
|
query = "foo"
|
2024-05-13 18:55:07 +00:00
|
|
|
embedding = QianfanEmbeddingsEndpoint() # type: ignore[call-arg]
|
2023-09-13 23:23:49 +00:00
|
|
|
output = embedding.embed_query(query)
|
|
|
|
assert len(output) == 384
|
|
|
|
|
|
|
|
|
|
|
|
def test_model() -> None:
|
|
|
|
documents = ["hi", "qianfan"]
|
2024-05-13 18:55:07 +00:00
|
|
|
embedding = QianfanEmbeddingsEndpoint(model="Embedding-V1") # type: ignore[call-arg]
|
2023-09-13 23:23:49 +00:00
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 2
|
2024-01-01 21:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_rate_limit() -> None:
|
2024-05-13 18:55:07 +00:00
|
|
|
llm = QianfanEmbeddingsEndpoint( # type: ignore[call-arg]
|
2024-01-01 21:12:31 +00:00
|
|
|
model="Embedding-V1", init_kwargs={"query_per_second": 2}
|
|
|
|
)
|
|
|
|
assert llm.client._client._rate_limiter._sync_limiter._query_per_second == 2
|
|
|
|
documents = ["foo", "bar"]
|
|
|
|
output = llm.embed_documents(documents)
|
|
|
|
assert len(output) == 2
|
|
|
|
assert len(output[0]) == 384
|
|
|
|
assert len(output[1]) == 384
|