Dev Local Vector Store
The Dev Local Vector Store plugin provides a local, file-based vector store for development and testing purposes. It is not intended for production use.
Installation
Section titled “Installation”pip3 install genkit-plugin-dev-local-vectorstore
Configuration
Section titled “Configuration”To use this plugin, specify it when you initialize Genkit:
from genkit.ai import Genkitfrom genkit.plugins.dev_local_vectorstore import DevLocalVectorStorefrom genkit.plugins.google_genai import VertexAI # Assuming VertexAI is used for embedder
ai = Genkit( plugins=[ VertexAI(), # Ensure the embedder's plugin is loaded DevLocalVectorStore( name='my_vectorstore', embedder='vertexai/text-embedding-004', # Example embedder ), ], # Define a default model if needed # model='vertexai/gemini-1.5-flash',)
Configuration Options
Section titled “Configuration Options”- name (str): A unique name for this vector store instance. This is used as the
retriever
argument toai.retrieve
. - embedder (str): The name of the embedding model to use. Must match a configured embedder in your Genkit project.
- embedder_options (dict, optional): Options to pass to the embedder.
Indexing Documents
Section titled “Indexing Documents”The Dev Local Vector Store automatically creates indexes. To populate with data you must call the static method .index(name, documents)
:
from genkit.ai import Genkitfrom genkit.plugins.dev_local_vectorstore import DevLocalVectorStorefrom genkit.plugins.google_genai import VertexAI # Assuming VertexAI is used for embedderfrom genkit.types import Document
# Assuming 'ai' is configured as shown in the Configuration section# ai = Genkit(...)
data_list = [ 'This is the first document.', 'This is the second document.', 'This is the third document.', "This is the fourth document.",]
genkit_docs = [Document.from_text(text=item) for item in data_list]# Ensure the vector store name matches the one in the Genkit configawait DevLocalVectorStore.index('my_vectorstore', genkit_docs)
Retrieving Documents
Section titled “Retrieving Documents”Use ai.retrieve
and pass the store name configured in the DevLocalVectorStore constructor.
from genkit.types import Document# Assuming 'ai' is configured as shown in the Configuration section# ai = Genkit(...)
docs = await ai.retrieve( query=Document.from_text('search query'), retriever='my_vectorstore', # Matches the 'name' in DevLocalVectorStore config)# print(docs) # Process the retrieved documents
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)}
_, myRetriever, err := localvec.DefineRetriever( g, "my_vectorstore", localvec.Config{ Embedder: googlegenai.VertexAIEmbedder(g, "text-embedding-004"), },)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))}
// You would implement your own indexing logic here// The local vector store handles the embedding and storage internally
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)}
The Dev Local Vector Store plugin provides a local, file-based vector store for development and testing purposes. It is not intended for production use.
Installation
Section titled “Installation”npm install @genkit-ai/dev-local-vectorstore
Configuration
Section titled “Configuration”To use this plugin, specify it when you initialize Genkit:
import { devLocalVectorstore } from '@genkit-ai/dev-local-vectorstore';import { googleAI } from '@genkit-ai/google-genai';import { genkit } from 'genkit';
const ai = genkit({ plugins: [ // googleAI provides the embedding models googleAI(),
// Configure the local vector store with an embedder devLocalVectorstore([ { indexName: 'my_vectorstore', embedder: googleAI.embedder('gemini-embedding-001'), }, ]), ],});
Configuration Options
Section titled “Configuration Options”- indexName (string): A unique name for this vector store instance. This is used as the indexer and retriever reference.
- embedder (EmbedderReference): 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, use the indexer reference and ai.index
:
import { devLocalIndexerRef } from '@genkit-ai/dev-local-vectorstore';import { Document } from 'genkit/retriever';
// Create the indexer referenceconst myIndexer = devLocalIndexerRef('my_vectorstore');
// Create documents from textconst data = [ 'This is the first document.', 'This is the second document.', 'This is the third document.', 'This is the fourth document.',];
const documents = data.map((text) => Document.fromText(text));
// Index the documentsawait ai.index({ indexer: myIndexer, documents,});
Retrieving Documents
Section titled “Retrieving Documents”Use ai.retrieve
with the retriever reference:
import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore';
// Create the retriever referenceconst myRetriever = devLocalRetrieverRef('my_vectorstore');
// Retrieve documents relevant to a queryconst docs = await ai.retrieve({ retriever: myRetriever, query: 'search query', options: { k: 3 }, // Return top 3 results});
// Process the retrieved documentsdocs.forEach(doc => { console.log(doc.content);});