Firestore in Datastore Mode is a NoSQL document database built for automatic scaling, high performance and ease of application development. Extend your database application to build AI-powered experiences leveraging Datastoreβs LangChain integrations.This notebook goes over how to use Firestore in Datastore Mode to save, load and delete langchain documents with
DatastoreLoader
and DatastoreSaver
.
Learn more about the package on GitHub.
Before You Begin
To run this notebook, you will need to do the following:- Create a Google Cloud Project
- Enable the Datastore API
- Create a Firestore in Datastore Mode database
π¦π Library Installation
The integration lives in its ownlangchain-google-datastore
package, so we need to install it.
β Set Your Google Cloud Project
Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook. If you donβt know your project ID, try the following:- Run
gcloud config list
. - Run
gcloud projects list
. - See the support page: Locate the project ID.
π Authentication
Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.- If you are using Colab to run this notebook, use the cell below and continue.
- If you are using Vertex AI Workbench, check out the setup instructions here.
Basic Usage
Save documents
Save langchain documents withDatastoreSaver.upsert_documents(<documents>)
. By default it will try to extract the entity key from the key
in the Document metadata.
Save documents without key
If akind
is specified the documents will be stored with an auto generated id.
Load documents via Kind
Load langchain documents withDatastoreLoader.load()
or DatastoreLoader.lazy_load()
. lazy_load
returns a generator that only queries database during the iteration. To initialize DatastoreLoader
class you need to provide:
source
- The source to load the documents. It can be an instance of Query or the name of the Datastore kind to read from.
Load documents via query
Other than loading documents from kind, we can also choose to load documents from query. For example:Delete documents
Delete a list of langchain documents from Datastore withDatastoreSaver.delete_documents(<documents>)
.
Advanced Usage
Load documents with customized document page content & metadata
The arguments ofpage_content_properties
and metadata_properties
will specify the Entity properties to be written into LangChain Document page_content
and metadata
.
Customize Page Content Format
When thepage_content
contains only one field the information will be the field value only. Otherwise the page_content
will be in JSON format.