这是indexloc提供的服务,不要输入任何密码
Skip to content

Pinecone plugin

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

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 {
return 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 {
    return 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 {
return 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 {
return err
}

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

resp, err := menuRetriever.Retrieve(ctx, &ai.RetrieverRequest{
Query: ai.DocumentFromText(userInput, nil),
Options: nil,
})
if err != nil {
return err
}
menuInfo := resp.Documents

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