Class FirestoreVectorStore

java.lang.Object
com.google.genkit.plugins.firebase.retriever.FirestoreVectorStore

public class FirestoreVectorStore extends Object
Firestore vector store implementation for RAG workflows.

Provides vector similarity search using Cloud Firestore's native vector search capabilities. Supports COSINE, EUCLIDEAN, and DOT_PRODUCT distance measures.

Example usage:


 // Retrieve documents
 RetrieverResponse response = genkit.retrieve("firebase/my-docs", Document.fromText("What is the meaning of life?"),
 		Map.of("limit", 5));
 
 // Index documents
 genkit.index("firebase/my-docs",
 		List.of(Document.fromText("The meaning of life is 42"), Document.fromText("Life is what you make of it")));
 
  • Constructor Details

    • FirestoreVectorStore

      public FirestoreVectorStore(com.google.cloud.firestore.Firestore firestore, FirestoreRetrieverConfig config, Embedder embedder)
      Creates a new FirestoreVectorStore.
      Parameters:
      firestore - the Firestore instance
      config - the retriever configuration
      embedder - the embedder to use
    • FirestoreVectorStore

      public FirestoreVectorStore(com.google.cloud.firestore.Firestore firestore, FirestoreRetrieverConfig config, Embedder embedder, String projectId)
      Creates a new FirestoreVectorStore with explicit project ID.
      Parameters:
      firestore - the Firestore instance
      config - the retriever configuration
      embedder - the embedder to use
      projectId - the Google Cloud project ID
  • Method Details

    • ensureDatabaseExists

      public void ensureDatabaseExists() throws GenkitException
      Ensures the Firestore database exists, creating it if configured to do so.
      Throws:
      GenkitException - if database creation fails
    • ensureVectorIndexExists

      public void ensureVectorIndexExists() throws GenkitException
      Ensures the Firestore vector index exists, creating it if configured to do so.
      Throws:
      GenkitException - if index creation fails
    • createRetriever

      public Retriever createRetriever()
      Creates a Retriever action for this vector store.
      Returns:
      the Retriever action
    • createIndexer

      public Indexer createIndexer()
      Creates an Indexer action for this vector store.
      Returns:
      the Indexer action
    • retrieve

      public RetrieverResponse retrieve(ActionContext ctx, RetrieverRequest request) throws GenkitException
      Retrieves documents from Firestore using vector similarity search.
      Parameters:
      ctx - the action context
      request - the retriever request
      Returns:
      the retriever response with matched documents
      Throws:
      GenkitException - if retrieval fails
    • index

      public IndexerResponse index(ActionContext ctx, IndexerRequest request) throws GenkitException
      Indexes documents into Firestore with their embeddings.
      Parameters:
      ctx - the action context
      request - the indexer request
      Returns:
      the indexer response
      Throws:
      GenkitException - if indexing fails