Skip to main content

upsertFromDocuments

Inserts or updates vectors from an array of documents.

upsertFromDocuments(
data: {
content: string
id?: string
metadata?: Record<string, any>
}[],
options?: {
textSplitter?: SplitterParams
}
): Promise<string[]>;

Reference

import { myVectorStore } from "#elements";
export default async function () {
const count = await myVectorStore.upsertFromDocuments([
{ content: "This is a document", id: "1", metadata: { key: "value" } },
{ content: "This is another document" },
]);
console.log(`${count} vectors upserted`);
}

Parameters

  • data: An array of objects, each containing a content string, an optional ID, and optional metadata.
    • content: The content string. It will be converted to an embedding vector before the upsert.
    • id: (Optional) The ID of the document. If not provided, a new ID will be generated.
    • metadata: (Optional) The metadata of the document.
  • options: Optional configuration parameters, including:
    • textSplitter: (Optional) The text splitter employed to divide the content into multiple vectors. In the absence of a provided splitter, the token splitter is used by default.

Returns

Promise of an array of IDs of the upserted vectors.

Caveats

  • This method will insert a new vector if the ID does not exist, or update the existing vector if the ID exists.
  • If the content field meets the tokenization criteria and an id is provided, a sequence number will be appended after the id.