2023-09-20 22:55:30 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
from unstructured.documents.elements import Text
|
2024-02-10 07:27:06 -08:00
|
|
|
from unstructured.embed.octoai import OctoAiEmbeddingConfig, OctoAIEmbeddingEncoder
|
2023-09-20 22:55:30 +03:00
|
|
|
|
2024-02-10 07:27:06 -08:00
|
|
|
embedding_encoder = OctoAIEmbeddingEncoder(
|
|
|
|
config=OctoAiEmbeddingConfig(api_key=os.environ["OCTOAI_API_KEY"])
|
|
|
|
)
|
2023-09-20 22:55:30 +03:00
|
|
|
elements = embedding_encoder.embed_documents(
|
|
|
|
elements=[Text("This is sentence 1"), Text("This is sentence 2")],
|
|
|
|
)
|
|
|
|
|
|
|
|
query = "This is the query"
|
|
|
|
query_embedding = embedding_encoder.embed_query(query=query)
|
|
|
|
|
|
|
|
[print(e.embeddings, e) for e in elements]
|
|
|
|
print(query_embedding, query)
|
|
|
|
print(embedding_encoder.is_unit_vector(), embedding_encoder.num_of_dimensions())
|