From 8247f9dc3eed446c2e1a3c14477406d633c3091d Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 4 Aug 2025 23:58:20 +0800 Subject: [PATCH] docs: update table creation examples to use 'if_exists' parameter for better clarity --- src/ai/guides/auto-embedding.md | 6 +++--- src/ai/guides/fulltext-search.md | 2 +- src/ai/guides/hybrid-search.md | 2 +- src/ai/guides/image-search.md | 2 +- src/ai/guides/joins.md | 4 ++-- src/ai/guides/tables.md | 8 ++++---- src/ai/guides/vector-search.md | 4 ++-- src/ai/quickstart.md | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ai/guides/auto-embedding.md b/src/ai/guides/auto-embedding.md index b0f10609..461297a4 100644 --- a/src/ai/guides/auto-embedding.md +++ b/src/ai/guides/auto-embedding.md @@ -35,14 +35,14 @@ Auto embedding is a feature that allows you to automatically generate vector emb ```python hl_lines="7" from pytidb.schema import TableModel, Field - from pytidb.datatype import Text + from pytidb.datatype import TEXT class Chunk(TableModel): id: int = Field(primary_key=True) - text: str = Field(sa_type=Text) + text: str = Field(sa_type=TEXT) text_vec: list[float] = embed_func.VectorField(source_field="text") - table = client.create_table(schema=Chunk, mode="overwrite") + table = client.create_table(schema=Chunk, if_exists="overwrite") ``` You don't need to specify the `dimensions` parameter, it will be automatically determined by the embedding model. diff --git a/src/ai/guides/fulltext-search.md b/src/ai/guides/fulltext-search.md index 311ffba4..722302b9 100644 --- a/src/ai/guides/fulltext-search.md +++ b/src/ai/guides/fulltext-search.md @@ -35,7 +35,7 @@ TiDB provides full-text search capabilities for **massive datasets** with high p id: int = Field(primary_key=True) title: str = FullTextField(fts_parser="MULTILINGUAL") - table = client.create_table(schema=Item, mode="overwrite") + table = client.create_table(schema=Item, if_exists="overwrite") ``` The `fts_parser` parameter specifies the parser for the full-text index. Supported values: diff --git a/src/ai/guides/hybrid-search.md b/src/ai/guides/hybrid-search.md index 12f858eb..8399dac1 100644 --- a/src/ai/guides/hybrid-search.md +++ b/src/ai/guides/hybrid-search.md @@ -47,7 +47,7 @@ embed_fn = EmbeddingFunction( text: str = FullTextField() text_vec: list[float] = embed_fn.VectorField(source_field="text") - table = client.create_table(schema=Chunk, mode="overwrite") + table = client.create_table(schema=Chunk, if_exists="overwrite") ``` In this example, PyTiDB will automatically create a full-text index on the `text` column and a vector index on the `text_vec` column. diff --git a/src/ai/guides/image-search.md b/src/ai/guides/image-search.md index 72d690c5..f08e38e4 100644 --- a/src/ai/guides/image-search.md +++ b/src/ai/guides/image-search.md @@ -43,7 +43,7 @@ class ImageItem(TableModel): source_field="image_uri" ) -table = client.create_table(schema=ImageItem, mode="overwrite") +table = client.create_table(schema=ImageItem, if_exists="overwrite") ``` ### Step 3. Insert image data diff --git a/src/ai/guides/joins.md b/src/ai/guides/joins.md index 936e8b32..5a65aa3c 100644 --- a/src/ai/guides/joins.md +++ b/src/ai/guides/joins.md @@ -23,7 +23,7 @@ As a relational database, TiDB allows you to store diverse data in tables with d id: int = Field(primary_key=True) title: str = Field(max_length=255) - client.create_table(schema=Document, mode="overwrite") + client.create_table(schema=Document, if_exists="overwrite") client.table("documents").truncate() client.table("documents").bulk_insert([ Document(id=1, title="The Power of Positive Thinking"), @@ -41,7 +41,7 @@ As a relational database, TiDB allows you to store diverse data in tables with d text: str = Field(max_length=255) document_id: int = Field(foreign_key="documents.id") - client.create_table(schema=Chunk, mode="overwrite") + client.create_table(schema=Chunk, if_exists="overwrite") client.table("chunks").truncate() client.table("chunks").bulk_insert([ Chunk(id=1, text="Positive thinking can change your life", document_id=1), diff --git a/src/ai/guides/tables.md b/src/ai/guides/tables.md index 915cb1d7..1e7bb816 100644 --- a/src/ai/guides/tables.md +++ b/src/ai/guides/tables.md @@ -37,15 +37,15 @@ In the following example, you create a table named `items` with these columns: embedding: list[float] = VectorField(dimensions=3) meta: dict = Field(sa_type=JSON, default_factory=dict) - table = client.create_table(schema=Item, mode="overwrite") + table = client.create_table(schema=Item, if_exists="overwrite") ``` The `create_table` method accepts these parameters: - `schema`: The `TableModel` class that defines your table structure. - - `mode`: The creation mode of the table. - - `create` (default): Creates the table if it does not exist; raises an error if it already exists. - - `exists_ok`: Creates the table if it does not exist; does nothing if it already exists. + - `if_exists`: The creation mode of the table. + - `raise` (default): Creates the table if it does not exist; raises an error if it already exists. + - `skip`: Creates the table if it does not exist; does nothing if it already exists. - `overwrite`: Drops the existing table and creates a new one. This is useful for **testing and development**, but not recommended for production environments. Once the table is created, you can use the `table` object to insert, update, delete, and query data. diff --git a/src/ai/guides/vector-search.md b/src/ai/guides/vector-search.md index 2b469f3f..117dc416 100644 --- a/src/ai/guides/vector-search.md +++ b/src/ai/guides/vector-search.md @@ -36,7 +36,7 @@ This section shows you how to use vector search in your application in minimal s text_vec: list[float] = VectorField(dimensions=3) meta: dict = Field(sa_type=JSON, default_factory=dict) - table = client.create_table(schema=Document, mode="overwrite") + table = client.create_table(schema=Document, if_exists="overwrite") ``` The `VectorField` class accepts the following parameters: @@ -385,7 +385,7 @@ For example, you can store both text embeddings and image embeddings in the same image_url: str image_vec: list[float] = VectorField(dimensions=3) - table = client.create_table(schema=RichTextDocument, mode="overwrite") + table = client.create_table(schema=RichTextDocument, if_exists="overwrite") # Insert sample data ... diff --git a/src/ai/quickstart.md b/src/ai/quickstart.md index 0b9b4ecf..8c285d0b 100644 --- a/src/ai/quickstart.md +++ b/src/ai/quickstart.md @@ -134,7 +134,7 @@ As an example, create a table named `chunks` with the following columns: text_vec: list[float] = text_embed.VectorField(source_field="text") user_id: int = Field() - table = client.create_table(schema=Chunk, mode="overwrite") + table = client.create_table(schema=Chunk, if_exists="overwrite") ``` Once created, you can use the `table` object to insert data, search data, and more.