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.
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.
-
You have installed the server mode of seekdb. For more information, see Deploy seekdb by using yum install.
-
You have connected to the database. For more information, see SeekdbClient.
-
The user to which you are connected has the
INSERTandUPDATEprivileges 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
)
| Parameter | Type | Required | Description | Example Value |
|---|---|---|---|---|
ids | string | string[] | Yes | The ID to be modified. It can be a single ID or an array of IDs. | item1 |
embeddings | number[] | number[][] | No | It 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] |
documents | string | string[] | No | The document content, which can be a single string or an array of strings. | "document text" |
metadatas | Metadata | Metadata[] | No | The metadata, which can be a single object or an array of objects. | {"category": "AI"} |
Request example
import { SeekdbClient } from "seekdb";
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