Skip to main content
Version: V1.4.1

upsert - Update or insert data

The upsert() method is used to insert new records or update existing records. If a record with the given ID exists, it will be updated; otherwise, a new record will be inserted.

info

This API can only be used when connected with SeekdbClient. For more information about SeekdbClient, see SeekdbClient.

Prerequisites​

  • You have installed seekdb-js. For more information, see Quick start.

  • If you use seekdb in server mode, make sure seekdb server mode is installed. For more information, see Deploy seekdb with package managers.

  • You have connected to the database. For more information, see SeekdbClient.

  • The user to which you are connected has the INSERT and UPDATE privileges on the table to be operated. For more information about viewing the current user privileges, see View user privileges. If the user does not have this privilege, contact the administrator to grant it. For more information about directly granting privileges, see Directly grant privileges.

Request parameters​

upsert(
ids: ids,
embeddings: embeddings,
documents: documents,
metadatas: metadatas
)
ParameterTypeRequiredDescriptionExample Value
idsstring | string[]YesThe ID to be modified. It can be a single ID or an array of IDs.item1
embeddingsnumber[] | number[][]NoIt can be a single vector or an array of vectors. If not provided but documents are provided, the embeddingFunction will be used to generate embeddings.[0.1, 0.2, 0.3]
documentsstring | string[]NoThe document content, which can be a single string or an array of strings."document text"
metadatasMetadata | Metadata[]NoThe metadata, which can be a single object or an array of objects.{"category": "AI"}

Request example​

import { SeekdbClient } from "seekdb";

// Embedded mode - Database management (seekdb Embedded)
// const client = new SeekdbClient({
// path: "./seekdb.db",
// database: "test",
// });

// Remote server mode - Database management (seekdb Server)
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});

const collection = await client.getCollection({
name: "my_collection"
});

await collection.upsert({
ids: "item1",
documents: "document text",
metadatas: { category: "AI" }
});

Response parameters​

None