Files
gh-oceanbase-ecology-plugin…/skills/seekdb-docs/official-docs/200.develop/900.sdk/60.embedding-funcations/300.using-custom-embedding-functions-of-api.md
2025-11-30 08:44:54 +08:00

1.0 KiB

slug
slug
/using-custom-embedding-functions-of-api

Use a custom embedding function

After you create a custom embedding function, you can use it when you create or get a collection.

Here is an example:

import pyseekdb
from pyseekdb import HNSWConfiguration

# Create a client
client = pyseekdb.Client()

# Create collection with custom embedding function
ef = SentenceTransformerCustomEmbeddingFunction()
collection = client.create_collection(
    name="my_collection",
    configuration=HNSWConfiguration(dimension=ef.dimension, distance='cosine'),
    embedding_function=ef
)

# Get collection with custom embedding function
collection = client.get_collection("my_collection", embedding_function=ef)

# Use the collection - documents will be automatically embedded
collection.add(
    ids=["doc1", "doc2"],
    documents=["Document 1", "Document 2"],  # Vectors auto-generated
    metadatas=[{"tag": "A"}, {"tag": "B"}]
)

# Query with texts - query vectors auto-generated
results = collection.query(
    query_texts=["my query"],
    n_results=10
)