{"id":35752,"date":"2026-12-01T09:31:35","date_gmt":"2026-12-01T17:31:35","guid":{"rendered":"https:\/\/www.pingcap.com\/?p=35752"},"modified":"2026-12-01T09:31:36","modified_gmt":"2026-12-01T17:31:36","slug":"context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it","status":"publish","type":"post","link":"https:\/\/www.pingcap.com\/ko\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/","title":{"rendered":"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It"},"content":{"rendered":"<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Key_Takeaways\"><\/span><strong>\ud575\uc2ec \uc694\uc57d<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Context compaction keeps an agent running when its window fills, but anything the summary leaves out drops out of the model\u2019s active context unless another memory source holds it.<\/li>\n\n\n\n<li>In the demo\u2019s memory.md setup, the model decides what goes into the notes file, so a fact it never wrote down can\u2019t be recovered from that file.<\/li>\n\n\n\n<li>Saving every turn as a row in TiDB let the demo agent recover the lost launch date by pulling back 440 tokens instead of re-reading about 7,552.<\/li>\n\n\n\n<li>Keyword and vector recall on the same table catch exact details like dates and questions phrased a new way.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Tell an AI agent your product ships on October 12, give it a few long tasks, then ask when you ship. There\u2019s a good chance it no longer knows. Nothing broke when the date disappeared. It was summarized away.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s context compaction. Context compaction is what an agent does when its context window fills: it writes a short summary of older turns, keeps the most recent exchange, and drops the rest from the active context to make room. It keeps the conversation going, and it quietly decides which facts the model can still see.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A small open-source demo, <a href=\"https:\/\/github.com\/pingcap\/tidb-agent-memory-demo\">tidb-agent-memory-demo on GitHub<\/a>, makes this visible. It runs the same chat twice in your terminal, once with a typical memory setup and once with every turn stored in a <a href=\"https:\/\/www.pingcap.com\/ko\/what-is-tidb\/\">\ud2f0DB<\/a> table. This post walks through both runs, what the numbers show, and how to run it yourself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_Context_Compaction\"><\/span><strong>What Is Context Compaction?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Context compaction is the step an LLM-based agent takes when its conversation history no longer fits in the model\u2019s context window. The agent condenses older turns into a summary and drops the originals from the active context so there\u2019s room for new input. Without it, a long session would simply stop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The cost is what the summary leaves out. Summaries are written for the gist, so specific details (a date, an account number, a threshold someone mentioned once) can get left out. Once the originals leave the context, the model can\u2019t tell what it lost unless it has another memory or history source to check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A common safeguard is to pair compaction with a notes file the agent can write to. That\u2019s the setup the demo tests first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_an_Agent_Forgets_When_Its_Context_Window_Fills\"><\/span><strong>What an Agent Forgets When Its Context Window Fills<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the first run (<strong>python demo.py forget<\/strong>), the agent loses a launch date it was told directly, and neither its summary nor its notes file can bring it back. Here\u2019s how that happens.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>The Setup: A Small Window and a Notes File<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The agent gets a deliberately small context window, 6,000 tokens, so compaction happens within a few messages instead of a few hours. Alongside it sits memory.md, a notes file where the agent writes down whatever it judges important.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The user, Maya, opens with her name and birthday (March 14). Next she says she\u2019s a product manager prepping the Atlas launch, which ships on October 12. Then come two heavy requests: summarize a 30-page vendor report, and plan a three-day team offsite. Those replies are saved in full, about 3,890 and 3,190 tokens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The chat is scripted, so every run is identical and you don\u2019t need an LLM or an API key. The replies, the notes, the point where compaction happens, and the summary are all fixed, and the agent\u2019s closing lines are templates. The long replies are saved in full in TiDB but shortened in the terminal output to keep it readable. The TiDB part is real: each message is inserted, TiDB embeds it on insert, and recall runs real vector and full-text queries against the table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What Compaction Dropped<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After the offsite reply, the chat has used 7,544 tokens of a 6,000-token window, so the agent compacts. It writes a short summary (\u201cI prepped the Atlas launch; summarized the vendor report; planned the 3-day offsite.\u201d), keeps the latest exchange word for word, and drops every older message from its context, including the one with the date.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The summary records the Atlas launch as a task. It doesn\u2019t record the date.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why the Notes File Didn\u2019t Save It<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The notes file survived compaction because it lives outside the context window. It holds a heading, Maya\u2019s birthday, and her job title. The agent never wrote down the launch date, so neither the summary nor the notes file has it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s the core limit of model-curated memory like memory.md: the agent decides what\u2019s worth saving when it first hears something, before it knows what will matter later. When Maya asks, \u201cRemind me, when do we ship Atlas?\u201d, the agent checks its summary and notes, finds no date, and asks her for it again. A full transcript would still contain the date, but reading it back means pulling about 7,552 tokens into context for one question, if a transcript was kept at all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_a_TiDB_Memory_Table_Changes_the_Outcome\"><\/span><strong>How a TiDB Memory Table Changes the Outcome<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The second run (<strong>python demo.py remember<\/strong>) keeps everything else the same: the same 6,000-token window, the same messages, and the same compaction. The agent\u2019s context loses exactly what it lost in the first run. The difference is that every message also lives outside the context, in a table the agent can search.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Every Turn Becomes a Row<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Saving a turn is a plain INSERT of the text into a TiDB table called agent_memory, and TiDB generates the embedding as part of the insert. There\u2019s no judgment call: the agent doesn\u2019t decide what to keep, so it can\u2019t forget to keep something. Each row also records a rough token count, which the demo uses to show how much context each recall pulls back. The long replies are saved in full and only shortened in the terminal output, so the eight rows total about 7,544 tokens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same rows serve every kind of access the agent needs. SQL reads them as a session log, vector search matches them by meaning, and a BM25 full-text index matches them by exact words. That one table covers the jobs a typical build splits across a database, a cache, a vector store, and a search index.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How the Agent Recovered the Launch Date<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When Maya asks the same question, the message with the date is gone from the context window, just as in the first run. This time the agent searches agent_memory. The demo runs two queries against the same rows, one by meaning and one by keyword, and merges the results with reciprocal rank fusion (RRF). Maya\u2019s original message ranks first in both lists.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The top three rows total 440 tokens, including the full launch plan reply, and the agent answers October 12, quoting the stored sentence.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then <strong>python demo.py recall<\/strong> starts a brand-new process with no conversation, no summary, and no notes. It returns the same rows, the same answer, and the same token ratio, because the memory lives in the table rather than the session.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What the Table Looks Like<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the demo\u2019s schema, from schema.sql in the repo. The embedding column is generated inside the database from content, so every row is searchable by meaning as soon as it\u2019s inserted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before you run it: full-text search and auto embedding currently require TiDB Cloud Starter on AWS in a supported region: Oregon (us-west-2), N. Virginia (us-east-1), Tokyo (ap-northeast-1), Frankfurt (eu-central-1), or Singapore (ap-southeast-1). Check the <a href=\"https:\/\/docs.pingcap.com\/ai\/vector-search-full-text-search-sql\/\">current list of regions<\/a> before you start. Vector search on TiDB Cloud is also currently available on Starter. To skip signup, <strong>python demo.py zero<\/strong> creates a disposable TiDB Cloud Zero database that expires after 30 days.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>sql<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE IF NOT EXISTS agent_memory (<br>&nbsp; id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BIGINT PRIMARY KEY AUTO_RANDOM,<br>&nbsp; user_id &nbsp; &nbsp; VARCHAR(64)&nbsp; NOT NULL,<br>&nbsp; session_id&nbsp; VARCHAR(64)&nbsp; NOT NULL,<br>&nbsp; speaker &nbsp; &nbsp; VARCHAR(16)&nbsp; NOT NULL,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- 'user' or 'agent'<br>&nbsp; content &nbsp; &nbsp; TEXT &nbsp; &nbsp; &nbsp; &nbsp; NOT NULL,<br>&nbsp; tokens&nbsp; &nbsp; &nbsp; INT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOT NULL,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- rough estimate: characters \/ 4<br>&nbsp; created_at&nbsp; TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),<br>&nbsp; embedding &nbsp; VECTOR(1024) GENERATED ALWAYS AS (<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EMBED_TEXT('tidbcloud_free\/amazon\/titan-embed-text-v2', content)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) STORED,<br>&nbsp; KEY idx_scope (user_id, session_id),<br>&nbsp; VECTOR INDEX idx_embedding ((VEC_COSINE_DISTANCE(embedding))),<br>&nbsp; FULLTEXT INDEX idx_content (content) WITH PARSER MULTILINGUAL<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Recall runs these two queries and fuses the results:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>sql<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- By meaning: TiDB embeds the question text itself<br>SELECT id, content,<br>&nbsp; &nbsp; &nbsp; VEC_EMBED_COSINE_DISTANCE(embedding, 'Remind me, when do we ship Atlas?') AS distance<br>FROM agent_memory<br>WHERE user_id = 'maya' AND session_id = 'blog-demo'<br>ORDER BY distance<br>LIMIT 10;<br><br>-- By keyword (BM25)<br>SELECT id, content<br>FROM agent_memory<br>WHERE user_id = 'maya' AND session_id = 'blog-demo'<br>&nbsp; AND fts_match_word('Remind me, when do we ship Atlas?', content)<br>ORDER BY fts_match_word('Remind me, when do we ship Atlas?', content) DESC<br>LIMIT 10;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Keyword recall matches \u201cAtlas\u201d exactly. <a href=\"https:\/\/www.pingcap.com\/ko\/ai\/vector-search\/\">Vector search<\/a> catches the same fact when the question is phrased differently. Because the user and session filter sits in the same query as the vector ordering, TiDB computes exact distances over just that user\u2019s rows instead of using the vector index. That\u2019s correct and fast for one user\u2019s memory. When a filter keeps a large share of a big table, <a href=\"https:\/\/docs.pingcap.com\/ai\/vector-search-index\/#use-the-vector-index-with-filters\">use the vector index with filters<\/a>: fetch the nearest rows first, then filter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a fuller build, see our guide to <a href=\"https:\/\/www.pingcap.com\/ko\/blog\/agent-memory-database-tidb\/\">building an agent memory database on TiDB<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_the_Demo_Shows\"><\/span><strong>What the Demo Shows<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The demo compares the two setups on four points. Both token figures come from the tokens column of the saved rows. The other two rows describe how the setups differ.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Measure<\/strong><\/td><td><strong>Result with one TiDB table<\/strong><\/td><td><strong>Compared with<\/strong><\/td><\/tr><tr><td>Systems to run for agent memory<\/td><td>One TiDB table<\/td><td>Four in a typical build: a database, a cache, a vector store, and a search index<\/td><\/tr><tr><td>Tokens to answer a recall question<\/td><td>440 recalled tokens<\/td><td>About 7,552 tokens, the eight saved rows plus the question, which the agent would have to re-read<\/td><\/tr><tr><td>Token reduction per answer<\/td><td>About 94% fewer, roughly 17x<\/td><td>Re-reading the full transcript on every question<\/td><\/tr><tr><td>Facts lost to compaction<\/td><td>Zero<\/td><td>The Atlas launch date, kept by neither the summary nor the notes file<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Read these as an illustration of the mechanism, not a benchmark for your workload. They come from one scripted conversation. Both sides use the same rough estimate (characters divided by four) on the text saved in TiDB. The eight saved rows total 7,544 tokens, and the question adds 8, for 7,552. Recall returned three rows totaling 440 tokens, including the full launch plan reply, so the ratio is about 17x. The dollar difference for your agent depends on your model\u2019s pricing. The ratio also depends on which rows come back: here one of the three is the 402-token launch plan, and if a long reply like the vendor report ranked in the top results, recall could cost thousands of tokens.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_the_Four-Database_Build_Comes_From\"><\/span><strong>Where the Four-Database Build Comes From<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The usual way to give an agent memory is to assemble it from parts: a relational database for facts, a cache for recent turns, a vector store for search by meaning, and a search index for exact words. Each part is reasonable on its own. Together they create the memory wall, where every write has to reach several systems and every read has to stitch their answers back together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The costs show up as sync lag, glue code, and four sets of credentials, backups, and access rules to maintain. A fact written a second ago may not be searchable yet. A message a user asked you to delete may linger in one of the indexes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Apply_the_Pattern_to_Your_Own_Agent\"><\/span><strong>How to Apply the Pattern to Your Own Agent<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A searchable memory table is a pattern you build on TiDB rather than a built-in feature. These practices follow directly from what the demo shows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Log every turn automatically. Don\u2019t ask the model to decide what to remember, because it can\u2019t know what will matter later.<\/li>\n\n\n\n<li>Let compaction manage the context window, and keep the originals in the table. The summary serves working memory, and the rows serve recall.<\/li>\n\n\n\n<li>Recall with both keyword and vector search. Dates, IDs, and names need exact matches, and paraphrased questions need semantic ones. The demo merges the two with RRF, and the TiDB <a href=\"https:\/\/docs.pingcap.com\/ai\/vector-search-hybrid-search\/\">hybrid search docs<\/a> show other ways to combine them in code.<\/li>\n\n\n\n<li>Scope every recall query by user or tenant, so one person\u2019s memory never reaches another person\u2019s prompt.<\/li>\n\n\n\n<li>Handle retention in the database. A TiDB TTL setting on created_at can expire old rows automatically. Deduplication and pruning still run as SQL jobs on whatever scheduler your app already uses.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Give_Your_Agent_a_Memory_It_Can_Search\"><\/span><strong>Give Your Agent a Memory It Can Search<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Context compaction will keep dropping details from context, because a summary can\u2019t hold everything. When every original turn sits in a searchable table, a dropped detail is one query away instead of gone, and recalling it costs hundreds of tokens instead of thousands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To see it yourself, clone <a href=\"https:\/\/github.com\/pingcap\/tidb-agent-memory-demo\">tidb-agent-memory-demo on GitHub<\/a>. After installing the requirements and connecting a database, the whole demo is five commands:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>bash<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python demo.py setup&nbsp; &nbsp; &nbsp; # creates the table (safe to re-run)<br>python demo.py forget &nbsp; &nbsp; # run 1: compaction loses the date<br>python demo.py remember &nbsp; # run 2: TiDB recalls it<br>python demo.py recall &nbsp; &nbsp; # new process, empty context: still recalled<br>python demo.py reset&nbsp; &nbsp; &nbsp; # delete this demo's rows<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To see which saved messages come back for a different question, pass your own, for example <strong>python demo.py recall &#8220;What date is Atlas shipping?&#8221;<\/strong>. TiDB runs the same hybrid search and prints how many tokens it read back. Only the default question gets a scripted answer line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To build this for your own agents, see how TiDB supports <a href=\"https:\/\/www.pingcap.com\/ko\/solutions\/ai-agent-context\/\">persistent context for AI agents<\/a>, with per-agent isolation and memory you can query in SQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Context_Compaction_and_Agent_Memory_FAQs\"><\/span><strong>Context Compaction and Agent Memory FAQs<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What Is Context Compaction?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The step an agent takes when its conversation no longer fits in the model\u2019s context window.<\/li>\n\n\n\n<li>It summarizes older turns, keeps the latest exchange, and drops the originals from the active context.<\/li>\n\n\n\n<li>It keeps long sessions running, but details the summary omits are no longer visible to the model.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why Do AI Agents Forget What Users Told Them?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compaction replaces original messages in the context with a summary that can miss specifics.<\/li>\n\n\n\n<li>Model-curated notes files hold only what the model chose to write down.<\/li>\n\n\n\n<li>New sessions start with an empty context window unless memory lives outside the model.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Is a memory.md Notes File Enough for Agent Memory?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It survives compaction because it lives outside the context window.<\/li>\n\n\n\n<li>It holds only facts the model flagged as important when it first heard them.<\/li>\n\n\n\n<li>In the demo, the launch date was never written down, so the notes file couldn\u2019t recover it.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How Is Agent Memory Different From RAG?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAG is a retrieval pattern: find relevant data and add it to the prompt.<\/li>\n\n\n\n<li>The source is often a document collection, but it doesn\u2019t have to be.<\/li>\n\n\n\n<li>Agent memory is the data saved from the agent\u2019s past conversations and actions.<\/li>\n\n\n\n<li>Agent memory can use the same retrieval pattern to bring the right turns back when needed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Do You Need a Separate Vector Database for Agent Memory?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Not necessarily. TiDB can store the text, embedding, and metadata for each turn in one table.<\/li>\n\n\n\n<li>Vector search, full-text search, and SQL filters run against the same rows.<\/li>\n\n\n\n<li>One system means one set of backups, access rules, and consistency guarantees.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Key Takeaways Tell an AI agent your product ships on October 12, give it a few long tasks, then ask when you ship. There\u2019s a good chance it no longer knows. Nothing broke when the date disappeared. It was summarized away. That\u2019s context compaction. Context compaction is what an agent does when its context window [&hellip;]<\/p>\n","protected":false},"author":344,"featured_media":35753,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-35752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-engineering"],"acf":[],"featured_image_src":"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png","author_info":{"display_name":"Ravish Patel","author_link":"https:\/\/www.pingcap.com\/ko\/blog\/author\/ravish-patel\/"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It | TiDB<\/title>\n<meta name=\"description\" content=\"Learn about the benefits of TiDB and the TiDB Cloud solutions from PingCAP. Read our latest post &quot;Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It&quot; here.\" \/>\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\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It | TiDB\" \/>\n<meta property=\"og:description\" content=\"Learn about the benefits of TiDB and the TiDB Cloud solutions from PingCAP. Read our latest post &quot;Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It&quot; here.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pingcap.com\/ko\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/\" \/>\n<meta property=\"og:site_name\" content=\"TiDB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/pingcap2015\" \/>\n<meta property=\"article:published_time\" content=\"2026-12-01T17:31:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-12-01T17:31:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ravish Patel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@PingCAP\" \/>\n<meta name=\"twitter:site\" content=\"@PingCAP\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ravish Patel\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"13\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/\"},\"author\":{\"name\":\"Ravish Patel\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#\\\/schema\\\/person\\\/d407dc40263c196dacd419baa2ea38a1\"},\"headline\":\"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It\",\"datePublished\":\"2026-12-01T17:31:35+00:00\",\"dateModified\":\"2026-12-01T17:31:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/\"},\"wordCount\":2360,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2026\\\/12\\\/01091345\\\/Copy-of-Blog-Feature.png\",\"articleSection\":[\"Engineering\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/\",\"url\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/\",\"name\":\"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It | TiDB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2026\\\/12\\\/01091345\\\/Copy-of-Blog-Feature.png\",\"datePublished\":\"2026-12-01T17:31:35+00:00\",\"dateModified\":\"2026-12-01T17:31:36+00:00\",\"description\":\"Learn about the benefits of TiDB and the TiDB Cloud solutions from PingCAP. Read our latest post \\\"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It\\\" here.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#primaryimage\",\"url\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2026\\\/12\\\/01091345\\\/Copy-of-Blog-Feature.png\",\"contentUrl\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2026\\\/12\\\/01091345\\\/Copy-of-Blog-Feature.png\",\"width\":1800,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/blog\\\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pingcap.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It\"}]},{\"@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\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pingcap.com\\\/#\\\/schema\\\/person\\\/d407dc40263c196dacd419baa2ea38a1\",\"name\":\"Ravish Patel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2022\\\/10\\\/17234942\\\/avatar.jpg\",\"url\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2022\\\/10\\\/17234942\\\/avatar.jpg\",\"contentUrl\":\"https:\\\/\\\/static.pingcap.com\\\/files\\\/2022\\\/10\\\/17234942\\\/avatar.jpg\",\"caption\":\"Ravish Patel\"},\"url\":\"https:\\\/\\\/www.pingcap.com\\\/ko\\\/blog\\\/author\\\/ravish-patel\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It | TiDB","description":"Learn about the benefits of TiDB and the TiDB Cloud solutions from PingCAP. Read our latest post \"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It\" here.","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\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/","og_locale":"ko_KR","og_type":"article","og_title":"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It | TiDB","og_description":"Learn about the benefits of TiDB and the TiDB Cloud solutions from PingCAP. Read our latest post \"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It\" here.","og_url":"https:\/\/www.pingcap.com\/ko\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/","og_site_name":"TiDB","article_publisher":"https:\/\/facebook.com\/pingcap2015","article_published_time":"2026-12-01T17:31:35+00:00","article_modified_time":"2026-12-01T17:31:36+00:00","og_image":[{"width":1800,"height":600,"url":"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png","type":"image\/png"}],"author":"Ravish Patel","twitter_card":"summary_large_image","twitter_creator":"@PingCAP","twitter_site":"@PingCAP","twitter_misc":{"\uae00\uc4f4\uc774":"Ravish Patel","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"13\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#article","isPartOf":{"@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/"},"author":{"name":"Ravish Patel","@id":"https:\/\/www.pingcap.com\/#\/schema\/person\/d407dc40263c196dacd419baa2ea38a1"},"headline":"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It","datePublished":"2026-12-01T17:31:35+00:00","dateModified":"2026-12-01T17:31:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/"},"wordCount":2360,"publisher":{"@id":"https:\/\/www.pingcap.com\/#organization"},"image":{"@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#primaryimage"},"thumbnailUrl":"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png","articleSection":["Engineering"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/","url":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/","name":"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It | TiDB","isPartOf":{"@id":"https:\/\/www.pingcap.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#primaryimage"},"image":{"@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#primaryimage"},"thumbnailUrl":"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png","datePublished":"2026-12-01T17:31:35+00:00","dateModified":"2026-12-01T17:31:36+00:00","description":"Learn about the benefits of TiDB and the TiDB Cloud solutions from PingCAP. Read our latest post \"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It\" here.","breadcrumb":{"@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/"]}]},{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#primaryimage","url":"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png","contentUrl":"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png","width":1800,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/www.pingcap.com\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pingcap.com\/"},{"@type":"ListItem","position":2,"name":"Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It"}]},{"@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"]},{"@type":"Person","@id":"https:\/\/www.pingcap.com\/#\/schema\/person\/d407dc40263c196dacd419baa2ea38a1","name":"Ravish Patel","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg","url":"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg","contentUrl":"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg","caption":"Ravish Patel"},"url":"https:\/\/www.pingcap.com\/ko\/blog\/author\/ravish-patel\/"}]}},"grav_blocks":false,"card_markup":"<a class=\"card-resource bg-white\" href=\"https:\/\/www.pingcap.com\/ko\/blog\/context-compaction-why-ai-agents-forget-and-how-a-memory-table-fixes-it\/\"><div class=\"card-resource__image-container\"><img class=\"card-resource__image\" alt=\"Copy of Blog - Feature\" src=\"https:\/\/static.pingcap.com\/files\/2026\/12\/01091345\/Copy-of-Blog-Feature.png\" loading=\"lazy\" width=\"1800\" height=\"600\" \/><\/div><div class=\"card-resource__content-container\"><div class=\"card-resource__content-head\"><div class=\"card-resource__category\">Engineering<\/div><\/div><h5 class=\"card-resource__title\">Context Compaction: Why AI Agents Forget and How a Memory Table Fixes It<\/h5><\/div><\/a>","_links":{"self":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts\/35752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/users\/344"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/comments?post=35752"}],"version-history":[{"count":3,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts\/35752\/revisions"}],"predecessor-version":[{"id":35756,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts\/35752\/revisions\/35756"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/media\/35753"}],"wp:attachment":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/media?parent=35752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/categories?post=35752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/tags?post=35752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}