This sample app demonstrates the use of the Vertex AI plugin retriever and indexer with Firestore for storing document content and metadata. This guide will walk you through setting up and running the sample.
Before running this sample, ensure you have the following:
- Node.js installed.
- PNPM (Node Package Manager) installed.
- A deployed index to an index endpoint in Vertex AI Vector Search.
- A Firestore instance.
Clone this repository to your local machine, and follow the instructions in the root README.md to build
the core packages. This sample uses workspace:*
dependencies, so they will need to be accessible.
Then
cd js/testapps/vertex-vector-search-bigquery && pnpm i
Ensure you have a deployed index in Vertex AI Vector Search.
Create a .env
file in the root directory and set the following variables (see the .env.example as well if needed)
PROJECT_ID=your-google-cloud-project-id
LOCATION=your-vertex-ai-location
FIRESTORE_COLLECTION=your_firestore_collection_here
VECTOR_SEARCH_PUBLIC_DOMAIN_NAME=your-vector-search-public-domain-name
VECTOR_SEARCH_INDEX_ENDPOINT_ID=your-index-endpoint-id
VECTOR_SEARCH_INDEX_ID=your-index-id
VECTOR_SEARCH_DEPLOYED_INDEX_ID=your-deployed-index-id
GOOGLE_APPLICATION_CREDENTIALS=path-to-your-service-account-key.json
Start the Genkit server:
genkit start
This sample demonstrates how to define a custom document indexer and retriever using Cloud Firestore. It integrates with Vertex AI for indexing and retrieval of documents.
- Firestore Document Indexer: Stores documents in a Firestore collection
- Firestore Document Retriever: Retrieves documents from the Firestore collection based on neighbor IDs.
- Genkit Configuration: Configures Genkit with the Vertex AI plugin, setting up the project, location, and vector search index options.
- Indexing Flow: Defines a flow for indexing documents.
- Query Flow: Defines a flow for querying indexed documents.
The firestoreDocumentIndexer
function writes document content and metadata to a Firestore collection, and returns the generated Firestore document ids:
const firestoreDocumentIndexer: DocumentIndexer = getFirestoreDocumentIndexer(
db,
FIRESTORE_COLLECTION
);
The firestoreDocumentRetriever
function reads from the Firestore Collection and retrieves documents based on neighbor IDs:
const firestoreDocumentRetriever: DocumentRetriever =
getFirestoreDocumentRetriever(db, FIRESTORE_COLLECTION);
Two flows are defined: indexFlow
for indexing documents and queryFlow
for querying documents.
- Index Flow: Converts text inputs to documents and indexes them.
- Query Flow: Retrieves documents based on a query and returns the results sorted by distance.
The server is started using the startFlowsServer
function, which sets up the Genkit server to handle flow requests.
startFlowsServer();
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
This sample provides a basic demonstration of using Vertex AI plugins with Genkit for document indexing and retrieval. It can be extended and adapted to suit more complex use cases and integrations with other data sources and services.
For more information, please refer to the official Firebase Genkit documentation.