Skip to main content
Version: V1.1.0

Default embedding function

An embedding function converts text documents into vector embeddings for similarity search. seekdb-js supports both built-in and custom embedding functions.

The default embedding function uses a local model (Xenova/all-MiniLM-L6-v2), requires no API key, and is suitable for quick development and testing. You must install @seekdb/default-embed manually before use:

npm install @seekdb/default-embed

After installation, you can use the default embedding logic in either of the following ways:

  • Option 1: Omit embeddingFunction when creating a collection. The system automatically uses the default embedding function for vectorization.

    // When embeddingFunction is omitted, the default embedding function is used.
    const collection = await client.createCollection({
    name: "local_embed_collection",
    });
  • Option 2: Pass a DefaultEmbeddingFunction instance explicitly (useful when you want to always pass an embedding function to the API).

    import { DefaultEmbeddingFunction } from "@seekdb/default-embed";

    const defaultEmbed = new DefaultEmbeddingFunction({
    // If you run into download issues, try switching region; default is 'cn'.
    // region: 'intl'
    });

    const collection = await client.createCollection({
    name: "local_embed_collection",
    embeddingFunction: defaultEmbed,
    });

The first time you run vectorization, the model is downloaded automatically. This usually takes 3–5 minutes depending on your network. Please allow time for it to complete.

To use other built-in embedding functions or define your own, see: