add - Insert data
The add() method is used to insert new data into a collection. When adding a record, if a record with the same ID already exists, 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 seekdb server mode. For more information, see Deploy seekdb by using yum install.
-
You are connected to the database. For more information, see SeekdbClient.
-
The user to which you are connected has the
Insertprivilege. 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
add(
ids: ids,
embeddings: embeddings,
documents: documents,
metadatas: metadatas
)
| Parameter | Type | Required | Description | Example value |
|---|---|---|---|---|
ids | string or string[] | Yes | The document ID, which can be a single ID or an array of IDs. | item1 |
embeddings | number[] | number[][] | No | A single vector or an array of vectors. If this parameter is not provided but the documents parameter is provided, the embeddingFunction will be used to generate the 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. | "Hello world", "seekdb is fast" |
metadatas | Metadata | Metadata[] | No | The metadata, which can be a single object or an array of objects. | { category: "test" }, { category: "db" } |
-
If embeddings are provided: The vectors will be used directly, and the embeddingFunction will not be called (even if it is provided).
-
If embeddings are not provided but documents are provided:
-
If the collection has an embeddingFunction (set during creation or retrieval), vectors will be automatically generated from the documents.
-
If the collection does not have an embeddingFunction, a ValueError will be returned.
-
-
If neither embeddings nor documents are provided: A
ValueErrorwill be returned. -
All array parameters must have the same length.
-
IDs cannot be duplicated.
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.createCollection({
name: "my_collection"
});
await collection.add({
ids: ["item1", "item2"],
documents: ["Hello world", "seekdb is fast"],
metadatas: [{ category: "test" }, { category: "db" }]
});
Return parameters
None