v0.0.12
✨ What's New
Breaking Changes
In the new version, EmbeddingFunction for text will use server-side embedding by default, which no longer sends the request on the client side, but leaves it to the database side for automatic embedding.
You need to configure the API Key using tidb_client.configure_embedding_provider() or use the built-in Embedding model on TiDB Cloud.
If you want to fall back to client-side embedding, pass use_server=False when initializing the EmbeddingFunction.
from app.db import tidb_client
from pytidb.embeddings import EmbeddingFunction
from pytidb.schema import TableModel, Field
# Set API key globally
tidb_client.configure_embedding_provider("openai", os.getenv("OPENAI_API_KEY"))
# Define table schema with auto embedding config.
class Chunk(TableModel):
id: int = Field(primary_key=True)
text: str = Field()
text_vec: Optional[list[float]] = EmbeddingFunction(
"openai/text-embedding-3-small"
).VectorField(source_field="text")
# Create table
tbl = tidb_client.create_table(schema=Chunk, if_exists="overwrite")
# Insert data
tbl.insert(Chunk(id=1, text="foo"))
# Search
results = tbl.search("bar").limit(1).to_pydantic(with_score=True)Full Changelog: v0.0.11...v0.0.12