OctoAI Embeddings¶
This guide shows you how to use OctoAI's Embeddings through LlamaIndex.
First, let's install LlamaIndex and OctoAI's dependencies
In [ ]:
Copied!
%pip install llama-index-embeddings-octoai
%pip install llama-index-embeddings-octoai
In [ ]:
Copied!
!pip install llama-index
!pip install llama-index
In [ ]:
Copied!
OCTOAI_API_KEY = ""
OCTOAI_API_KEY = ""
We can then query embeddings on OctoAI
In [ ]:
Copied!
from llama_index.embeddings.octoai import OctoAIEmbedding
embed_model = OctoAIEmbedding(api_key=OCTOAI_API_KEY)
from llama_index.embeddings.octoai import OctoAIEmbedding
embed_model = OctoAIEmbedding(api_key=OCTOAI_API_KEY)
In [ ]:
Copied!
# Basic embedding example
embeddings = embed_model.get_text_embedding("How do I sail to the moon?")
print(len(embeddings), embeddings[:10])
assert len(embeddings) == 1024
# Basic embedding example
embeddings = embed_model.get_text_embedding("How do I sail to the moon?")
print(len(embeddings), embeddings[:10])
assert len(embeddings) == 1024
Using Batched Embeddings¶
In [ ]:
Copied!
texts = [
"How do I sail to the moon?",
"What is the best way to cook a steak?",
"How do I apply for a job?",
]
embeddings = embed_model.get_text_embedding_batch(texts)
print(len(embeddings))
assert len(embeddings) == 3
assert len(embeddings[0]) == 1024
texts = [
"How do I sail to the moon?",
"What is the best way to cook a steak?",
"How do I apply for a job?",
]
embeddings = embed_model.get_text_embedding_batch(texts)
print(len(embeddings))
assert len(embeddings) == 3
assert len(embeddings[0]) == 1024