In-memory key-value store with optional vector search.
A lightweight store implementation using JavaScript Maps. Supports basic key-value operations and vector search when configured with embeddings.
class InMemoryStoreList and filter namespaces in the store.
Execute multiple operations in a single batch. This is more efficient than executing operations individually.
Delete an item from the store.
Retrieve a single item by its namespace and key.
List and filter namespaces in the store. Used to explore data organization and navigate the namespace hierarchy.
Store or update an item.
Search for items within a namespace prefix. Supports both metadata filtering and vector similarity search.
Start the store. Override if initialization is needed.
Stop the store. Override if cleanup is needed.
// Basic key-value storage
const store = new InMemoryStore();
await store.put(["users", "123"], "prefs", { theme: "dark" });
const item = await store.get(["users", "123"], "prefs");
// Vector search with embeddings
import { OpenAIEmbeddings } from "@langchain/openai";
const store = new InMemoryStore({
index: {
dims: 1536,
embeddings: new OpenAIEmbeddings({ modelName: "text-embedding-3-small" }),
}
});
// Store documents
await store.put(["docs"], "doc1", { text: "Python tutorial" });
await store.put(["docs"], "doc2", { text: "TypeScript guide" });
// Search by similarity
const results = await store.search(["docs"], { query: "python programming" });