设置¶
如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。
In [ ]:
Copied!
%pip install llama-index-embeddings-oci-genai
%pip install llama-index-embeddings-oci-genai
In [ ]:
Copied!
!pip install llama-index
!pip install llama-index
您还需要安装OCI sdk。
In [ ]:
Copied!
!pip install -U oci
!pip install -U oci
基本用法¶
In [ ]:
Copied!
from llama_index.embeddings.oci_genai import OCIGenAIEmbeddings
embedding = OCIGenAIEmbeddings(
model_name="cohere.embed-english-light-v3.0",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
)
e1 = embedding.get_text_embedding("This is a test document")
print(e1[-5:])
e2 = embedding.get_query_embedding("This is a test document")
print(e2[-5:])
docs = ["This is a test document", "This is another test document"]
e3 = embedding.get_text_embedding_batch(docs)
print(e3)
from llama_index.embeddings.oci_genai import OCIGenAIEmbeddings
embedding = OCIGenAIEmbeddings(
model_name="cohere.embed-english-light-v3.0",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
)
e1 = embedding.get_text_embedding("This is a test document")
print(e1[-5:])
e2 = embedding.get_query_embedding("This is a test document")
print(e2[-5:])
docs = ["This is a test document", "This is another test document"]
e3 = embedding.get_text_embedding_batch(docs)
print(e3)