Skip to content

Pinecone Vector Database

The Pinecone plugin provides indexer and retriever implementations that use the Pinecone cloud vector database.

Pinecone is a cloud-native vector database that provides fast, scalable similarity search for AI applications. It offers managed infrastructure with automatic scaling and high availability.

Terminal window
npm install genkitx-pinecone

To use this plugin, specify it when you initialize Genkit:

import { genkit } from 'genkit';
import { pinecone } from 'genkitx-pinecone';
import { googleAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [
pinecone([
{
indexId: 'bob-facts',
embedder: googleAI.embedder('gemini-embedding-001'),
},
]),
],
});

You must specify a Pinecone index ID and the embedding model you want to use.

In addition, you must configure Genkit with your Pinecone API key. There are two ways to do this:

  • Set the PINECONE_API_KEY environment variable.

  • Specify it in the clientParams optional parameter:

    clientParams: {
    apiKey: ...,
    }

    The value of this parameter is a PineconeConfiguration object, which gets passed to the Pinecone client; you can use it to pass any parameter the client supports.

Import retriever and indexer references like so:

import { pineconeRetrieverRef } from 'genkitx-pinecone';
import { pineconeIndexerRef } from 'genkitx-pinecone';

Then, use these references with ai.retrieve() and ai.index():

// To use the index you configured when you loaded the plugin:
let docs = await ai.retrieve({ retriever: pineconeRetrieverRef, query });
// To specify an index:
export const bobFactsRetriever = pineconeRetrieverRef({
indexId: 'bob-facts',
});
docs = await ai.retrieve({ retriever: bobFactsRetriever, query });
// To use the index you configured when you loaded the plugin:
await ai.index({ indexer: pineconeIndexerRef, documents });
// To specify an index:
export const bobFactsIndexer = pineconeIndexerRef({
indexId: 'bob-facts',
});
await ai.index({ indexer: bobFactsIndexer, documents });

See the Retrieval-augmented generation page for a general discussion on indexers and retrievers.

The Pinecone plugin provides retriever implementatons that use the Pinecone cloud vector database.

Pinecone is a cloud-native vector database that provides fast, scalable similarity search for AI applications. It offers managed infrastructure with automatic scaling and high availability.

To use this plugin, import the pinecone package and call pinecone.Init():

import "github.com/firebase/genkit/go/plugins/pinecone"
if err := (&pinecone.Pinecone{}).Init(ctx, g); err != nil {
log.Fatal(err)
}

The plugin requires your Pinecone API key. Configure the plugin to use your API key by doing one of the following:

  • Set the PINECONE_API_KEY environment variable to your API key.

  • Specify the API key when you initialize the plugin:

    if err := (&pinecone.Pinecone{APIKey: pineconeAPIKey}).Init(ctx, g); err != nil {
    log.Fatal(err)
    }

    However, don’t embed your API key directly in code! Use this feature only in conjunction with a service like Cloud Secret Manager or similar.

Index your documents in pinecone. An example of indexing is provided within the Pinecone plugin as shown below. This functionality should be customized by the user according to their use case.

err := pinecone.Index(ctx, docChunks, ds, "")
if err != nil {
log.Fatal(err)
}

To retrieve documents from an index, first create a retriever definition:

menuRetriever, err := pinecone.DefineRetriever(ctx, g, pinecone.Config{
IndexID: "menu_data", // Your Pinecone index
Embedder: googlegenai.GoogleAIEmbedder(g, "text-embedding-004"), // Embedding model of your choice
})
if err != nil {
log.Fatal(err)
}

Then, call the retriever’s Retrieve() method, passing it a text query:

resp, err := genkit.Retrieve(ctx, g, ai.WithRetriever(menuRetriever), ai.WithTextDocs(userInput))
if err != nil {
log.Fatal(err)
}
menuInfo := resp.Documents

See the Retrieval-augmented generation page for a general discussion on using retrievers for RAG.