Google El Carro for Oracle Workloads
Google El Carro Oracle Operator offers a way to run Oracle databases in Kubernetes as a portable, open source, community driven, no vendor lock-in container orchestration system. El Carro provides a powerful declarative API for comprehensive and consistent configuration and deployment as well as for real-time operations and monitoring. Extend your Oracle database's capabilities to build AI-powered experiences by leveraging the El Carro Langchain integration.
This guide goes over how to use El Carro Langchain integration to
save, load and delete langchain documents
with ElCarroLoader
and ElCarroDocumentSaver
. This integration works for any Oracle database, regardless of where it is running.
Learn more about the package on GitHub.
Before You Begin
Please complete the Getting Started section of the README to set up your El Carro Oracle database.
🦜🔗 Library Installation
The integration lives in its own langchain-google-el-carro
package, so
we need to install it.
%pip install --upgrade --quiet langchain-google-el-carro
Basic Usage
Set Up Oracle Database Connection
Fill out the following variable with your Oracle database connections details.
# @title Set Your Values Here { display-mode: "form" }
HOST = "127.0.0.1" # @param {type: "string"}
PORT = 3307 # @param {type: "integer"}
DATABASE = "my-database" # @param {type: "string"}
TABLE_NAME = "message_store" # @param {type: "string"}
USER = "my-user" # @param {type: "string"}
PASSWORD = input("Please provide a password to be used for the database user: ")
If you are using El Carro, you can find the hostname and port values in the status of the El Carro Kubernetes instance. Use the user password you created for your PDB.
Example Ouput:
kubectl get -w instances.oracle.db.anthosapis.com -n db
NAME DB ENGINE VERSION EDITION ENDPOINT URL DB NAMES BACKUP ID READYSTATUS READYREASON DBREADYSTATUS DBREADYREASON
mydb Oracle 18c Express mydb-svc.db 34.71.69.25:6021 ['pdbname'] TRUE CreateComplete True CreateComplete
ElCarroEngine Connection Pool
ElCarroEngine
configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices.
from langchain_google_el_carro import ElCarroEngine
elcarro_engine = ElCarroEngine.from_instance(
db_host=HOST,
db_port=PORT,
db_name=DATABASE,
db_user=USER,
db_password=PASSWORD,
)
Initialize a table
Initialize a table of default schema
via elcarro_engine.init_document_table(<table_name>)
. Table Columns:
- page_content (type: text)
- langchain_metadata (type: JSON)
elcarro_engine.drop_document_table(TABLE_NAME)
elcarro_engine.init_document_table(
table_name=TABLE_NAME,
)
Save documents
Save langchain documents with ElCarroDocumentSaver.add_documents(<documents>)
.
To initialize ElCarroDocumentSaver
class you need to provide 2 things:
elcarro_engine
- An instance of aElCarroEngine
engine.table_name
- The name of the table within the Oracle database to store langchain documents.
from langchain_core.documents import Document
from langchain_google_el_carro import ElCarroDocumentSaver
doc = Document(
page_content="Banana",
metadata={"type": "fruit", "weight": 100, "organic": 1},
)
saver = ElCarroDocumentSaver(
elcarro_engine=elcarro_engine,
table_name=TABLE_NAME,
)
saver.add_documents([doc])
Load documents
Load langchain documents with ElCarroLoader.load()
or ElCarroLoader.lazy_load()
.
lazy_load
returns a generator that only queries database during the iteration.
To initialize ElCarroLoader
class you need to provide:
elcarro_engine
- An instance of aElCarroEngine
engine.table_name
- The name of the table within the Oracle database to store langchain documents.
from langchain_google_el_carro import ElCarroLoader
loader = ElCarroLoader(elcarro_engine=elcarro_engine, table_name=TABLE_NAME)
docs = loader.lazy_load()
for doc in docs:
print("Loaded documents:", doc)