Skip to main content

Memory Vector Index

The memory vector index is a simple implementation of the VectorIndex interface that stores all vectors in memory. It is helpful for development and prototyping or when you only have a small number of entries and want to avoid setting up a database, e.g., for conversational memory that does not need to be persisted.

Usage

API | Examples

Create a Vector Index

import { MemoryVectorIndex, zodSchema } from "modelfusion";

const vectorIndex = new MemoryVectorIndex<TextChunk>();

Serialization

const serializedData = vectorIndex.serialize();

Deserialization

Deserialization can optionally take a Zod schema for type validation:

const deserializedIndex = await MemoryVectorIndex.deserialize({
serializedData,
schema: zodSchema(z.object({ text: z.string() })),
});