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 ownlangchain-google-el-carro package, so
we need to install it.
Basic Usage
Set Up Oracle Database Connection
Fill out the following variable with your Oracle database connections details.ElCarroEngine Connection Pool
ElCarroEngine configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices.
Initialize a table
Initialize a table of default schema viaelcarro_engine.init_document_table(<table_name>). Table Columns:
- page_content (type: text)
- langchain_metadata (type: JSON)
Save documents
Save langchain documents withElCarroDocumentSaver.add_documents(<documents>).
To initialize ElCarroDocumentSaver class you need to provide 2 things:
elcarro_engine- An instance of aElCarroEngineengine.table_name- The name of the table within the Oracle database to store langchain documents.
Load documents
Load langchain documents withElCarroLoader.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 aElCarroEngineengine.table_name- The name of the table within the Oracle database to store langchain documents.
Load documents via query
Other than loading documents from a table, we can also choose to load documents from a view generated from a SQL query. For example:Delete documents
Delete a list of langchain documents from an Oracle table withElCarroDocumentSaver.delete(<documents>).
For a table with a default schema (page_content, langchain_metadata), the
deletion criteria is:
A row should be deleted if there exists a document in the list, such that
document.page_contentequalsrow[page_content]document.metadataequalsrow[langchain_metadata]
Advanced Usage
Load documents with customized document page content & metadata
First we prepare an example table with non-default schema, and populate it with some arbitrary data.ElCarroLoader
from this example table, the page_content of loaded documents will be the
first column of the table, and metadata will be consisting of key-value pairs
of all the other columns.
content_columns and metadata_columns when initializing
the ElCarroLoader.
content_columns: The columns to write into thepage_contentof the document.metadata_columns: The columns to write into themetadataof the document.
content_columns will be joined
together into a space-separated string, as page_content of loaded documents,
and metadata of loaded documents will only contain key-value pairs of columns
specified in metadata_columns.
Save document with customized page content & metadata
In order to save langchain document into table with customized metadata fields we need first create such a table viaElCarroEngine.init_document_table(), and
specify the list of metadata_columns we want it to have. In this example, the
created table will have table columns:
- content (type: text): for storing fruit description.
- type (type VARCHAR2(200)): for storing fruit type.
- weight (type INT): for storing fruit weight.
- extra_json_metadata (type: JSON): for storing other metadata information of the fruit.
elcarro_engine.init_document_table() to create the table:
table_name: The name of the table within the Oracle database to store langchain documents.metadata_columns: A list ofsqlalchemy.Columnindicating the list of metadata columns we need.content_column: column name to storepage_contentof langchain document. Default:"page_content", "VARCHAR2(4000)"metadata_json_column: column name to store extra JSONmetadataof langchain document. Default:"langchain_metadata", "VARCHAR2(4000)".
ElCarroDocumentSaver.add_documents(<documents>). As you
can see in this example,
document.page_contentwill be saved intocontentcolumn.document.metadata.typewill be saved intotypecolumn.document.metadata.weightwill be saved intoweightcolumn.document.metadata.organicwill be saved intoextra_json_metadatacolumn in JSON format.
Delete documents with customized page content & metadata
We can also delete documents from table with customized metadata columns viaElCarroDocumentSaver.delete(<documents>). The deletion criteria is:
A row should be deleted if there exists a document in the list, such that
document.page_contentequalsrow[page_content]- For every metadata field
kindocument.metadatadocument.metadata[k]equalsrow[k]ordocument.metadata[k]equalsrow[langchain_metadata][k]
- There is no extra metadata field present in
rowbut not indocument.metadata.
More examples
Please look at demo_doc_loader_basic.py and demo_doc_loader_advanced.py for complete code examples.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.