pytidb
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePyTiDB (pytidb)
PyTiDB (pytidb)
Use this skill to connect to TiDB from Python via , define tables, and build search / AI features on top.
pytidb使用本Skill通过从Python连接到TiDB,定义表结构,并在其之上构建搜索与AI功能。
pytidbWhen to Use This Skill
何时使用本Skill
- You want a Python ORM-like experience on TiDB via (built on SQLAlchemy).
pytidb - You want vector search / full-text search / hybrid search on TiDB with high-level APIs.
- You want runnable starter templates (scripts + small examples) you can adapt.
Need to provision a TiDB Cloud cluster first? Use (TiDB X) for cluster lifecycle guidance.
tidbx- 你希望通过(基于SQLAlchemy)在TiDB上获得类Python ORM的使用体验。
pytidb - 你希望通过高级API在TiDB上实现向量搜索/全文搜索/混合搜索。
- 你需要可直接运行的入门模板(脚本+小型示例)并进行适配。
需要先部署TiDB Cloud集群? 使用(TiDB X)获取集群生命周期管理指导。
tidbxCode Generation Rules (Python)
代码生成规则(Python)
- Never hardcode credentials; use env vars () and document required variables.
.env - Prefer and pinned deps for reproducibility.
python -m venv .venv - When editing requirements.txt, do not invent pytidb versions, use an unpinned pytidb by default unless the user explicitly requests it and the version has been verified to exist.
- Keep examples minimal and runnable; avoid framework-specific assumptions unless the user asks.
- Use parameterized SQL for any dynamic value (SQL injection safety).
- For interactive environments, avoid “table already defined” errors (use /
extend_existing/open_tablepatterns).if rows()==0
- 切勿硬编码凭证;使用环境变量()并记录所需变量。
.env - 优先使用和固定版本的依赖以保证可复现性。
python -m venv .venv - 编辑requirements.txt时,不要自定义pytidb版本,默认使用未固定版本,除非用户明确要求且该版本已验证存在。
- 保持示例简洁可运行;除非用户要求,否则避免依赖特定框架。
- 任何动态值都使用参数化SQL(防止SQL注入)。
- 在交互式环境中,避免“表已定义”错误(使用/
extend_existing/open_table等模式)。if rows()==0
Available Guides
可用指南
Each guide is a self-contained walkthrough with a checklist and phases:
- — one-file “connect → create table → insert → vector search”
guides/quickstart.md - — vector / full-text / hybrid: when to use which, plus gotchas
guides/search.md - — examples playbook (vector/hybrid/image)
guides/demos.md - — agent-ish examples (RAG / memory / text2sql)
guides/agent-apps.md - — connection, TLS, embedding, and index/search issues
guides/troubleshooting.md - — implement a custom embedding function (example: BGE-M3)
guides/custom-embedding.md
I’ll infer your intent (CRUD vs search vs “agent app”), then point you to the smallest guide and template set that gets you running.
每个指南都是包含检查清单和阶段的独立教程:
- — 单文件指南:连接→创建表→插入→向量搜索
guides/quickstart.md - — 向量/全文/混合搜索:适用场景与注意事项
guides/search.md - — 示例手册(向量/混合/图像)
guides/demos.md - — 面向Agent的示例(RAG/记忆/Text2SQL)
guides/agent-apps.md - — 连接、TLS、嵌入与索引/搜索问题排查
guides/troubleshooting.md - — 实现自定义嵌入函数(示例:BGE-M3)
guides/custom-embedding.md
我会推断你的需求(CRUD操作 vs 搜索 vs “Agent应用”),然后为你推荐最适合的最简指南与模板集。
Templates & Scripts
模板与脚本
Each template is a complete file you can copy into your project. Choose the smallest one that matches your goal.
每个模板都是可直接复制到项目中的完整文件。选择与你的目标最匹配的最小模板。
Core usage
核心用法
- — minimal end-to-end: connect → create table → insert → vector search
templates/quickstart.py - — basic table modeling + CRUD lifecycle (create/truncate/insert/query/update/delete)
templates/crud.py - — auto embedding with pluggable providers (env-driven)
templates/auto_embedding.py - — vector search example (optional metadata filter + threshold)
templates/vector_search.py - — hybrid search example (FullTextField + vector field) with fused scoring
templates/hybrid_search.py
- — 极简端到端示例:连接→创建表→插入→向量搜索
templates/quickstart.py - — 基础表建模+CRUD生命周期(创建/清空/插入/查询/更新/删除)
templates/crud.py - — 支持可插拔提供商的自动嵌入(由环境变量驱动)
templates/auto_embedding.py - — 向量搜索示例(可选元数据过滤+阈值)
templates/vector_search.py - — 混合搜索示例(FullTextField+向量字段),融合评分
templates/hybrid_search.py
Image search
图像搜索
- — image-to-image or text-to-image search (requires multimodal embedding + Pillow)
templates/image_search.py - — loads Oxford Pets dataset into TiDB (used by
templates/image_search_data_loader.py)image_search.py
- — 图搜图或文搜图(需要多模态嵌入+Pillow)
templates/image_search.py - — 将Oxford Pets数据集加载到TiDB(供
templates/image_search_data_loader.py使用)image_search.py
Custom embeddings
自定义嵌入
- — example
templates/custom_embedding_function.pyimplementation (BGE-M3 via FlagEmbedding)BaseEmbeddingFunction - — uses the custom embedder with auto embedding + vector search
templates/custom_embedding.py
- —
templates/custom_embedding_function.py实现示例(通过FlagEmbedding的BGE-M3)BaseEmbeddingFunction - — 将自定义嵌入器与自动嵌入+向量搜索结合使用
templates/custom_embedding.py
Agent-ish examples
面向Agent的示例
- — minimal RAG: retrieve via vector search, then generate via local LLM (Ollama via LiteLLM)
templates/rag.py - — reusable “memory” library (extract facts → store → retrieve)
templates/memory_lib.py - — CLI memory chat example using
templates/memory.pymemory_lib.py - — interactive Text2SQL (generates SQL via OpenAI; asks before executing)
templates/text2sql.py
- — 极简RAG:通过向量搜索检索,再通过本地LLM生成(Ollama via LiteLLM)
templates/rag.py - — 可复用的“记忆”库(提取事实→存储→检索)
templates/memory_lib.py - — 使用
templates/memory.py的CLI记忆聊天示例memory_lib.py - — 交互式Text2SQL(通过OpenAI生成SQL;执行前会确认)
templates/text2sql.py
Scripts
脚本
- — quick connection +
scripts/validate_connection.pysmoke test (supports params orSELECT 1)DATABASE_URL
- — 快速连接+
scripts/validate_connection.py冒烟测试(支持参数或SELECT 1)DATABASE_URL
Related Skills
相关Skill
- — provision/manage TiDB Cloud (TiDB X) clusters
tidbx
- — 部署/管理TiDB Cloud(TiDB X)集群
tidbx
Workflow
工作流程
I will:
- Confirm your TiDB deployment (Cloud Starter vs self-managed) and how you want to connect (params vs ).
DATABASE_URL - Help you set env vars, validate the connection, and choose the right path:
- CRUD/table modeling
- vector/full-text/hybrid search (and embedding provider)
- example templates
- Generate the minimal set of files and commands to get you running.
我会:
- 确认你的TiDB部署类型(Cloud Starter vs 自托管)以及连接方式(参数 vs )。
DATABASE_URL - 帮助你设置环境变量、验证连接,并选择合适的路径:
- CRUD/表建模
- 向量/全文/混合搜索(以及嵌入提供商)
- 示例模板
- 生成让你快速上手的最小文件集与命令。