Skip to content

Instantly share code, notes, and snippets.

@ptorru
Last active March 20, 2024 19:20
Show Gist options
  • Select an option

  • Save ptorru/39b84e2770a6e725d37dfd82cb6f4f8d to your computer and use it in GitHub Desktop.

Select an option

Save ptorru/39b84e2770a6e725d37dfd82cb6f4f8d to your computer and use it in GitHub Desktop.
Using OctoAI's Embedding Encoder in Unstructured.io
import os
from unstructured.documents.elements import Text
from unstructured.embed.octoai import OctoAiEmbeddingConfig, OctoAIEmbeddingEncoder
embedding_encoder = OctoAIEmbeddingEncoder(
config=OctoAiEmbeddingConfig(api_key=os.environ["OCTOAI_API_KEY"])
)
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment