Skip to content

Commit 34786d7

Browse files
Mini256Wendong-Fan
andauthored
enhance: replace pytidb-experimental with pytidb dep for tidb integration (#3073)
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent 29b8eea commit 34786d7

File tree

5 files changed

+26
-34
lines changed

5 files changed

+26
-34
lines changed

camel/retrievers/auto_retriever.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def _initialize_vector_storage(
9797
"URL (database url) and API key required for TiDB storage "
9898
"are not provided. Format: "
9999
"mysql+pymysql://<username>:<password>@<host>:4000/test"
100+
"You can get the database url from https://tidbcloud.com/console/clusters"
100101
)
101102
return TiDBStorage(
102103
vector_dim=self.embedding_model.get_output_dim(),

camel/storages/vectordb_storages/tidb.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TiDBStorage(BaseVectorStorage):
4444
r"""An implementation of the `BaseVectorStorage` for interacting with TiDB.
4545
4646
The detailed information about TiDB is available at:
47-
`TiDB Vector Search <https://ai.pingcap.com/>`_
47+
`TiDB Vector Search <https://pingcap.com/ai>`_
4848
4949
Args:
5050
vector_dim (int): The dimension of storing vectors.
@@ -107,10 +107,10 @@ def _create_client(
107107
)
108108

109109
def _get_table_model(self, collection_name: str) -> Any:
110+
from pytidb.datatype import JSON
110111
from pytidb.schema import Field, TableModel, VectorField
111-
from sqlalchemy import JSON
112112

113-
class VectorDBRecord(TableModel):
113+
class VectorDBRecordBase(TableModel, table=False):
114114
id: Optional[str] = Field(None, primary_key=True)
115115
vector: list[float] = VectorField(self.vector_dim)
116116
payload: Optional[dict[str, Any]] = Field(None, sa_type=JSON)
@@ -119,7 +119,7 @@ class VectorDBRecord(TableModel):
119119
# class names.
120120
return type(
121121
f"VectorDBRecord_{collection_name}",
122-
(VectorDBRecord,),
122+
(VectorDBRecordBase,),
123123
{"__tablename__": collection_name},
124124
table=True,
125125
)
@@ -128,8 +128,9 @@ def _open_and_create_table(self) -> "Table[Any]":
128128
r"""Opens an existing table or creates a new table in TiDB."""
129129
table = self._client.open_table(self.collection_name)
130130
if table is None:
131+
table_model = self._get_table_model(self.collection_name)
131132
table = self._client.create_table(
132-
schema=self._get_table_model(self.collection_name)
133+
schema=table_model, if_exists="skip"
133134
)
134135
return table
135136

@@ -166,6 +167,7 @@ def _get_table_info(self) -> Dict[str, Any]:
166167
table.
167168
"""
168169
vector_count = self._table.rows()
170+
169171
# Get vector dimension from table schema
170172
columns = self._table.columns()
171173
dim_value = None
@@ -303,7 +305,7 @@ def query(
303305
for row in rows:
304306
query_results.append(
305307
VectorDBQueryResult.create(
306-
similarity=float(row['similarity_score']),
308+
similarity=float(row['_score']),
307309
id=str(row['id']),
308310
payload=row['payload'],
309311
vector=row['vector'],

docs/key_modules/storages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The <b>Storage</b> module in CAMEL-AI gives you a **unified interface for saving
4545
- High scalability, real-time search
4646

4747
**TiDBStorage**
48-
- For [TiDB](https://ai.pingcap.com/) (hybrid vector/relational database)
48+
- For [TiDB](https://pingcap.com/ai) (hybrid vector/relational database)
4949
- Handles embeddings, knowledge graphs, ops data
5050

5151
**QdrantStorage**

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ rag = [
6969
"numpy>=1.2,<=2.2",
7070
"qdrant-client>=1.9.0,<2",
7171
"pymilvus>=2.4.0,<3",
72-
"pytidb-experimental==0.0.1.dev4",
72+
"pytidb>=0.0.13",
7373
"faiss-cpu>=1.7.2,<2",
7474
"weaviate-client>=4.15.0",
7575
"protobuf>=6.0.0",
@@ -200,7 +200,7 @@ huggingface = [
200200
storage = [
201201
"qdrant-client>=1.9.0,<2",
202202
"pymilvus>=2.4.0,<3",
203-
"pytidb-experimental==0.0.1.dev4",
203+
"pytidb>=0.0.13",
204204
"faiss-cpu>=1.7.2,<2",
205205
"neo4j>=5.18.0,<6",
206206
"nebula3-python==3.8.2",
@@ -360,7 +360,7 @@ all = [
360360
"networkx>=3.4.2,<4",
361361
"qdrant-client>=1.9.0,<2",
362362
"pymilvus>=2.4.0,<3",
363-
"pytidb-experimental==0.0.1.dev4",
363+
"pytidb>=0.0.13",
364364
"faiss-cpu>=1.7.2,<2",
365365
"cohere>=5.11.0,<6",
366366
"neo4j>=5.18.0,<6",

uv.lock

Lines changed: 13 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)