2022-11-02 04:29:39 +00:00
|
|
|
"""Test openai embeddings."""
|
|
|
|
from langchain.embeddings.openai import OpenAIEmbeddings
|
|
|
|
|
|
|
|
|
|
|
|
def test_openai_embedding_documents() -> None:
|
|
|
|
"""Test openai embeddings."""
|
|
|
|
documents = ["foo bar"]
|
|
|
|
embedding = OpenAIEmbeddings()
|
|
|
|
output = embedding.embed_documents(documents)
|
|
|
|
assert len(output) == 1
|
2023-02-10 14:59:50 +00:00
|
|
|
assert len(output[0]) == 1536
|
|
|
|
|
|
|
|
|
|
|
|
def test_openai_embedding_documents_multiple() -> None:
|
|
|
|
"""Test openai embeddings."""
|
|
|
|
documents = ["foo bar", "bar foo", "foo"]
|
2023-03-09 05:24:18 +00:00
|
|
|
embedding = OpenAIEmbeddings(chunk_size=2)
|
2023-02-16 07:02:32 +00:00
|
|
|
embedding.embedding_ctx_length = 8191
|
2023-03-09 05:24:18 +00:00
|
|
|
output = embedding.embed_documents(documents)
|
2023-02-10 14:59:50 +00:00
|
|
|
assert len(output) == 3
|
|
|
|
assert len(output[0]) == 1536
|
|
|
|
assert len(output[1]) == 1536
|
|
|
|
assert len(output[2]) == 1536
|
2022-11-02 04:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_openai_embedding_query() -> None:
|
|
|
|
"""Test openai embeddings."""
|
|
|
|
document = "foo bar"
|
|
|
|
embedding = OpenAIEmbeddings()
|
|
|
|
output = embedding.embed_query(document)
|
2023-02-10 14:59:50 +00:00
|
|
|
assert len(output) == 1536
|