Skip to main content

upsertFromAssets

Inserts or updates vectors from an Assets Element.

upsertFromAssets(
assets: Assets,
options?: {
items?: string[]
metadata?: Record<string, any>
textSplitter?: SplitterParams
}
): Promise<string[]>

Reference

import { myVectorStore, myAssets } from "#elements";
export default async function () {
const count = await myVectorStore.upsertFromAssets(myAssets, {
items: ["/item1.txt", "/item2.txt"],
});
console.log(`${count} vectors upserted`);
}

Parameters

  • assets: The Assets Element to extract content from.
  • options: Optional configuration parameters, including:
    • items: (optional) An array of items to upsert. If not provided, all items in the assets will be upserted.
    • metadata: (optional) The metadata to associate with the vectors.
    • 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 item does not exist in the VectorStore, or update the existing vector if the item exists.
  • This method will only upsert items that are text files.
  • You can query all the results by filtering the metadata field assets to assets.