Skip to content

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.

Terminal window
pip3 install genkit-plugin-dev-local-vectorstore

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

from genkit.ai import Genkit
from genkit.plugins.dev_local_vectorstore import DevLocalVectorStore
from 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',
)
  • name (str): A unique name for this vector store instance. This is used as the retriever argument to ai.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.

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 Genkit
from genkit.plugins.dev_local_vectorstore import DevLocalVectorStore
from genkit.plugins.google_genai import VertexAI # Assuming VertexAI is used for embedder
from 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 config
await DevLocalVectorStore.index('my_vectorstore', genkit_docs)

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.

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"

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)
}
  • 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.

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 text
data := []string{
"This is the first document.",
"This is the second document.",
"This is the third document.",
"This is the fourth document.",
}
var docs []*ai.Document
for _, 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

Use ai.Retrieve with the retriever you defined:

// Retrieve documents relevant to a query
resp, err := ai.Retrieve(ctx, myRetriever, ai.WithTextDocs("search query"))
if err != nil {
log.Fatal(err)
}
// Process the retrieved documents
for _, 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.

Terminal window
npm install @genkit-ai/dev-local-vectorstore

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'),
},
]),
],
});
  • 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.

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 reference
const myIndexer = devLocalIndexerRef('my_vectorstore');
// Create documents from text
const 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 documents
await ai.index({
indexer: myIndexer,
documents,
});

Use ai.retrieve with the retriever reference:

import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore';
// Create the retriever reference
const myRetriever = devLocalRetrieverRef('my_vectorstore');
// Retrieve documents relevant to a query
const docs = await ai.retrieve({
retriever: myRetriever,
query: 'search query',
options: { k: 3 }, // Return top 3 results
});
// Process the retrieved documents
docs.forEach(doc => {
console.log(doc.content);
});