Skip to content
LlamaIndex 文档版本 跟随上游 源快照 8bdcbecb 更新于 2026-10-18

Oracle Cloud Infrastructure (OCI) Generative AI 是一项完全托管的服务,提供一组最先进、可定制的大型语言模型(LLM),覆盖广泛的用例,并可通过单一 API 使用。使用 OCI Generative AI 服务,你可以访问即用型预训练模型,或基于自己的数据在专用 AI 集群上创建并托管自己的微调自定义模型。该服务与 API 的详细文档见**此处和此处**。

本 Notebook 介绍如何在 LlamaIndex 中使用 OCI 的生成式 AI 嵌入模型。

设置

如果你在 Colab 中打开这个 Notebook,可能需要先安装 LlamaIndex 🦙。

%pip install llama-index-embeddings-oci-genai
!pip install llama-index

你还需要安装 OCI SDK

!pip install -U oci

基本用法

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)

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。