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

使用自定义嵌入函数

创建并注册自定义嵌入函数后,在创建或获取 collections 时使用它。

示例如下:

import { SeekdbClient } from "seekdb";

const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});

// 创建带自定义向量函数的集合
const ef = new MyCustomEmbeddingFunction();

const collection = await client.createCollection({
name: "my_collection",
configuration: {
dimension: 384,
distance: "cosine"
},
embeddingFunction: ef
});

// 获取带自定义向量函数的集合
const collection = await client.getCollection({
name: "my_collection",
embeddingFunction: ef
});

// 使用集合 - 文档将自动嵌入
await collection.add({
ids: ["doc1", "doc2"],
documents: ["文档 1", "文档 2"], // 向量自动生成
metadatas: [{ tag: "A" }, { tag: "B" }]
});

// 带文本查询 - 查询向量自动生成
const results = await collection.query({
queryTexts: "我的查询",
nResults: 10
});

相关操作

如果您需要使用其他内置函数或者自定义函数,可以参考以下文档创建和使用自定义函数: