Use a custom embedding function
After you create and register a custom embedding function, you can use it when you create or retrieve a collection.
Here is an example:
import { SeekdbClient } from "seekdb";
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});
// Create a collection with a custom embedding function
const ef = new MyCustomEmbeddingFunction();
const collection = await client.createCollection({
name: "my_collection",
configuration: {
dimension: 384,
distance: "cosine"
},
embeddingFunction: ef
});
// Retrieve a collection with a custom embedding function
const collection = await client.getCollection({
name: "my_collection",
embeddingFunction: ef
});
// Use the collection - documents will be automatically embedded
await collection.add({
ids: ["doc1", "doc2"],
documents: ["Document 1", "Document 2"], // Vectors are automatically generated
metadatas: [{ tag: "A" }, { tag: "B" }]
});
// Text-based query - query vector is automatically generated
const results = await collection.query({
queryTexts: "My query",
nResults: 10
});
Related operations
If you want to use other built-in functions or custom functions, you can refer to the following documentation to create and use custom functions: