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
)