Oracle Cloud Infrastructure (OCI) 数据科学服务¶
Oracle Cloud Infrastructure (OCI) 数据科学 是一个完全托管、无服务器的平台,供数据科学团队在 Oracle Cloud Infrastructure 中构建、训练和管理机器学习模型。
它提供 AI 快速操作,可用于在 OCI 数据科学中部署嵌入模型。AI 快速操作面向希望快速利用 AI 能力的用户。它们旨在通过提供精简、无需编写代码且高效的基础模型工作环境,将基础模型的覆盖范围扩展到更广泛的用户群体。可以从数据科学 Notebook 访问 AI 快速操作。
关于如何在 OCI 数据科学中使用 AI 快速操作部署嵌入模型的详细文档可在此处和此处获取。
本 notebook 解释了如何将 OCI 的数据科学嵌入模型与 LlamaIndex 一起使用。
设置¶
如果您在 colab 上打开此 Notebook,您可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
%pip install llama-index-embeddings-oci-data-science
%pip install llama-index-embeddings-oci-data-science
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
您还需要安装 oracle-ads SDK。
In [ ]
已复制!
!pip install -U oracle-ads
!pip install -U oracle-ads
基本用法¶
In [ ]
已复制!
import ads
from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")
embedding = OCIDataScienceEmbedding(
endpoint="https://<MD_OCID>/predict",
)
e1 = embeddings.get_text_embedding("This is a test document")
print(e1)
e2 = embeddings.get_text_embedding_batch(
["This is a test document", "This is another test document"]
)
print(e2)
import ads from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding ads.set_auth(auth="security_token", profile="") embedding = OCIDataScienceEmbedding( endpoint="https:///predict", ) e1 = embeddings.get_text_embedding("This is a test document") print(e1) e2 = embeddings.get_text_embedding_batch( ["This is a test document", "This is another test document"] ) print(e2)
异步¶
In [ ]
已复制!
import ads
from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")
embedding = OCIDataScienceEmbedding(
endpoint="https://<MD_OCID>/predict",
)
e1 = await embeddings.aget_text_embedding("This is a test document")
print(e1)
e2 = await embeddings.aget_text_embedding_batch(
["This is a test document", "This is another test document"]
)
print(e2)
import ads from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding ads.set_auth(auth="security_token", profile="") embedding = OCIDataScienceEmbedding( endpoint="https:///predict", ) e1 = await embeddings.aget_text_embedding("This is a test document") print(e1) e2 = await embeddings.aget_text_embedding_batch( ["This is a test document", "This is another test document"] ) print(e2)