Skip to content

Commit 3b94a5a

Browse files
authored
Create langchain-oracledb Package for Oracle AI Vector Search (#3)
* Add langchain-oracledb package * Add support for oracle dsl * Add async support * Convert execute to executemany * Fix formatting issues * Fix error handling and version check * Add file level comments - better logging * Use LOB outputtypehandler * Use oracledb.DB_TYPE_JSON for JSON binding * Fix license year * Update OracleAutonomousDatabaseLoader * Use quoted identifiers
1 parent 1869fe0 commit 3b94a5a

File tree

29 files changed

+10338
-128
lines changed

29 files changed

+10338
-128
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ __pycache__
66
.env
77
.venv*
88
.idea
9+
.coverage

README.md

Lines changed: 21 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,47 @@
11
# 🦜️🔗 LangChain 🤝 Oracle
22

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**.
44

55
## Features
66

77
- **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.
88
- **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.
1016

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.
1319
1420
---
1521

1622
## Installation
1723

24+
For OCI services:
1825

1926
```bash
20-
pip install -U langchain-oci
27+
python -m pip install -U langchain-oci
2128
```
2229

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:
5731

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
12934
```
13035

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+
---
14437

145-
query = "Hello World!"
146-
embeddings.embed_query(query)
38+
## Quick Start
14739

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:
15141

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)
15245

15346
## Contributing
15447

libs/oracledb/LICENSE.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.

libs/oracledb/Makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.PHONY: all format lint test tests integration_tests help
2+
3+
# Default target executed when no arguments are given to make.
4+
all: help
5+
6+
# Define a variable for the test file path.
7+
TEST_FILE ?= tests/unit_tests/
8+
integration_test integration_tests: TEST_FILE = tests/integration_tests/
9+
10+
test tests integration_test integration_tests:
11+
poetry run pytest $(TEST_FILE)
12+
13+
test_watch:
14+
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)
15+
16+
######################
17+
# LINTING AND FORMATTING
18+
######################
19+
20+
# Define a variable for Python and notebook files.
21+
PYTHON_FILES=.
22+
MYPY_CACHE=.mypy_cache
23+
lint format: PYTHON_FILES=.
24+
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/oracledb --name-only --diff-filter=d main | grep -E '\.py$$|\.ipynb$$')
25+
lint_package: PYTHON_FILES=langchain_oracledb
26+
lint_tests: PYTHON_FILES=tests
27+
lint_tests: MYPY_CACHE=.mypy_cache_test
28+
29+
lint lint_diff lint_package lint_tests:
30+
poetry run ruff .
31+
poetry run ruff format $(PYTHON_FILES) --diff
32+
poetry run ruff --select I $(PYTHON_FILES)
33+
mkdir -p $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
34+
35+
format format_diff:
36+
poetry run ruff format $(PYTHON_FILES)
37+
poetry run ruff --select I --fix $(PYTHON_FILES)
38+
39+
spell_check:
40+
poetry run codespell --toml pyproject.toml
41+
42+
spell_fix:
43+
poetry run codespell --toml pyproject.toml -w
44+
45+
check_imports: $(shell find langchain_oracledb -name '*.py')
46+
poetry run python ./scripts/check_imports.py $^
47+
48+
######################
49+
# HELP
50+
######################
51+
52+
help:
53+
@echo '----'
54+
@echo 'check_imports - check imports'
55+
@echo 'format - run code formatters'
56+
@echo 'lint - run linters'
57+
@echo 'test - run unit tests'
58+
@echo 'tests - run unit tests'
59+
@echo 'test TEST_FILE=<test_file> - run all tests in file'

0 commit comments

Comments
 (0)