OCI 数据科学
OCIDataScienceEmbedding #
基础: BaseEmbedding
适用于 OCI Data Science 模型的 Embedding 类。
此类提供使用部署在 Oracle Cloud Infrastructure (OCI) Data Science 上的模型生成嵌入的方法。它支持同步和异步请求,并处理身份验证、批处理和其他配置。
设置
安装所需的包
pip install -U oracle-ads llama-index-embeddings-oci-data-science
使用 ads.set_auth()
配置身份验证。例如,使用 OCI 资源主体进行身份验证
import ads
ads.set_auth("resource_principal")
有关身份验证的更多详细信息,请参阅:https://accelerated-data-science.readthedocs.io/en/stable/user_guide/cli/authentication.html
确保您具有访问 OCI Data Science 模型部署端点所需的策略:https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-policies-auth.htm
要了解如何在 OCI Data Science 中部署 LLM 模型,请参阅:https://docs.oracle.com/en-us/iaas/data-science/using/ai-quick-actions-model-deploy.htm
示例
基本用法
import ads
from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding
ads.set_auth(auth="security_token", profile="OC1")
embeddings = 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
import asyncio
from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding
ads.set_auth(auth="security_token", profile="OC1")
embeddings = OCIDataScienceEmbedding(
endpoint="https://<MD_OCID>/predict",
)
async def async_embedding():
e1 = await embeddings.aget_query_embedding("This is a test document")
print(e1)
asyncio.run(async_embedding())
属性
名称 | 类型 | 描述 |
---|---|---|
endpoint |
str
|
部署模型的端点的 URI。 |
auth |
Dict[str, Any]
|
用于 OCI API 请求的身份验证字典。 |
model_name |
str
|
OCI Data Science embedding 模型的名称。 |
embed_batch_size |
int
|
embedding 调用的批处理大小。 |
additional_kwargs |
Dict[str, Any]
|
OCI Data Science AI 请求的其他关键字参数。 |
default_headers |
Dict[str, str]
|
API 请求的默认头部信息。 |
Source code in llama-index-integrations/embeddings/llama-index-embeddings-oci-data-science/llama_index/embeddings/oci_data_science/base.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
client property
#
client: Client
返回同步客户端实例。
返回值
名称 | 类型 | 描述 |
---|---|---|
Client |
Client
|
用于与 OCI Data Science 模型部署端点交互的同步客户端。 |
async_client property
#
async_client: AsyncClient
返回异步客户端实例。
返回值
名称 | 类型 | 描述 |
---|---|---|
AsyncClient |
AsyncClient
|
用于与 OCI Data Science 模型部署端点交互的异步客户端。 |
validate_env #
validate_env(values: Dict[str, Any]) -> Dict[str, Any]
在初始化之前验证环境和依赖项。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
values
|
Dict[str, Any]
|
传递给模型的值。 |
required |
返回值
类型 | 描述 |
---|---|
Dict[str, Any]
|
Dict[str, Any]: 已验证的值。 |
抛出
类型 | 描述 |
---|---|
ImportError
|
如果缺少必需的依赖项。 |
Source code in llama-index-integrations/embeddings/llama-index-embeddings-oci-data-science/llama_index/embeddings/oci_data_science/base.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
class_name classmethod
#
class_name() -> str
获取类名。
返回值
名称 | 类型 | 描述 |
---|---|---|
str |
str
|
类的名称。 |
Source code in llama-index-integrations/embeddings/llama-index-embeddings-oci-data-science/llama_index/embeddings/oci_data_science/base.py
243 244 245 246 247 248 249 250 251 252 |
|