{"id":17896,"date":"2026-10-02T13:18:29","date_gmt":"2026-10-02T20:18:29","guid":{"rendered":"https:\/\/www.pingcap.com\/?post_type=article&#038;p=17896"},"modified":"2026-10-02T13:35:02","modified_gmt":"2026-10-02T20:35:02","slug":"unleashing-the-power-of-mysql-with-vector-columns-in-tidb","status":"publish","type":"article","link":"https:\/\/www.pingcap.com\/ko\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/","title":{"rendered":"How to Add Vector Search to a MySQL Application with TiDB"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Adding vector search to an application that runs on MySQL usually means standing up a separate vector database next to it, then keeping the two in sync for one new feature. <a href=\"https:\/\/www.pingcap.com\/what-is-tidb\/\">TiDB<\/a> offers a simpler path. It&#8217;s a MySQL-compatible distributed SQL database with a native VECTOR data type and HNSW index. Move your MySQL workload to TiDB and your embeddings live in the same tables as your relational data, queried with the same SQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_a_Vector_Column_in_TiDB\"><\/span>What Is a Vector Column in TiDB?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A vector column in TiDB is a table column declared with the VECTOR data type and a fixed dimension, stored in the same table as your other relational columns. Set the dimension to match your embedding model&#8217;s output size so TiDB can validate inserts and build an index on the column. A 1536-dimension column, the size produced by several common embedding models, looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE documents (\n    id INT PRIMARY KEY,\n    content TEXT,\n    embedding VECTOR(1536)\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There is no separate vector table type and no separate vector database to run. The vector column sits in a regular TiDB table alongside your other columns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Not_Use_a_Separate_Vector_Database\"><\/span>Why Not Use a Separate Vector Database?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Running a dedicated vector database alongside MySQL means two systems to operate, two consistency models, and a sync job to keep them aligned. With TiDB, vectors are a data type in the same database as your relational data. You get vector support through SQL functions and a vector index, and you query it with the same drivers and connection you already use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">TiDB is MySQL-compatible, which matters here because your existing drivers, ORMs, and most of your application queries work against it with few or no changes. Moving to TiDB is still a migration, so plan for it the way you would any database move. Once you&#8217;re on TiDB, adding vector search is a schema change rather than a new service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.pingcap.com\/case-study\/dify-consolidates-massive-database-containers-into-one-unified-system-with-tidb\/\">Dify<\/a>, the open-source LLM app development platform, took this approach in production. Its team consolidated nearly half a million database containers into a single TiDB Cloud deployment that stores documents, vectors, chat histories, and relational data together, queried through SQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_Vector_Column_and_Index_in_TiDB\"><\/span>Creating a Vector Column and Index in TiDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Vector indexes in TiDB use HNSW and are built on TiFlash replicas. If you define the index when you create the table, TiDB creates the TiFlash replica for you:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE documents_indexed (\n    id INT PRIMARY KEY,\n    content TEXT,\n    embedding VECTOR(1536),\n    VECTOR INDEX idx_embedding ((VEC_COSINE_DISTANCE(embedding)))\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To add vector search to a table you already have, add the column, create a TiFlash replica, then add the index:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE documents ADD COLUMN embedding VECTOR(1536);\nALTER TABLE documents SET TIFLASH REPLICA 1;\nALTER TABLE documents ADD VECTOR INDEX idx_embedding ((VEC_COSINE_DISTANCE(embedding))) USING HNSW;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On TiDB Self-Managed, the cluster needs TiFlash nodes deployed before you can build a vector index.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Query for the nearest neighbors with <code>ORDER BY<\/code> on the distance function and a <code>LIMIT<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT id, content, VEC_COSINE_DISTANCE(embedding, '&#91;0.01, 0.02, 0.03, ...]') AS distance\nFROM documents_indexed\nORDER BY distance\nLIMIT 5;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The index is only used for this pattern: ascending order on the same distance function the index was built with, plus a <code>LIMIT<\/code>. Ordering by a different distance function, or descending, falls back to a full scan. Filters in the same <code>WHERE<\/code> clause can also stop the index from being used. The <a href=\"https:\/\/docs.pingcap.com\/ai\/vector-search-index\/\">vector search index docs<\/a> cover how to combine filters with indexed search and how to check index usage with <code>EXPLAIN<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQ\"><\/span>FAQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Can I add a vector column to an existing table in TiDB?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Add it with <code>ALTER TABLE<\/code> the same way you would add any other column.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Existing rows keep their data, and the new column is <code>NULL<\/code> until you populate it<\/li>\n\n\n\n<li>To index it, create a TiFlash replica on the table first, then add the vector index<\/li>\n\n\n\n<li>If your data is still in MySQL, migrate it to TiDB first. MySQL itself has no equivalent of TiDB&#8217;s VECTOR type and HNSW index<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Does a vector column slow down my regular SQL queries?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Queries that don&#8217;t touch the vector column don&#8217;t use it, but the table does get larger.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Each 1536-dimension vector adds several kilobytes per row, so plan for storage growth<\/li>\n\n\n\n<li>The vector index lives on TiFlash, so it doesn&#8217;t add to your row-store indexes<\/li>\n\n\n\n<li>Vector columns can&#8217;t be primary keys, unique indexes, or partition keys<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What indexing does TiDB use for vector columns?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">TiDB uses HNSW (Hierarchical Navigable Small World) for approximate nearest-neighbor search.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create the index inline in <code>CREATE TABLE<\/code>, or with <code>CREATE VECTOR INDEX<\/code> or <code>ALTER TABLE ... ADD VECTOR INDEX<\/code> on an existing table<\/li>\n\n\n\n<li>Vector columns support up to 16,383 dimensions<\/li>\n\n\n\n<li>Building vector indexes isn&#8217;t supported on TiFlash nodes with encryption at rest enabled<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Can I use TiDB&#8217;s vector columns with my existing AI framework?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. TiDB has integrations for LangChain, LlamaIndex, SQLAlchemy, Django ORM, and peewee.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Any MySQL-compatible driver can read and write vector columns<\/li>\n\n\n\n<li>Vectors are passed as strings like <code>'[0.1, 0.2, 0.3]'<\/code>, so no special client protocol is needed<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_Vector_Search_Without_a_Second_Database\"><\/span>Add Vector Search Without a Second Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A vector column and an HNSW index put vector search in the same TiDB database as your relational data, so you don&#8217;t run and sync a separate vector store. <a href=\"https:\/\/tidbcloud.com\/free-trial\/\">Sign up for TiDB Cloud Starter<\/a> and add a vector column to your own table.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding vector search to an application that runs on MySQL usually means standing up a separate vector database next to it, then keeping the two in sync for one new feature. TiDB offers a simpler path. It&#8217;s a MySQL-compatible distributed SQL database with a native VECTOR data type and HNSW index. Move your MySQL workload [&hellip;]<\/p>\n","protected":false},"author":305,"featured_media":0,"template":"","class_list":["post-17896","article","type-article","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Add Vector Columns to MySQL with TiDB<\/title>\n<meta name=\"description\" content=\"Delve into how you can enhance your MySQL database with vector columns using TiDB, unlocking new potentials for your applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pingcap.com\/ko\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Vector Columns to MySQL with TiDB\" \/>\n<meta property=\"og:description\" content=\"Delve into how you can enhance your MySQL database with vector columns using TiDB, unlocking new potentials for your applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pingcap.com\/ko\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/\" \/>\n<meta property=\"og:site_name\" content=\"TiDB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/pingcap2015\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-02T20:35:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.pingcap.com\/files\/2024\/09\/11005522\/Homepage-Ad.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1440\" \/>\n\t<meta property=\"og:image:height\" content=\"714\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@PingCAP\" \/>\n<meta name=\"twitter:label1\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data1\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/article\\\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\\\/\",\"url\":\"https:\\\/\\\/www.pingcap.com\\\/article\\\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\\\/\",\"name\":\"Add Vector Columns to MySQL with TiDB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#website\"},\"datePublished\":\"2026-10-02T20:18:29+00:00\",\"dateModified\":\"2026-10-02T20:35:02+00:00\",\"description\":\"Delve into how you can enhance your MySQL database with vector columns using TiDB, unlocking new potentials for your applications.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/article\\\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\\\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pingcap.com\\\/article\\\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/article\\\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pingcap.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\\\/\\\/www.pingcap.com\\\/article\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Add Vector Search to a MySQL Application with TiDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pingcap.com\\\/\",\"name\":\"TiDB\",\"description\":\"TiDB | SQL at Scale\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pingcap.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#organization\",\"name\":\"PingCAP\",\"url\":\"https:\\\/\\\/www.pingcap.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2021\\\/11\\\/pingcap-logo.png\",\"contentUrl\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2021\\\/11\\\/pingcap-logo.png\",\"width\":811,\"height\":232,\"caption\":\"PingCAP\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/facebook.com\\\/pingcap2015\",\"https:\\\/\\\/x.com\\\/PingCAP\",\"https:\\\/\\\/linkedin.com\\\/company\\\/pingcap\",\"https:\\\/\\\/youtube.com\\\/channel\\\/UCuq4puT32DzHKT5rU1IZpIA\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add Vector Columns to MySQL with TiDB","description":"Delve into how you can enhance your MySQL database with vector columns using TiDB, unlocking new potentials for your applications.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pingcap.com\/ko\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/","og_locale":"ko_KR","og_type":"article","og_title":"Add Vector Columns to MySQL with TiDB","og_description":"Delve into how you can enhance your MySQL database with vector columns using TiDB, unlocking new potentials for your applications.","og_url":"https:\/\/www.pingcap.com\/ko\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/","og_site_name":"TiDB","article_publisher":"https:\/\/facebook.com\/pingcap2015","article_modified_time":"2026-10-02T20:35:02+00:00","og_image":[{"width":1440,"height":714,"url":"https:\/\/static.pingcap.com\/files\/2024\/09\/11005522\/Homepage-Ad.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@PingCAP","twitter_misc":{"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pingcap.com\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/","url":"https:\/\/www.pingcap.com\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/","name":"Add Vector Columns to MySQL with TiDB","isPartOf":{"@id":"https:\/\/www.pingcap.com\/#website"},"datePublished":"2026-10-02T20:18:29+00:00","dateModified":"2026-10-02T20:35:02+00:00","description":"Delve into how you can enhance your MySQL database with vector columns using TiDB, unlocking new potentials for your applications.","breadcrumb":{"@id":"https:\/\/www.pingcap.com\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pingcap.com\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pingcap.com\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pingcap.com\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/www.pingcap.com\/article\/"},{"@type":"ListItem","position":3,"name":"How to Add Vector Search to a MySQL Application with TiDB"}]},{"@type":"WebSite","@id":"https:\/\/www.pingcap.com\/#website","url":"https:\/\/www.pingcap.com\/","name":"\ud2f0DB","description":"TiDB | SQL at Scale","publisher":{"@id":"https:\/\/www.pingcap.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pingcap.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/www.pingcap.com\/#organization","name":"PingCAP","url":"https:\/\/www.pingcap.com\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/","url":"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png","contentUrl":"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png","width":811,"height":232,"caption":"PingCAP"},"image":{"@id":"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/pingcap2015","https:\/\/x.com\/PingCAP","https:\/\/linkedin.com\/company\/pingcap","https:\/\/youtube.com\/channel\/UCuq4puT32DzHKT5rU1IZpIA"]}]}},"card_markup":"        <a class=\"card-article\" href=\"https:\/\/www.pingcap.com\/ko\/article\/unleashing-the-power-of-mysql-with-vector-columns-in-tidb\/\">            <h3>How to Add Vector Search to a MySQL Application with TiDB<\/h3>            <p>Adding vector search to an application that runs on MySQL usually means standing up a separate vector database next to it, then keeping the two in sync for one new feature. TiDB offers a simpler path. It&#8217;s a MySQL-compatible distributed SQL database with a native VECTOR data type and HNSW index. Move your MySQL workload [&hellip;]<\/p>        <\/a>","_links":{"self":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/article\/17896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/types\/article"}],"author":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/users\/305"}],"wp:attachment":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/media?parent=17896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}