|
1 | 1 | # 🦜️🔗 LangChain 🤝 Oracle |
2 | 2 |
|
3 | | -Welcome to the official repository for LangChain integration with [Oracle Cloud Infrastructure (OCI)](https://cloud.oracle.com/). This library provides native LangChain components for interacting with Oracle's AI services—combining support for **OCI Generative AI** and **OCI Data Science**. |
| 3 | +Welcome to the official repository for LangChain integration with [Oracle Cloud Infrastructure (OCI)](https://cloud.oracle.com/) and [Oracle AI Vector Search](https://www.oracle.com/database/ai-vector-search/). This project provides native LangChain components for interacting with Oracle's AI services—providing support for **OCI Generative AI**, **OCI Data Science** and **Oracle AI Vector Search**. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | 7 | - **LLMs**: Includes LLM classes for OCI services like [Generative AI](https://cloud.oracle.com/ai-services/generative-ai) and [ModelDeployment Endpoints](https://cloud.oracle.com/ai-services/model-deployment), allowing you to leverage their language models within LangChain. |
8 | 8 | - **Agents**: Includes Runnables to support [Oracle Generative AI Agents](https://www.oracle.com/artificial-intelligence/generative-ai/agents/), allowing you to leverage Generative AI Agents within LangChain and LangGraph. |
9 | | -- **More to come**: This repository will continue to expand and offer additional components for various OCI services as development progresses. |
| 9 | +- **Vector Search**: Offers native integration with [Oracle AI Vector Search](https://www.oracle.com/database/ai-vector-search/) through a LangChain-compatible components. This enables pipelines that can: |
| 10 | + - Load the documents from various sources using `OracleDocLoader` |
| 11 | + - Summarize content within/outside the database using `OracleSummary` |
| 12 | + - Generate embeddings within/outside the database using `OracleEmbeddings` |
| 13 | + - Chunk according to different requirements using Advanced Oracle Capabilities from `OracleTextSplitter` |
| 14 | + - Store, index, and query vectors using `OracleVS` |
| 15 | +- **More to come**: This repository will continue to expand and offer additional components for various OCI and Oracle AI services as development progresses. |
10 | 16 |
|
11 | | -> This project merges and replaces earlier OCI integrations from the `langchain-community` repository and unifies contributions from Oracle's GenAI and Data Science teams. |
12 | | -> All integrations in this package assume that you have the credentials setup to connect with oci services. |
| 17 | +> This project merges and replaces earlier OCI and Oracle AI Vector Search integrations from the `langchain-community` repository and unifies contributions from Oracle teams. |
| 18 | +> All integrations in this package assume that you have the credentials setup to connect with oci and database services. |
13 | 19 |
|
14 | 20 | --- |
15 | 21 |
|
16 | 22 | ## Installation |
17 | 23 |
|
| 24 | +For OCI services: |
18 | 25 |
|
19 | 26 | ```bash |
20 | | -pip install -U langchain-oci |
| 27 | +python -m pip install -U langchain-oci |
21 | 28 | ``` |
22 | 29 |
|
23 | | ---- |
24 | | - |
25 | | -## Quick Start |
26 | | - |
27 | | -This repository includes two main integration categories: |
28 | | - |
29 | | -- [OCI Generative AI](#oci-generative-ai-examples) |
30 | | -- [OCI Data Science (Model Deployment)](#oci-data-science-model-deployment-examples) |
31 | | - |
32 | | - |
33 | | ---- |
34 | | - |
35 | | -## OCI Generative AI Examples |
36 | | - |
37 | | -### 1. Use a Chat Model |
38 | | - |
39 | | -`ChatOCIGenAI` class exposes chat models from OCI Generative AI. |
40 | | - |
41 | | -```python |
42 | | -from langchain_oci import ChatOCIGenAI |
43 | | - |
44 | | -llm = ChatOCIGenAI() |
45 | | -llm.invoke("Sing a ballad of LangChain.") |
46 | | -``` |
47 | | - |
48 | | -### 2. Use a Completion Model |
49 | | -`OCIGenAI` class exposes LLMs from OCI Generative AI. |
50 | | - |
51 | | -```python |
52 | | -from langchain_oci import OCIGenAI |
53 | | - |
54 | | -llm = OCIGenAI() |
55 | | -llm.invoke("The meaning of life is") |
56 | | -``` |
| 30 | +For Oracle AI Vector Search services: |
57 | 31 |
|
58 | | -### 3. Use an Embedding Model |
59 | | -`OCIGenAIEmbeddings` class exposes embeddings from OCI Generative AI. |
60 | | - |
61 | | -```python |
62 | | -from langchain_oci import OCIGenAIEmbeddings |
63 | | - |
64 | | -embeddings = OCIGenAIEmbeddings() |
65 | | -embeddings.embed_query("What is the meaning of life?") |
66 | | -``` |
67 | | - |
68 | | - |
69 | | -## OCI Data Science Model Deployment Examples |
70 | | - |
71 | | -### 1. Use a Chat Model |
72 | | - |
73 | | -You may instantiate the OCI Data Science model with the generic `ChatOCIModelDeployment` or framework specific class like `ChatOCIModelDeploymentVLLM`. |
74 | | - |
75 | | -```python |
76 | | -from langchain_oci.chat_models import ChatOCIModelDeployment, ChatOCIModelDeploymentVLLM |
77 | | - |
78 | | -# Create an instance of OCI Model Deployment Endpoint |
79 | | -# Replace the endpoint uri with your own |
80 | | -endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict" |
81 | | - |
82 | | -messages = [ |
83 | | - ( |
84 | | - "system", |
85 | | - "You are a helpful assistant that translates English to French. Translate the user sentence.", |
86 | | - ), |
87 | | - ("human", "I love programming."), |
88 | | -] |
89 | | - |
90 | | -chat = ChatOCIModelDeployment( |
91 | | - endpoint=endpoint, |
92 | | - streaming=True, |
93 | | - max_retries=1, |
94 | | - model_kwargs={ |
95 | | - "temperature": 0.2, |
96 | | - "max_tokens": 512, |
97 | | - }, # other model params... |
98 | | - default_headers={ |
99 | | - "route": "/v1/chat/completions", |
100 | | - # other request headers ... |
101 | | - }, |
102 | | -) |
103 | | -chat.invoke(messages) |
104 | | - |
105 | | -chat_vllm = ChatOCIModelDeploymentVLLM(endpoint=endpoint) |
106 | | -chat_vllm.invoke(messages) |
107 | | -``` |
108 | | - |
109 | | -### 2. Use a Completion Model |
110 | | -You may instantiate the OCI Data Science model with `OCIModelDeploymentLLM` or `OCIModelDeploymentVLLM`. |
111 | | - |
112 | | -```python |
113 | | -from langchain_oci.llms import OCIModelDeploymentLLM, OCIModelDeploymentVLLM |
114 | | - |
115 | | -# Create an instance of OCI Model Deployment Endpoint |
116 | | -# Replace the endpoint uri and model name with your own |
117 | | -endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict" |
118 | | - |
119 | | -llm = OCIModelDeploymentLLM( |
120 | | - endpoint=endpoint, |
121 | | - model="odsc-llm", |
122 | | -) |
123 | | -llm.invoke("Who is the first president of United States?") |
124 | | - |
125 | | -vllm = OCIModelDeploymentVLLM( |
126 | | - endpoint=endpoint, |
127 | | -) |
128 | | -vllm.invoke("Who is the first president of United States?") |
| 32 | +```bash |
| 33 | +python -m pip install -U langchain-oracledb |
129 | 34 | ``` |
130 | 35 |
|
131 | | -### 3. Use an Embedding Model |
132 | | -You may instantiate the OCI Data Science model with the `OCIModelDeploymentEndpointEmbeddings`. |
133 | | - |
134 | | -```python |
135 | | -from langchain_oci.embeddings import OCIModelDeploymentEndpointEmbeddings |
136 | | - |
137 | | -# Create an instance of OCI Model Deployment Endpoint |
138 | | -# Replace the endpoint uri with your own |
139 | | -endpoint = "https://modeldeployment.<region>.oci.customer-oci.com/<ocid>/predict" |
140 | | - |
141 | | -embeddings = OCIModelDeploymentEndpointEmbeddings( |
142 | | - endpoint=endpoint, |
143 | | -) |
| 36 | +--- |
144 | 37 |
|
145 | | -query = "Hello World!" |
146 | | -embeddings.embed_query(query) |
| 38 | +## Quick Start |
147 | 39 |
|
148 | | -documents = ["This is a sample document", "and here is another one"] |
149 | | -embeddings.embed_documents(documents) |
150 | | -``` |
| 40 | +This repository includes three main integration categories. For detailed information, please refer to the respective libraries: |
151 | 41 |
|
| 42 | +- [OCI Generative AI](https://github.com/oracle/langchain-oracle/tree/main/libs/oci) |
| 43 | +- [OCI Data Science (Model Deployment)](https://github.com/oracle/langchain-oracle/tree/main/libs/oci) |
| 44 | +- [Oracle AI Vector Search](https://github.com/oracle/langchain-oracle/tree/main/libs/oracledb) |
152 | 45 |
|
153 | 46 | ## Contributing |
154 | 47 |
|
|
0 commit comments