getCollection - 获取 collection
getCollection() 用于获取指定的 Collection。
信息
仅支持在使用 SeekdbClient 连接时,才能使用该接口。关于 SeekdbClient 的详细介绍,参见 SeekdbClient。
前提条件
-
您已经安装了 seekdb-js,有关安装 seekdb-js 的详细信息,参见 快速开始。
-
您已经安装了 seekdb 服务器模式,有关安装 seekdb 服务器模式的详细信息,参见 通过 yum install 部署 seekdb。
-
您已经连接到数据库。有关连接的详细操作参见 SeekdbClient。
-
您获取的 Collection 存在。如果 Collection 不存在,则会提示报错。
请求参数
getCollection(options: GetCollectionOptions)
| 参数 | 取值类型 | 是否必选 | 描述 | 取值示例 |
|---|---|---|---|---|
name | string | 必选 | 指定要获取的 Collection 的名称。 | my_collection |
embeddingFunction | EmbeddingFunction | null | 可选 | 嵌入函数。传入 null 表示不使用嵌入函数 | DefaultEmbeddingFunction() |
信息
embeddingFunction (EmbeddingFunction, 可选): 用于此集合的向量函数
- 如果未提供,默认使用
createCollection时使用的embeddingfunction。 - 如果设置为 null,集合将不使用向量函数。
- 当提供文档/文本但未提供向量时,此处设置的向量函数将用于此集合的所有操作 (add, upsert, update, query, hybridSearch)。
请求示例
import { SeekdbClient } from "seekdb";
// 1. Connect
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});
// 使用默认嵌入函数获取集合
const collection = await client.getCollection({
name: 'my_collection'
});
// 不使用嵌入函数
const collection2 = await client.getCollection({
name: 'my_collection',
embeddingFunction: null
});
返回参数
| 参数 | 返回类型 | 是否必选 | 描述 | 返回示例 |
|---|---|---|---|---|
name | string | 必选 | 指定要查询的 Collection 的名称。 | my_collection |
dimension | int | 可选 | 384 | |
embeddingFunction | EmbeddingFunction | 可选 | DefaultEmbeddingFunction { name: 'default-embed', pipe: null, modelName: 'Xenova/all-MiniLM-L6-v2', revision: undefined, dtype: undefined, cacheDir: undefined, localFilesOnly: undefined, progressCallback: undefined } | |
distance | string | 可选 | cosine | |
metadata | dict | 可选 | 预留字段,暂无数据 | undefined |
返回示例
Collection {
name: 'my_collection',
dimension: 384,
distance: 'cosine',
embeddingFunction: DefaultEmbeddingFunction {
name: 'default-embed',
pipe: null,
modelName: 'Xenova/all-MiniLM-L6-v2',
revision: undefined,
dtype: undefined,
cacheDir: undefined,
localFilesOnly: undefined,
progressCallback: undefined
},
metadata: undefined
}
Collection {
name: 'my_collection',
dimension: 384,
distance: 'cosine',
embeddingFunction: undefined,
metadata: undefined
}