React Native RAG - v0.2.0
    Preparing search index...

    Class MemoryVectorStore

    In-memory implementation of VectorStore.

    Useful for testing or ephemeral/local scenarios where persistence is not required. Stores all vectors in a Map and performs cosine similarity search on demand.

    const store = await new MemoryVectorStore({ embeddings }).load();
    await store.add({ documents: ['hello world'] });
    const [[top]] = await store.query({ queryTexts: ['hello'] });
    console.log(top.id, top.similarity);

    Implements

    Index

    Constructors

    Methods

    • Adds a document to the in-memory store.

      Parameters

      • params: {
            document?: string;
            embedding?: number[];
            id?: string;
            metadata?: Record<string, any>;
        }

        Parameters for the operation.

        • Optionaldocument?: string

          Raw text content for the document.

        • Optionalembedding?: number[]

          Embeddings for the document.

        • Optionalid?: string

          ID for the document.

        • Optionalmetadata?: Record<string, any>

          Metadata for the document.

      Returns Promise<string>

      Promise that resolves to the ID of the newly added document.

    • Deletes documents by predicate.

      Parameters

      • params: { predicate: (value: GetResult) => boolean }

        Parameters for deletion.

        • predicate: (value: GetResult) => boolean

          Predicate to match documents for deletion.

      Returns Promise<void>

      Promise that resolves once the documents are deleted.

    • Executes a cosine-similarity query over the in-memory vectors. Provide exactly one of queryText or queryEmbedding.

      Parameters

      • params: {
            nResults?: number;
            predicate?: (value: QueryResult) => boolean;
            queryEmbedding?: number[];
            queryText?: string;
        }

        Query parameters.

        • OptionalnResults?: number

          Number of top results to return.

        • Optionalpredicate?: (value: QueryResult) => boolean

          Function to filter results after retrieval.

        • OptionalqueryEmbedding?: number[]

          Precomputed query embedding.

        • OptionalqueryText?: string

          Raw query string to search for.

      Returns Promise<QueryResult[]>

      Promise that resolves to an array of QueryResult.

    • Unloads underlying dependencies (embeddings).

      Returns Promise<void>

      Promise that resolves when unloading is complete.

    • Updates a document by ID. Recomputes the embedding when document is provided and embedding is omitted.

      Parameters

      • params: {
            document?: string;
            embedding?: number[];
            id: string;
            metadata?: Record<string, any>;
        }

        Update parameters.

        • Optionaldocument?: string

          New content.

        • Optionalembedding?: number[]

          New embedding.

        • id: string

          ID of the document to update.

        • Optionalmetadata?: Record<string, any>

          New metadata.

      Returns Promise<void>

      Promise that resolves when the update completes.