> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OCI Generative AI Integration for LangChain

> Integrate with OCI Generative AI embeddings using LangChain Python.

This doc will help you get started with OCI Generative AI [embedding models](/oss/python/integrations/embeddings). Oracle Cloud Infrastructure (OCI) Generative AI provides state-of-the-art embedding models for text and images, enabling semantic search, RAG, clustering, and cross-modal applications.

For detailed documentation, see the [OCI Generative AI documentation](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm) and [API reference](https://docs.oracle.com/en-us/iaas/api/#/en/generative-ai/20231130/).

## Overview

### Integration details

| Class                                                                                 | Package                                                    | Serializable | Caches at params | Async |                                            Downloads                                           |                                           Version                                           |
| :------------------------------------------------------------------------------------ | :--------------------------------------------------------- | :----------: | :--------------: | :---: | :--------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------: |
| [`OCIGenAIEmbeddings`](https://github.com/oracle/langchain-oracle/tree/main/libs/oci) | [`langchain-oci`](https://pypi.org/project/langchain-oci/) |     beta     |         ✅        |   ✅   | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-oci?style=flat-square\&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-oci?style=flat-square\&label=%20) |

### Model features

| Text embeddings | Image embeddings | Multimodal | Batch operations | Async |
| :-------------: | :--------------: | :--------: | :--------------: | :---: |
|        ✅        |         ✅        |      ✅     |         ✅        |   ✅   |

## Setup

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -qU langchain-oci oci
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-oci oci
  ```
</CodeGroup>

Set up authentication:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
oci setup config
```

## Instantiation

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_oci import OCIGenAIEmbeddings

embeddings = OCIGenAIEmbeddings(
    model_id="cohere.embed-english-v3.0",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
)
```

## Usage

Build semantic search over technical documentation:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Index code documentation
docs = [
    "authenticate() validates JWT tokens and returns user object",
    "authorize() checks user permissions for resource access",
    "audit_log() records user actions for compliance tracking"
]
doc_vectors = embeddings.embed_documents(docs)

# Search with natural language query
query = "How do I verify user identity?"
query_vector = embeddings.embed_query(query)

# Find most relevant documentation
import numpy as np
similarities = [
    np.dot(query_vector, doc_vec) /
    (np.linalg.norm(query_vector) * np.linalg.norm(doc_vec))
    for doc_vec in doc_vectors
]
best_match = docs[np.argmax(similarities)]
# Returns: "authenticate() validates JWT tokens..."
```

**Use cases:** Code search, documentation Q\&A, log analysis, duplicate detection

## Image Embeddings

Search visual assets with text queries using multimodal embeddings:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import numpy as np
from langchain_oci import OCIGenAIEmbeddings

embeddings = OCIGenAIEmbeddings(
    model_id="cohere.embed-v4.0",
    service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
    compartment_id="ocid1.compartment.oc1..your-compartment-id",
)

# Index architecture diagrams
diagrams = ["microservices.png", "database_schema.png", "network.png"]
image_vectors = embeddings.embed_image_batch(diagrams)

# Search with text query
query_vector = embeddings.embed_query("database relationships")

# Find best match
similarities = [np.dot(query_vector, v) / (np.linalg.norm(query_vector) * np.linalg.norm(v))
                for v in image_vectors]
print(diagrams[np.argmax(similarities)])  # "database_schema.png"
```

**Use cases:** Technical diagram search, asset management, visual documentation retrieval

## Available Models

| Model                            | Dimensions | Type         |
| -------------------------------- | ---------- | ------------ |
| `cohere.embed-english-v3.0`      | 1024       | Text only    |
| `cohere.embed-multilingual-v3.0` | 1024       | Text only    |
| `cohere.embed-v4.0`              | 256-1536   | Text + Image |

See the [OCI model catalog](https://docs.oracle.com/en-us/iaas/Content/generative-ai/pretrained-models.htm) for all models.

## RAG Example

<Warning>
  The `langchain-community` package is no longer maintained. Examples that import from `langchain_community` may be outdated or broken. Use with caution.
</Warning>

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.vectorstores import FAISS

# Create vector store
vectorstore = FAISS.from_documents(documents, embeddings)

# Search
results = vectorstore.similarity_search("your query", k=3)
```

## Async

Async operations for production use:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
query_vector = await embeddings.aembed_query("What is AI?")
doc_vectors = await embeddings.aembed_documents(["Doc 1", "Doc 2"])
```

## API Reference

For detailed documentation of all `OCIGenAIEmbeddings` features and configurations, head to the [API reference](https://github.com/oracle/langchain-oracle/tree/main/libs/oci).

## Related

* [OCI Provider Overview](/oss/python/integrations/providers/oci)
* [`ChatOCIGenAI`](/oss/python/integrations/chat/oci_generative_ai)
* [Embeddings Guide](/oss/python/integrations/embeddings)
* [RAG Tutorial](/oss/python/langchain/rag)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/embeddings/oci_generative_ai.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
