跳到主要内容
版本:V1.1.0

getCollection - 获取 collection

getCollection() 用于获取指定的 Collection。

信息

仅支持在使用 SeekdbClient 连接时,才能使用该接口。关于 SeekdbClient 的详细介绍,参见 SeekdbClient

前提条件

  • 您已经安装了 seekdb-js,有关安装 seekdb-js 的详细信息,参见 快速开始

  • 您已经安装了 seekdb 服务器模式,有关安装 seekdb 服务器模式的详细信息,参见 通过 yum install 部署 seekdb

  • 您已经连接到数据库。有关连接的详细操作参见 SeekdbClient

  • 您获取的 Collection 存在。如果 Collection 不存在,则会提示报错。

请求参数

getCollection(options: GetCollectionOptions)
参数取值类型是否必选描述取值示例
namestring必选指定要获取的 Collection 的名称。my_collection
embeddingFunctionEmbeddingFunction | 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
});

返回参数

参数返回类型是否必选描述返回示例
namestring必选指定要查询的 Collection 的名称。my_collection
dimensionint可选384
embeddingFunctionEmbeddingFunction可选DefaultEmbeddingFunction { name: 'default-embed', pipe: null, modelName: 'Xenova/all-MiniLM-L6-v2', revision: undefined, dtype: undefined, cacheDir: undefined, localFilesOnly: undefined, progressCallback: undefined }
distancestring可选cosine
metadatadict可选预留字段,暂无数据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
}

相关操作