Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OCI Data Science Model Deployment Embedding Integration #17243

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions docs/docs/examples/embeddings/oci_data_science.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "6d1ca9ac",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/embeddings/oci_data_science.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "9e3a8796-edc8-43f2-94ad-fe4fb20d70ed",
"metadata": {},
"source": [
"# Oracle Cloud Infrastructure (OCI) Data Science Service\n",
"\n",
"Oracle Cloud Infrastructure (OCI) [Data Science](https://www.oracle.com/artificial-intelligence/data-science) is a fully managed, serverless platform for data science teams to build, train, and manage machine learning models in Oracle Cloud Infrastructure.\n",
"\n",
"It offers [AI Quick Actions](https://docs.oracle.com/en-us/iaas/data-science/using/ai-quick-actions.htm), which can be used to deploy embedding models in OCI Data Science. AI Quick Actions target users who want to quickly leverage the capabilities of AI. They aim to expand the reach of foundation models to a broader set of users by providing a streamlined, code-free, and efficient environment for working with foundation models. AI Quick Actions can be accessed from the Data Science Notebook.\n",
"\n",
"Detailed documentation on how to deploy embedding models in OCI Data Science using AI Quick Actions is available [here](https://github.com/oracle-samples/oci-data-science-ai-samples/blob/main/ai-quick-actions/model-deployment-tips.md) and [here](https://docs.oracle.com/en-us/iaas/data-science/using/ai-quick-actions-model-deploy.htm).\n",
"\n",
"This notebook explains how to use OCI's Data Science embedding models with LlamaIndex."
]
},
{
"cell_type": "markdown",
"id": "3802e8c4",
"metadata": {},
"source": [
"## Setup\n",
"\n",
"If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb0dd8c9",
"metadata": {},
"outputs": [],
"source": [
"%pip install llama-index-embeddings-oci-data-science"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "544d49f9",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
]
},
{
"cell_type": "markdown",
"id": "c2921307",
"metadata": {},
"source": [
"You will also need to install the [oracle-ads](https://accelerated-data-science.readthedocs.io/en/latest/index.html) SDK."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "378d5179",
"metadata": {},
"outputs": [],
"source": [
"!pip install -U oracle-ads"
]
},
{
"cell_type": "markdown",
"id": "423605c6",
"metadata": {},
"source": [
"## Authentication\n",
"\n",
"The authentication methods supported for LlamaIndex are equivalent to those used with other OCI services and follow the standard SDK authentication methods, specifically API Key, session token, instance principal, and resource principal. More details can be found [here](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html). Make sure to have the required [policies](https://docs.oracle.com/en-us/iaas/data-science/using/model-dep-policies-auth.htm) to access the OCI Data Science Model Deployment endpoint. The [oracle-ads](https://accelerated-data-science.readthedocs.io/en/latest/index.html) helps to simplify the authentication within OCI Data Science."
]
},
{
"cell_type": "markdown",
"id": "03d4024a",
"metadata": {},
"source": [
"## Basic Usage\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60be18ae-c957-4ac2-a58a-0652e18ee6d6",
"metadata": {},
"outputs": [],
"source": [
"import ads\n",
"from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding\n",
"\n",
"ads.set_auth(auth=\"security_token\", profile=\"<replace-with-your-profile>\")\n",
"\n",
"embedding = OCIDataScienceEmbedding(\n",
" endpoint=\"https://<MD_OCID>/predict\",\n",
")\n",
"\n",
"\n",
"e1 = embeddings.get_text_embedding(\"This is a test document\")\n",
"print(e1)\n",
"\n",
"e2 = embeddings.get_text_embedding_batch(\n",
" [\"This is a test document\", \"This is another test document\"]\n",
")\n",
"print(e2)"
]
},
{
"cell_type": "markdown",
"id": "170e1ad7",
"metadata": {},
"source": [
"## Async"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cbc3cba9",
"metadata": {},
"outputs": [],
"source": [
"import ads\n",
"from llama_index.embeddings.oci_data_science import OCIDataScienceEmbedding\n",
"\n",
"ads.set_auth(auth=\"security_token\", profile=\"<replace-with-your-profile>\")\n",
"\n",
"embedding = OCIDataScienceEmbedding(\n",
" endpoint=\"https://<MD_OCID>/predict\",\n",
")\n",
"\n",
"e1 = await embeddings.aget_text_embedding(\"This is a test document\")\n",
"print(e1)\n",
"\n",
"e2 = await embeddings.aget_text_embedding_batch(\n",
" [\"This is a test document\", \"This is another test document\"]\n",
")\n",
"print(e2)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
llama_index/_static
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
bin/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
etc/
include/
lib/
lib64/
parts/
sdist/
share/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints
notebooks/

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pyvenv.cfg

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Jetbrains
.idea
modules/
*.swp

# VsCode
.vscode

# pipenv
Pipfile
Pipfile.lock

# pyright
pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
poetry_requirements(
name="poetry",
module_mapping={"oracle-ads": ["ads"]},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)

help: ## Show all Makefile targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'

format: ## Run code autoformatters (black).
pre-commit install
git ls-files | xargs pre-commit run black --files

lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files

test: ## Run tests via pytest.
pytest tests

watch-docs: ## Build and watch documentation.
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/
Loading
Loading