Skip to content

Commit 16c5720

Browse files
authored
docs: update table creation examples to use 'if_exists' parameter for better clarity (#170)
1 parent 1e44b82 commit 16c5720

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

src/ai/guides/auto-embedding.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ Auto embedding is a feature that allows you to automatically generate vector emb
3535

3636
```python hl_lines="7"
3737
from pytidb.schema import TableModel, Field
38-
from pytidb.datatype import Text
38+
from pytidb.datatype import TEXT
3939

4040
class Chunk(TableModel):
4141
id: int = Field(primary_key=True)
42-
text: str = Field(sa_type=Text)
42+
text: str = Field(sa_type=TEXT)
4343
text_vec: list[float] = embed_func.VectorField(source_field="text")
4444

45-
table = client.create_table(schema=Chunk, mode="overwrite")
45+
table = client.create_table(schema=Chunk, if_exists="overwrite")
4646
```
4747

4848
You don't need to specify the `dimensions` parameter, it will be automatically determined by the embedding model.

src/ai/guides/fulltext-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TiDB provides full-text search capabilities for **massive datasets** with high p
3535
id: int = Field(primary_key=True)
3636
title: str = FullTextField(fts_parser="MULTILINGUAL")
3737

38-
table = client.create_table(schema=Item, mode="overwrite")
38+
table = client.create_table(schema=Item, if_exists="overwrite")
3939
```
4040

4141
The `fts_parser` parameter specifies the parser for the full-text index. Supported values:

src/ai/guides/hybrid-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ embed_fn = EmbeddingFunction(
4747
text: str = FullTextField()
4848
text_vec: list[float] = embed_fn.VectorField(source_field="text")
4949

50-
table = client.create_table(schema=Chunk, mode="overwrite")
50+
table = client.create_table(schema=Chunk, if_exists="overwrite")
5151
```
5252

5353
In this example, PyTiDB will automatically create a full-text index on the `text` column and a vector index on the `text_vec` column.

src/ai/guides/image-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ImageItem(TableModel):
4343
source_field="image_uri"
4444
)
4545

46-
table = client.create_table(schema=ImageItem, mode="overwrite")
46+
table = client.create_table(schema=ImageItem, if_exists="overwrite")
4747
```
4848

4949
### Step 3. Insert image data

src/ai/guides/joins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ As a relational database, TiDB allows you to store diverse data in tables with d
2323
id: int = Field(primary_key=True)
2424
title: str = Field(max_length=255)
2525

26-
client.create_table(schema=Document, mode="overwrite")
26+
client.create_table(schema=Document, if_exists="overwrite")
2727
client.table("documents").truncate()
2828
client.table("documents").bulk_insert([
2929
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
4141
text: str = Field(max_length=255)
4242
document_id: int = Field(foreign_key="documents.id")
4343

44-
client.create_table(schema=Chunk, mode="overwrite")
44+
client.create_table(schema=Chunk, if_exists="overwrite")
4545
client.table("chunks").truncate()
4646
client.table("chunks").bulk_insert([
4747
Chunk(id=1, text="Positive thinking can change your life", document_id=1),

src/ai/guides/tables.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ In the following example, you create a table named `items` with these columns:
3737
embedding: list[float] = VectorField(dimensions=3)
3838
meta: dict = Field(sa_type=JSON, default_factory=dict)
3939

40-
table = client.create_table(schema=Item, mode="overwrite")
40+
table = client.create_table(schema=Item, if_exists="overwrite")
4141
```
4242

4343
The `create_table` method accepts these parameters:
4444

4545
- `schema`: The `TableModel` class that defines your table structure.
46-
- `mode`: The creation mode of the table.
47-
- `create` (default): Creates the table if it does not exist; raises an error if it already exists.
48-
- `exists_ok`: Creates the table if it does not exist; does nothing if it already exists.
46+
- `if_exists`: The creation mode of the table.
47+
- `raise` (default): Creates the table if it does not exist; raises an error if it already exists.
48+
- `skip`: Creates the table if it does not exist; does nothing if it already exists.
4949
- `overwrite`: Drops the existing table and creates a new one. This is useful for **testing and development**, but not recommended for production environments.
5050

5151
Once the table is created, you can use the `table` object to insert, update, delete, and query data.

src/ai/guides/vector-search.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This section shows you how to use vector search in your application in minimal s
3636
text_vec: list[float] = VectorField(dimensions=3)
3737
meta: dict = Field(sa_type=JSON, default_factory=dict)
3838

39-
table = client.create_table(schema=Document, mode="overwrite")
39+
table = client.create_table(schema=Document, if_exists="overwrite")
4040
```
4141

4242
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
385385
image_url: str
386386
image_vec: list[float] = VectorField(dimensions=3)
387387

388-
table = client.create_table(schema=RichTextDocument, mode="overwrite")
388+
table = client.create_table(schema=RichTextDocument, if_exists="overwrite")
389389

390390
# Insert sample data ...
391391

src/ai/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ As an example, create a table named `chunks` with the following columns:
134134
text_vec: list[float] = text_embed.VectorField(source_field="text")
135135
user_id: int = Field()
136136

137-
table = client.create_table(schema=Chunk, mode="overwrite")
137+
table = client.create_table(schema=Chunk, if_exists="overwrite")
138138
```
139139

140140
Once created, you can use the `table` object to insert data, search data, and more.

0 commit comments

Comments
 (0)