update - Update data
The update() method is used to update existing records in a collection. When updating a record, the record must exist; otherwise, an error will be returned.
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
UPDATEprivilege on the table to be operated. For more information about how to view 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 how to directly grant privileges, see Directly grant privileges.
Request parameters
update(
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 and documents are provided, the embeddingFunction will be used to generate it. | [[0.9, 0.8, 0.7], [0.6, 0.5, 0.4]] |
documents | string | string[] | No | The document content, which can be a single string or an array of strings. | "New document text" |
metadatas | Metadata | Metadata[] | No | The metadata, which can be a single object or an array of objects. | {"category": "AI"} |
- At least one of
embeddings,metadatas, ordocumentsmust be provided. - Only metadata can be updated (no vectors or documents). The
embeddingFunctionused is the one associated with the collection. - The length of all array parameters must be the same as the length of the
idsarray. - Only existing records are updated. Non-existent IDs are ignored.
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.update({
ids: "item1",
documents: "New document text",
metadatas: { category: "AI" }
});
Response parameters
None