设置¶
如果您在 colab 上打开此笔记本,您可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
%pip install llama-index-embeddings-oci-genai
%pip install llama-index-embeddings-oci-genai
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
您还需要安装 OCI sdk
In [ ]
已复制!
!pip install -U oci
!pip install -U oci
基本用法¶
In [ ]
已复制!
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)