upsertFromDatabase
Inserts or updates vectors from a Database Element.
upsertFromDatabase(
database: Database,
options?: {
keys: string[]
metadata?: Record<string, any>
textSplitter?: SplitterParams
}
): Promise<string[]>
Reference
import { myVectorStore, myDatabase } from "#elements";
export default async function () {
const count = await myVectorStore.upsertFromDatabase(myDatabase, {
keys: ["key1", "key2"],
});
console.log(`${count} vectors upserted`);
}
Parameters
database
: The Database Element to extract content from.options
: Optional configuration parameters, including:keys
: (optional) An array of keys of the items to upsert. If not provided, all items in the database 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 key does not exist in the VectorStore, or update the existing vector if the key exists.
- You can query all the results by filtering the metadata field
database
todatabase
.