Last active
March 20, 2024 19:20
-
-
Save ptorru/39b84e2770a6e725d37dfd82cb6f4f8d to your computer and use it in GitHub Desktop.
Using OctoAI's Embedding Encoder in Unstructured.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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