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.
langchain-google-el-carro
package, so
we need to install it.
ElCarroEngine
configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices.
elcarro_engine.init_document_table(<table_name>)
. Table Columns:
ElCarroDocumentSaver.add_documents(<documents>)
.
To initialize ElCarroDocumentSaver
class you need to provide 2 things:
elcarro_engine
- An instance of a ElCarroEngine
engine.table_name
- The name of the table within the Oracle database to store
langchain documents.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 a ElCarroEngine
engine.table_name
- The name of the table within the Oracle database to store
langchain documents.ElCarroDocumentSaver.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_content
equals row[page_content]
document.metadata
equals row[langchain_metadata]
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 the page_content
of the
document.metadata_columns
: The columns to write into the metadata
of 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
.
ElCarroEngine.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:
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 of sqlalchemy.Column
indicating the list of
metadata columns we need.content_column
: column name to store page_content
of langchain
document. Default: "page_content", "VARCHAR2(4000)"
metadata_json_column
: column name to store extra
JSON metadata
of langchain document.
Default: "langchain_metadata", "VARCHAR2(4000)"
.ElCarroDocumentSaver.add_documents(<documents>)
. As you
can see in this example,
document.page_content
will be saved into content
column.document.metadata.type
will be saved into type
column.document.metadata.weight
will be saved into weight
column.document.metadata.organic
will be saved into extra_json_metadata
column in
JSON format.ElCarroDocumentSaver.delete(<documents>)
. The deletion criteria is:
A row
should be deleted if there exists a document
in the list, such that
document.page_content
equals row[page_content]
k
in document.metadata
document.metadata[k]
equals row[k]
or document.metadata[k]
equals row[langchain_metadata][k]
row
but not
in document.metadata
.