Dev local vector store
The Dev Local Vector Store provides a local, file-based vector store for development and testing purposes. It is not intended for production use.
Installation
Section titled “Installation”The local vector store functionality is built into Genkit Go. You need to import the localvec package:
import "github.com/firebase/genkit/go/plugins/localvec"Configuration
Section titled “Configuration”To use the local vector store, initialize it and define a retriever with an embedder:
import ( "context" "log"
"github.com/firebase/genkit/go/ai" "github.com/firebase/genkit/go/genkit" "github.com/firebase/genkit/go/plugins/googlegenai" "github.com/firebase/genkit/go/plugins/localvec")
ctx := context.Background()
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.VertexAI{}))
if err := localvec.Init(); err != nil { log.Fatal(err)}
myDocStore, myRetriever, err := localvec.DefineRetriever( g, "my_vectorstore", localvec.Config{ Embedder: googlegenai.VertexAIEmbedder(g, "text-embedding-004"), }, nil,)if err != nil { log.Fatal(err)}Configuration Options
Section titled “Configuration Options”- name (string): A unique name for this vector store instance. This is used as the retriever reference.
- Embedder (
ai.Embedder): The embedding model to use. Must be a configured embedder in your Genkit project.
Indexing Documents
Section titled “Indexing Documents”The Dev Local Vector Store automatically creates indexes. To populate with data, you need to implement your own indexing logic using the ai.Document format:
import ( "github.com/firebase/genkit/go/ai")
// Create documents from textdata := []string{ "This is the first document.", "This is the second document.", "This is the third document.", "This is the fourth document.",}
var docs []*ai.Documentfor _, text := range data { docs = append(docs, ai.DocumentFromText(text, nil))}
// Index the documents using the DocStore returned by DefineRetrievererr := localvec.Index(ctx, docs, myDocStore)if err != nil { log.Fatal(err)}Retrieving Documents
Section titled “Retrieving Documents”Use ai.Retrieve with the retriever you defined:
// Retrieve documents relevant to a queryresp, err := ai.Retrieve(ctx, myRetriever, ai.WithTextDocs("search query"))if err != nil { log.Fatal(err)}
// Process the retrieved documentsfor _, doc := range resp.Documents { fmt.Println(doc.Content)}