{"id":117738,"date":"2026-10-25T08:48:55","date_gmt":"2026-10-25T00:48:55","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117738.html"},"modified":"2026-10-25T08:48:55","modified_gmt":"2026-10-25T00:48:55","slug":"%e5%9b%a0%e6%9e%9c%e5%8e%8b%e7%bc%a9%ef%bc%9a%e4%bb%8e-gzip-%e5%88%b0-transformer-kv-cache-%e5%88%b0%e8%ae%b0%e5%bf%86%e7%9a%84%e7%bb%9f%e4%b8%80%e8%a7%86%e8%a7%92","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117738.html","title":{"rendered":"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2"},"content":{"rendered":"<h2><\/h2>\n<p>\u4e00\u53e5\u8bdd\u7ed3\u8bba&#xff1a;\u538b\u7f29 &#061; \u56e0\u679c\u94fe\u5728\u87ba\u65cb\u5c55\u5f00\u4e2d&#xff0c;\u5c06\u5df2\u786e\u5b9a\u7684\u4f4e\u865a\u90e8\u5206\u652f\u6298\u53e0\u56de\u751f\u6210\u5143&#xff0c;\u7528\u66f4\u77ed\u7684\u7f16\u7801\u66ff\u4ee3\u5197\u4f59\u5c55\u5f00\u3002gzip \u7684 LZ77\u3001Transformer \u7684 KV Cache\u3001\u4eba\u8111\u7684\u8bb0\u5fc6\u3001\u6570\u636e\u5e93\u7684\u7d22\u5f15\u2014\u2014\u5168\u90fd\u662f\u540c\u4e00\u4ef6\u4e8b&#xff1a;\u7528 I\u00b2 &#061; -N \u628a\u9ad8\u7ef4\u56e0\u679c\u6d41\u538b\u7f29\u5230\u4f4e\u7ef4\u8868\u793a&#xff0c;\u4ee3\u4ef7\u662f\u4e22\u5931\u90e8\u5206\u53ef\u5c55\u5f00\u6027\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6280\u672f\u75db\u70b9&#xff1a;\u4e3a\u4ec0\u4e48\u4f60\u7684\u7cfb\u7edf\u603b\u5728&#034;\u91cd\u590d\u8ba1\u7b97&#034;\u548c&#034;\u4e22\u4e0a\u4e0b\u6587&#034;\u4e4b\u95f4\u4e24\u96be&#xff1f;<\/h3>\n<p>\u4f60\u4e00\u5b9a\u9047\u5230\u8fc7\u8fd9\u4e9b\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>Transformer \u63a8\u7406\u592a\u6162\/\u592a\u8d35&#xff1a;128K \u4e0a\u4e0b\u6587&#xff0c;\u6bcf\u751f\u6210\u4e00\u4e2a token \u90fd\u8981\u91cd\u65b0\u7b97\u6240\u6709\u5386\u53f2 token \u7684\u6ce8\u610f\u529b\u3002\u4f60\u52a0 KV Cache&#xff0c;\u663e\u5b58\u70b8\u4e86&#xff1b;\u4f60\u622a\u65ad\u4e0a\u4e0b\u6587&#xff0c;\u6a21\u578b&#034;\u5fd8&#034;\u4e86\u524d\u9762\u7684\u7ea6\u675f\u3002\u4e3a\u4ec0\u4e48&#xff1f;\u56e0\u4e3a\u4f60\u6ca1\u7406\u89e3 KV Cache \u7684\u672c\u8d28\u662f\u56e0\u679c\u94fe\u7684\u538b\u7f29\u5feb\u7167<\/li>\n<li>gzip \u538b\u7f29\u7387\u5230\u74f6\u9888&#xff1a;\u65e5\u5fd7\u6587\u4ef6 gzip \u540e\u8fd8\u662f\u5f88\u5927&#xff0c;\u56e0\u4e3a\u65e5\u5fd7\u6709&#034;\u7ed3\u6784&#034;\u4f46 gzip \u53ea\u770b\u5230\u5b57\u8282\u91cd\u590d\u3002\u4f60\u6362 zstd\u3001\u6362 snappy&#xff0c;\u63d0\u5347\u6709\u9650\u3002\u4e3a\u4ec0\u4e48&#xff1f;\u56e0\u4e3a\u4f60\u9700\u8981\u5728\u8bed\u4e49\u5c42\u7ea7\u538b\u7f29&#xff0c;\u4e0d\u662f\u5b57\u8282\u5c42\u7ea7<\/li>\n<li>\u6570\u636e\u5e93\u7d22\u5f15\u81a8\u80c0&#xff1a;\u7ed9\u6bcf\u4e2a\u67e5\u8be2\u7ef4\u5ea6\u5efa\u7d22\u5f15&#xff0c;\u5199\u5165\u53d8\u6162&#xff0c;\u5b58\u50a8\u7a7a\u95f4\u7ffb\u500d\u3002\u4f60\u4e0d\u5efa\u7d22\u5f15&#xff0c;\u67e5\u8be2\u5168\u8868\u626b\u63cf\u3002\u4e3a\u4ec0\u4e48&#xff1f;\u56e0\u4e3a\u7d22\u5f15\u548c\u538b\u7f29\u662f\u540c\u4e00\u679a\u786c\u5e01\u7684\u4e24\u9762\u2014\u2014\u90fd\u662f\u7528\u7a7a\u95f4\u6362\u56e0\u679c\u7684\u53ef\u68c0\u7d22\u6027<\/li>\n<li>\u4eba\u8111\u9057\u5fd8&#xff1a;\u4f60\u8bb0\u4e0d\u4f4f\u4e09\u4e2a\u6708\u524d\u67d0\u5929\u7684\u7ec6\u8282&#xff0c;\u4f46\u8bb0\u5f97\u90a3\u5468\u53d1\u751f\u4e86\u4ec0\u4e48&#034;\u5927\u4e8b&#034;\u3002\u8fd9\u4e0d\u662f bug&#xff0c;\u662f\u7279\u6027\u2014\u2014\u5927\u8111\u5728\u81ea\u52a8\u538b\u7f29\u56e0\u679c\u94fe&#xff0c;\u4e22\u5f03\u4f4e\u865a\u90e8\u5206\u652f<\/li>\n<li>\u7f13\u5b58 vs \u8ba1\u7b97&#xff1a;\u7f13\u5b58\u547d\u4e2d\u7387\u9ad8\u4f46\u5360\u5185\u5b58&#xff0c;\u547d\u4e2d\u7387\u4f4e\u5c31\u4e0d\u5982\u91cd\u7b97\u3002\u4f60\u600e\u4e48\u5b9a\u7f13\u5b58\u5927\u5c0f&#xff1f;\u4f60\u51ed\u7ecf\u9a8c\u8bbe 512MB\u30011GB\u2014\u2014\u4f46\u90a3\u4e2a\u6570\u5b57\u6ca1\u6709\u7406\u8bba\u4f9d\u636e<\/li>\n<li>RAG \u7684 chunk \u5207\u5206&#xff1a;\u5207\u5927\u4e86\u68c0\u7d22\u4e0d\u7cbe\u51c6&#xff0c;\u5207\u5c0f\u4e86\u4e22\u5931\u4e0a\u4e0b\u6587\u3002\u4f60\u8bd5 256\u3001512\u30011024 token\u2014\u2014\u4e3a\u4ec0\u4e48\u6ca1\u6709\u6700\u4f18\u89e3&#xff1f;\u56e0\u4e3a\u4f60\u5728\u9519\u8bef\u7684\u7ef4\u5ea6\u5207\u5206<\/li>\n<\/ul>\n<p>\u6839\u56e0&#xff1a;\u4f60\u6ca1\u610f\u8bc6\u5230\u538b\u7f29\u548c\u667a\u80fd\u662f\u540c\u4e00\u4ef6\u4e8b\u3002\u4e0d\u80fd\u538b\u7f29\u7684\u56e0\u679c\u94fe &#061; \u6ca1\u6709\u89c4\u5f8b &#061; \u4e0d\u53ef\u9884\u6d4b &#061; \u4e0d\u667a\u80fd\u3002\u80fd\u538b\u7f29 &#061; \u627e\u5230\u4e86\u751f\u6210\u5143 &#061; \u7406\u89e3\u4e86\u7ed3\u6784\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u4ece\u87ba\u65cb\u516c\u7406\u5230\u56e0\u679c\u538b\u7f29<\/h3>\n<h4>2.1 \u538b\u7f29\u7684\u87ba\u65cb\u5b9a\u4e49<\/h4>\n<p>\u56de\u987e I\u00b2 &#061; -N\u3002<\/p>\n<p>\u56e0\u679c\u94fe\u5c55\u5f00\u65f6&#xff0c;\u6bcf\u4e00\u6b65\u90fd\u4ea7\u751f\u65b0\u7684\u5206\u652f\u3002\u4f46\u5f88\u591a\u5206\u652f\u662f\u76f8\u4f3c\u7684\u2014\u2014\u5b83\u4eec\u5171\u4eab\u540c\u4e00\u4e2a\u751f\u6210\u5143&#xff0c;\u53ea\u662f\u521d\u59cb\u6761\u4ef6\u7565\u6709\u4e0d\u540c\u3002\u538b\u7f29 &#061; \u8bc6\u522b\u8fd9\u4e9b\u5171\u4eab\u751f\u6210\u5143&#xff0c;\u628a N \u4e2a\u76f8\u4f3c\u5206\u652f\u6298\u53e0\u56de 1 \u4e2a\u751f\u6210\u5143 &#043; N \u4e2a\u504f\u79fb\u91cf\u3002<\/p>\n<table>\n<tr>\n<p>\u6982\u5ff5<\/p>\n<p>\u4f20\u7edf\u89e3\u91ca<\/p>\n<p>\u87ba\u65cb\u89e3\u91ca<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u538b\u7f29<\/p>\n<\/td>\n<td>\n<p>\u51cf\u5c11\u6570\u636e\u5197\u4f59<\/p>\n<\/td>\n<td>\n<p>\u5c06\u56e0\u679c\u94fe\u4e2d\u865a\u90e8\u8d8b\u540c\u7684\u5206\u652f\u6298\u53e0\u56de\u751f\u6210\u5143<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u89e3\u538b<\/p>\n<\/td>\n<td>\n<p>\u6062\u590d\u539f\u59cb\u6570\u636e<\/p>\n<\/td>\n<td>\n<p>\u4ece\u751f\u6210\u5143\u91cd\u65b0\u5c55\u5f00\u56e0\u679c\u94fe<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u538b\u7f29\u7387<\/p>\n<\/td>\n<td>\n<p>\u539f\u59cb\u5927\u5c0f\/\u538b\u7f29\u540e\u5927\u5c0f<\/p>\n<\/td>\n<td>\n<p>N \/ (1 &#043; log_N(\u76f8\u4f3c\u5206\u652f\u6570))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>KV Cache<\/p>\n<\/td>\n<td>\n<p>\u7f13\u5b58\u6ce8\u610f\u529b\u8ba1\u7b97\u7ed3\u679c<\/p>\n<\/td>\n<td>\n<p>\u5df2\u574d\u7f29\u56e0\u679c\u7684\u538b\u7f29\u5feb\u7167<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u7d22\u5f15<\/p>\n<\/td>\n<td>\n<p>\u52a0\u901f\u67e5\u627e\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<\/td>\n<td>\n<p>\u56e0\u679c\u94fe\u7684\u5206\u5c42\u538b\u7f29<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8bb0\u5fc6<\/p>\n<\/td>\n<td>\n<p>\u5b58\u50a8\u8fc7\u53bb\u7ecf\u9a8c<\/p>\n<\/td>\n<td>\n<p>\u5df2\u5c55\u5f00\u56e0\u679c\u7684\u865a\u90e8\u5f52\u96f6&#xff08;\u786e\u5b9a\u6027\u5b58\u50a8&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u9057\u5fd8<\/p>\n<\/td>\n<td>\n<p>\u8bb0\u5fc6\u6d88\u9000<\/p>\n<\/td>\n<td>\n<p>\u865a\u90e8\u4fe1\u606f\u8870\u51cf\u5230\u9608\u503c\u4ee5\u4e0b&#xff0c;\u5206\u652f\u88ab\u6298\u53e0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u4fe1\u606f\u635f\u5931<\/p>\n<\/td>\n<td>\n<p>\u538b\u7f29\u5931\u771f<\/p>\n<\/td>\n<td>\n<p>\u6298\u53e0\u65f6\u4e22\u5f03\u7684\u865a\u90e8\u5206\u652f\u4e0d\u53ef\u6062\u590d<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6838\u5fc3\u516c\u5f0f&#xff1a;<\/p>\n<p>\u538b\u7f29\u7387 R &#061; N \/ C<\/p>\n<p>\u5176\u4e2d&#xff1a;<br \/>\nC &#061; 1 &#043; log_N(\u03a3 similarity(z_i, z_gen))  &#xff08;\u538b\u7f29\u540e\u7f16\u7801\u957f\u5ea6&#xff09;<br \/>\nN &#061; \u539f\u59cb\u56e0\u679c\u5206\u652f\u6570<br \/>\nsimilarity &#061; |z_i &#8211; z_gen| \/ |z_gen|  &#xff08;\u5206\u652f\u4e0e\u751f\u6210\u5143\u7684\u76f8\u4f3c\u5ea6&#xff09;<\/p>\n<p>\u538b\u7f29\u4ee3\u4ef7 &#061; \u4fe1\u606f\u635f\u5931 &#061; \u03a3 |Im(z_i)| for i in discarded_branches<\/p>\n<p>\u5f53 similarity \u2192 0&#xff08;\u6240\u6709\u5206\u652f\u51e0\u4e4e\u76f8\u540c&#xff09;&#xff1a;C \u2192 1&#xff0c;R \u2192 N&#xff0c;\u5b8c\u7f8e\u538b\u7f29<\/p>\n<p>\u5f53 similarity \u2192 1&#xff08;\u5206\u652f\u5b8c\u5168\u4e0d\u540c&#xff09;&#xff1a;C \u2192 N&#xff0c;R \u2192 1&#xff0c;\u65e0\u6cd5\u538b\u7f29<\/p>\n<h4>2.2 \u87ba\u65cb\u538b\u7f29\u6a21\u578b<\/h4>\n<p>import math<br \/>\nimport random<br \/>\nfrom dataclasses import dataclass, field<br \/>\nfrom typing import List, Dict, Tuple, Optional<br \/>\nimport zlib<br \/>\nimport time as time_module<\/p>\n<p>&#064;dataclass<br \/>\nclass CausalBranch:<br \/>\n    &#034;&#034;&#034;\u56e0\u679c\u5206\u652f&#034;&#034;&#034;<br \/>\n    branch_id: str<br \/>\n    value: complex<br \/>\n    parent_id: Optional[str] &#061; None<br \/>\n    generation: int &#061; 0<br \/>\n    collapsed: bool &#061; False<br \/>\n    imag_part: float &#061; 0.0<\/p>\n<p>    &#064;property<br \/>\n    def magnitude(self) -&gt; float:<br \/>\n        return abs(self.value)<\/p>\n<p>    &#064;property<br \/>\n    def phase(self) -&gt; float:<br \/>\n        return math.atan2(self.value.imag, self.value.real)<\/p>\n<p>class SpiralCompressor:<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u87ba\u65cb\u56e0\u679c\u538b\u7f29\u5668<\/p>\n<p>    \u5c06\u56e0\u679c\u94fe\u4e2d\u76f8\u4f3c\u7684\u5206\u652f\u538b\u7f29\u4e3a\u751f\u6210\u5143 &#043; \u504f\u79fb\u91cf<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    def __init__(self, N: float &#061; 4.0, similarity_threshold: float &#061; 0.15):<br \/>\n        self.N &#061; N<br \/>\n        self.scale &#061; math.sqrt(N)<br \/>\n        self.similarity_threshold &#061; similarity_threshold<br \/>\n        self.branches: Dict[str, CausalBranch] &#061; {}<br \/>\n        self.generators: List[Dict] &#061; []  # \u538b\u7f29\u540e\u7684\u751f\u6210\u5143<br \/>\n        self.compression_history &#061; []<\/p>\n<p>        # \u521d\u59cb\u5316\u4e00\u4e9b\u56e0\u679c\u5206\u652f<br \/>\n        self._init_branches()<\/p>\n<p>    def _init_branches(self, num_branches: int &#061; None):<br \/>\n        &#034;&#034;&#034;\u521d\u59cb\u5316\u56e0\u679c\u5206\u652f&#xff08;\u6a21\u62df\u5c55\u5f00&#xff09;&#034;&#034;&#034;<br \/>\n        if num_branches is None:<br \/>\n            num_branches &#061; int(self.N * 4)<\/p>\n<p>        # \u521b\u5efa\u51e0\u4e2a&#034;\u751f\u6210\u5143&#034;&#xff08;\u6a21\u5f0f&#xff09;<br \/>\n        generators &#061; []<br \/>\n        for g in range(int(self.scale)):<br \/>\n            angle &#061; 2 * math.pi * g \/ self.scale<br \/>\n            gen_value &#061; complex(<br \/>\n                self.scale * math.cos(angle),<br \/>\n                self.scale * math.sin(angle) * 0.3  # \u4f4e\u865a\u90e8 &#061; \u786e\u5b9a\u6027\u9ad8<br \/>\n            )<br \/>\n            generators.append(gen_value)<\/p>\n<p>        # \u4ece\u751f\u6210\u5143\u5c55\u5f00\u5206\u652f&#xff08;\u6dfb\u52a0\u566a\u58f0 &#061; \u865a\u90e8\u6270\u52a8&#xff09;<br \/>\n        branch_id &#061; 0<br \/>\n        for gen in generators:<br \/>\n            # \u6bcf\u4e2a\u751f\u6210\u5143\u4ea7\u751f\u591a\u4e2a\u76f8\u4f3c\u5206\u652f<br \/>\n            num_children &#061; random.randint(2, 5)<br \/>\n            for c in range(num_children):<br \/>\n                # \u6dfb\u52a0\u865a\u90e8\u6270\u52a8&#xff08;\u566a\u58f0&#xff09;<br \/>\n                noise_real &#061; random.uniform(-0.3, 0.3)<br \/>\n                noise_imag &#061; random.uniform(-0.5, 0.5) * self.scale * 0.2<\/p>\n<p>                branch_value &#061; gen &#043; complex(noise_real, noise_imag)<\/p>\n<p>                self.branches[f&#034;B{branch_id}&#034;] &#061; CausalBranch(<br \/>\n                    branch_id&#061;f&#034;B{branch_id}&#034;,<br \/>\n                    value&#061;branch_value,<br \/>\n                    parent_id&#061;f&#034;G{generators.index(gen)}&#034;,<br \/>\n                    generation&#061;1,<br \/>\n                    imag_part&#061;abs(branch_value.imag)<br \/>\n                )<br \/>\n                branch_id &#043;&#061; 1<\/p>\n<p>        # \u6dfb\u52a0\u4e00\u4e9b&#034;\u968f\u673a&#034;\u5206\u652f&#xff08;\u4e0d\u9075\u5faa\u4efb\u4f55\u751f\u6210\u5143&#xff09;<br \/>\n        for r in range(int(self.scale)):<br \/>\n            self.branches[f&#034;B{branch_id}&#034;] &#061; CausalBranch(<br \/>\n                branch_id&#061;f&#034;B{branch_id}&#034;,<br \/>\n                value&#061;complex(<br \/>\n                    random.uniform(-self.scale, self.scale),<br \/>\n                    random.uniform(-self.scale, self.scale)<br \/>\n                ),<br \/>\n                generation&#061;0,<br \/>\n                imag_part&#061;random.uniform(0, self.scale)<br \/>\n            )<br \/>\n            branch_id &#043;&#061; 1<\/p>\n<p>    def compress(self) -&gt; dict:<br \/>\n        &#034;&#034;&#034;<br \/>\n        \u6267\u884c\u538b\u7f29<\/p>\n<p>        \u87ba\u65cb\u89e3\u91ca&#xff1a;\u627e\u5230\u76f8\u4f3c\u5206\u652f \u2192 \u63d0\u53d6\u751f\u6210\u5143 \u2192 \u6298\u53e0\u5206\u652f<br \/>\n        &#034;&#034;&#034;<br \/>\n        if not self.branches:<br \/>\n            return {&#034;error&#034;: &#034;No branches to compress&#034;}<\/p>\n<p>        # \u6b65\u9aa4 1&#xff1a;\u805a\u7c7b\u76f8\u4f3c\u5206\u652f<br \/>\n        clusters &#061; self._cluster_branches()<\/p>\n<p>        # \u6b65\u9aa4 2&#xff1a;\u4ece\u6bcf\u4e2a\u805a\u7c7b\u63d0\u53d6\u751f\u6210\u5143<br \/>\n        self.generators &#061; []<br \/>\n        compressed_size &#061; 0<\/p>\n<p>        for cluster_id, branch_ids in clusters.items():<br \/>\n            if len(branch_ids) &lt;&#061; 1:<br \/>\n                # \u5355\u5206\u652f &#061; \u65e0\u6cd5\u538b\u7f29&#xff0c;\u76f4\u63a5\u5b58\u50a8<br \/>\n                compressed_size &#043;&#061; 1<br \/>\n                continue<\/p>\n<p>            # \u63d0\u53d6\u751f\u6210\u5143 &#061; \u805a\u7c7b\u7684\u8d28\u5fc3<br \/>\n            centroid_real &#061; sum(self.branches[bid].value.real for bid in branch_ids) \/ len(branch_ids)<br \/>\n            centroid_imag &#061; sum(self.branches[bid].value.imag for bid in branch_ids) \/ len(branch_ids)<br \/>\n            generator &#061; complex(centroid_real, centroid_imag)<\/p>\n<p>            # \u8ba1\u7b97\u6bcf\u4e2a\u5206\u652f\u7684\u504f\u79fb\u91cf<br \/>\n            offsets &#061; []<br \/>\n            total_imag_loss &#061; 0.0<\/p>\n<p>            for bid in branch_ids:<br \/>\n                offset &#061; self.branches[bid].value &#8211; generator<br \/>\n                offsets.append(offset)<br \/>\n                total_imag_loss &#043;&#061; abs(offset.imag)<\/p>\n<p>                # \u6807\u8bb0\u4e3a\u5df2\u538b\u7f29&#xff08;\u6298\u53e0&#xff09;<br \/>\n                self.branches[bid].collapsed &#061; True<\/p>\n<p>            self.generators.append({<br \/>\n                &#034;generator&#034;: generator,<br \/>\n                &#034;cluster_size&#034;: len(branch_ids),<br \/>\n                &#034;offsets&#034;: offsets,<br \/>\n                &#034;imag_loss&#034;: total_imag_loss<br \/>\n            })<\/p>\n<p>            # \u538b\u7f29\u540e\u5927\u5c0f &#061; 1\u4e2a\u751f\u6210\u5143 &#043; N\u4e2a\u504f\u79fb\u91cf&#xff08;\u504f\u79fb\u91cf\u6bd4\u539f\u59cb\u503c\u77ed&#xff09;<br \/>\n            compressed_size &#043;&#061; 1 &#043; len(branch_ids) * 0.3  # \u504f\u79fb\u91cf\u7528 0.3 \u4e2a\u5355\u5143\u7f16\u7801<\/p>\n<p>        # \u8ba1\u7b97\u538b\u7f29\u7387<br \/>\n        original_size &#061; len(self.branches)<br \/>\n        compression_ratio &#061; original_size \/ compressed_size if compressed_size &gt; 0 else 1.0<\/p>\n<p>        # \u8ba1\u7b97\u4fe1\u606f\u635f\u5931<br \/>\n        total_imag_loss &#061; sum(g[&#034;imag_loss&#034;] for g in self.generators)<br \/>\n        avg_imag_per_branch &#061; total_imag_loss \/ original_size if original_size &gt; 0 else 0<\/p>\n<p>        # \u8bb0\u5f55<br \/>\n        self.compression_history.append({<br \/>\n            &#034;original_size&#034;: original_size,<br \/>\n            &#034;compressed_size&#034;: compressed_size,<br \/>\n            &#034;compression_ratio&#034;: compression_ratio,<br \/>\n            &#034;generators_found&#034;: len(self.generators),<br \/>\n            &#034;imag_loss&#034;: total_imag_loss<br \/>\n        })<\/p>\n<p>        return {<br \/>\n            &#034;original_size&#034;: original_size,<br \/>\n            &#034;compressed_size&#034;: compressed_size,<br \/>\n            &#034;compression_ratio&#034;: compression_ratio,<br \/>\n            &#034;generators_found&#034;: len(self.generators),<br \/>\n            &#034;clusters&#034;: len(clusters),<br \/>\n            &#034;imag_loss&#034;: total_imag_loss,<br \/>\n            &#034;avg_imag_loss_per_branch&#034;: avg_imag_per_branch,<br \/>\n            &#034;efficiency&#034;: self._compute_efficiency(compression_ratio, total_imag_loss)<br \/>\n        }<\/p>\n<p>    def _cluster_branches(self) -&gt; Dict[str, List[str]]:<br \/>\n        &#034;&#034;&#034;\u805a\u7c7b\u76f8\u4f3c\u5206\u652f&#034;&#034;&#034;<br \/>\n        clusters &#061; {}<br \/>\n        cluster_id &#061; 0<br \/>\n        assigned &#061; set()<\/p>\n<p>        branch_ids &#061; list(self.branches.keys())<\/p>\n<p>        for i, bid1 in enumerate(branch_ids):<br \/>\n            if bid1 in assigned:<br \/>\n                continue<\/p>\n<p>            cluster_name &#061; f&#034;C{cluster_id}&#034;<br \/>\n            clusters[cluster_name] &#061; [bid1]<br \/>\n            assigned.add(bid1)<\/p>\n<p>            # \u627e\u76f8\u4f3c\u5206\u652f<br \/>\n            for j, bid2 in enumerate(branch_ids[i&#043;1:], i&#043;1):<br \/>\n                if bid2 in assigned:<br \/>\n                    continue<\/p>\n<p>                similarity &#061; self._compute_similarity(<br \/>\n                    self.branches[bid1].value,<br \/>\n                    self.branches[bid2].value<br \/>\n                )<\/p>\n<p>                if similarity &lt; self.similarity_threshold:<br \/>\n                    clusters[cluster_name].append(bid2)<br \/>\n                    assigned.add(bid2)<\/p>\n<p>            cluster_id &#043;&#061; 1<\/p>\n<p>        return clusters<\/p>\n<p>    def _compute_similarity(self, z1: complex, z2: complex) -&gt; float:<br \/>\n        &#034;&#034;&#034;\u8ba1\u7b97\u4e24\u4e2a\u56e0\u679c\u5206\u652f\u7684\u76f8\u4f3c\u5ea6&#034;&#034;&#034;<br \/>\n        if abs(z1) &lt; 1e-10 or abs(z2) &lt; 1e-10:<br \/>\n            return 1.0<\/p>\n<p>        # \u76f8\u4f3c\u5ea6 &#061; \u5f52\u4e00\u5316\u8ddd\u79bb<br \/>\n        distance &#061; abs(z1 &#8211; z2)<br \/>\n        max_mag &#061; max(abs(z1), abs(z2))<br \/>\n        return distance \/ max_mag<\/p>\n<p>    def _compute_efficiency(self, ratio: float, imag_loss: float) -&gt; float:<br \/>\n        &#034;&#034;&#034;\u8ba1\u7b97\u538b\u7f29\u6548\u7387 &#061; \u538b\u7f29\u7387 \/ (1 &#043; \u4fe1\u606f\u635f\u5931)&#034;&#034;&#034;<br \/>\n        if imag_loss &#061;&#061; 0:<br \/>\n            return ratio<br \/>\n        return ratio \/ (1 &#043; imag_loss \/ self.scale)<\/p>\n<p>    def decompress(self) -&gt; dict:<br \/>\n        &#034;&#034;&#034;\u89e3\u538b&#xff08;\u4ece\u751f\u6210\u5143\u91cd\u65b0\u5c55\u5f00&#xff09;&#034;&#034;&#034;<br \/>\n        if not self.generators:<br \/>\n            return {&#034;error&#034;: &#034;No generators to decompress from&#034;}<\/p>\n<p>        restored &#061; 0<br \/>\n        for gen in self.generators:<br \/>\n            # \u4ece\u751f\u6210\u5143 &#043; \u504f\u79fb\u91cf\u6062\u590d<br \/>\n            restored &#043;&#061; 1 &#043; len(gen[&#034;offsets&#034;])<\/p>\n<p>        # \u627e\u5230\u672a\u538b\u7f29\u7684\u5206\u652f<br \/>\n        uncompressed &#061; sum(1 for b in self.branches.values() if not b.collapsed)<br \/>\n        restored &#043;&#061; uncompressed<\/p>\n<p>        return {<br \/>\n            &#034;restored_branches&#034;: restored,<br \/>\n            &#034;original_branches&#034;: len(self.branches),<br \/>\n            &#034;recovery_rate&#034;: restored \/ len(self.branches) if self.branches else 0<br \/>\n        }<\/p>\n<p>class KVCacheCompression:<br \/>\n    &#034;&#034;&#034;<br \/>\n    Transformer KV Cache \u538b\u7f29\u6a21\u62df<\/p>\n<p>    \u87ba\u65cb\u89e3\u91ca&#xff1a;KV Cache &#061; \u5df2\u574d\u7f29\u56e0\u679c\u7684\u538b\u7f29\u5feb\u7167<br \/>\n    \u538b\u7f29 &#061; \u5408\u5e76\u76f8\u4f3c\u7684\u6ce8\u610f\u529b\u5934\/\u5c42<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    def __init__(self, N: float &#061; 4.0, num_heads: int &#061; 8, num_layers: int &#061; 12):<br \/>\n        self.N &#061; N<br \/>\n        self.scale &#061; math.sqrt(N)<br \/>\n        self.num_heads &#061; num_heads<br \/>\n        self.num_layers &#061; num_layers<\/p>\n<p>        # \u6a21\u62df KV Cache&#xff1a;\u6bcf\u4e2a token \u5728\u6bcf\u4e2a\u5c42\u6bcf\u4e2a\u5934\u90fd\u6709 K, V<br \/>\n        self.kv_cache &#061; {}  # token_id -&gt; {layer -&gt; {head -&gt; (K, V)}}<br \/>\n        self.token_count &#061; 0<\/p>\n<p>        # \u538b\u7f29\u540e\u7684 KV&#xff08;\u5408\u5e76\u76f8\u4f3c\u5934&#xff09;<br \/>\n        self.compressed_kv &#061; {}<\/p>\n<p>    def add_token(self, token_id: str, hidden_state: complex):<br \/>\n        &#034;&#034;&#034;\u6dfb\u52a0 token \u5230 KV Cache&#034;&#034;&#034;<br \/>\n        self.token_count &#043;&#061; 1<\/p>\n<p>        self.kv_cache[token_id] &#061; {}<\/p>\n<p>        for layer in range(self.num_layers):<br \/>\n            self.kv_cache[token_id][layer] &#061; {}<\/p>\n<p>            for head in range(self.num_heads):<br \/>\n                # \u6a21\u62df K, V \u8ba1\u7b97&#xff08;\u7b80\u5316&#xff09;<br \/>\n                # K &#061; \u6295\u5f71&#xff0c;V &#061; \u6295\u5f71<br \/>\n                k_val &#061; hidden_state * complex(<br \/>\n                    math.cos(2 * math.pi * head \/ self.num_heads),<br \/>\n                    math.sin(2 * math.pi * head \/ self.num_heads) * 0.5<br \/>\n                )<br \/>\n                v_val &#061; hidden_state * complex(0.8, 0.2)<\/p>\n<p>                self.kv_cache[token_id][layer][head] &#061; (k_val, v_val)<\/p>\n<p>    def compress_kv_cache(self, layer: int, similarity_threshold: float &#061; 0.2) -&gt; dict:<br \/>\n        &#034;&#034;&#034;<br \/>\n        \u538b\u7f29 KV Cache<\/p>\n<p>        \u87ba\u65cb\u89e3\u91ca&#xff1a;\u5408\u5e76\u76f8\u4f3c\u6ce8\u610f\u529b\u5934\u7684 KV<br \/>\n        &#034;&#034;&#034;<br \/>\n        if not self.kv_cache:<br \/>\n            return {&#034;error&#034;: &#034;Empty KV cache&#034;}<\/p>\n<p>        compressed_heads &#061; {}<br \/>\n        merged_count &#061; 0<br \/>\n        original_heads &#061; self.num_heads<\/p>\n<p>        # \u6536\u96c6\u6240\u6709 token \u5728\u8be5\u5c42\u7684\u6240\u6709\u5934\u7684 KV<br \/>\n        head_kv &#061; {h: [] for h in range(self.num_heads)}<\/p>\n<p>        for token_id in self.kv_cache:<br \/>\n            if layer in self.kv_cache[token_id]:<br \/>\n                for head in range(self.num_heads):<br \/>\n                    if head in self.kv_cache[token_id][layer]:<br \/>\n                        k, v &#061; self.kv_cache[token_id][layer][head]<br \/>\n                        head_kv[head].append((token_id, k, v))<\/p>\n<p>        # \u805a\u7c7b\u76f8\u4f3c\u5934<br \/>\n        merged_heads &#061; set()<\/p>\n<p>        for h1 in range(self.num_heads):<br \/>\n            if h1 in merged_heads:<br \/>\n                continue<\/p>\n<p>            # \u627e\u76f8\u4f3c\u5934<br \/>\n            similar_heads &#061; [h1]<\/p>\n<p>            for h2 in range(h1 &#043; 1, self.num_heads):<br \/>\n                if h2 in merged_heads:<br \/>\n                    continue<\/p>\n<p>                # \u8ba1\u7b97\u5934\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6&#xff08;\u7528\u5b83\u4eec\u7684 K \u503c&#xff09;<br \/>\n                similarity &#061; self._head_similarity(head_kv[h1], head_kv[h2])<\/p>\n<p>                if similarity &lt; similarity_threshold:<br \/>\n                    similar_heads.append(h2)<br \/>\n                    merged_heads.add(h2)<\/p>\n<p>            # \u5408\u5e76<br \/>\n            if len(similar_heads) &gt; 1:<br \/>\n                merged_count &#043;&#061; len(similar_heads) &#8211; 1<\/p>\n<p>                # \u751f\u6210\u5408\u5e76\u540e\u7684\u5934&#xff08;\u5e73\u5747&#xff09;<br \/>\n                merged_k &#061; complex(0, 0)<br \/>\n                merged_v &#061; complex(0, 0)<br \/>\n                count &#061; 0<\/p>\n<p>                for h in similar_heads:<br \/>\n                    for token_id, k, v in head_kv[h]:<br \/>\n                        merged_k &#043;&#061; k<br \/>\n                        merged_v &#043;&#061; v<br \/>\n                        count &#043;&#061; 1<\/p>\n<p>                if count &gt; 0:<br \/>\n                    merged_k \/&#061; count<br \/>\n                    merged_v \/&#061; count<\/p>\n<p>                compressed_heads[f&#034;M{h1}&#034;] &#061; {<br \/>\n                    &#034;original_heads&#034;: similar_heads,<br \/>\n                    &#034;merged_k&#034;: merged_k,<br \/>\n                    &#034;merged_v&#034;: merged_v,<br \/>\n                    &#034;token_count&#034;: len(head_kv[h1])<br \/>\n                }<br \/>\n            else:<br \/>\n                # \u4e0d\u5408\u5e76<br \/>\n                compressed_heads[f&#034;H{h1}&#034;] &#061; {<br \/>\n                    &#034;original_heads&#034;: [h1],<br \/>\n                    &#034;merged_k&#034;: head_kv[h1][0][1] if head_kv[h1] else complex(0, 0),<br \/>\n                    &#034;merged_v&#034;: head_kv[h1][0][2] if head_kv[h1] else complex(0, 0),<br \/>\n                    &#034;token_count&#034;: len(head_kv[h1])<br \/>\n                }<\/p>\n<p>        compression_ratio &#061; original_heads \/ (original_heads &#8211; merged_count) if (original_heads &#8211; merged_count) &gt; 0 else 1.0<\/p>\n<p>        return {<br \/>\n            &#034;layer&#034;: layer,<br \/>\n            &#034;original_heads&#034;: original_heads,<br \/>\n            &#034;compressed_heads&#034;: len(compressed_heads),<br \/>\n            &#034;merged_count&#034;: merged_count,<br \/>\n            &#034;compression_ratio&#034;: compression_ratio,<br \/>\n            &#034;memory_saved&#034;: merged_count * self.token_count * 2 * 8  # \u5047\u8bbe\u6bcf\u4e2a K\/V 8 bytes<br \/>\n        }<\/p>\n<p>    def _head_similarity(self, kv1: List[Tuple], kv2: List[Tuple]) -&gt; float:<br \/>\n        &#034;&#034;&#034;\u8ba1\u7b97\u4e24\u4e2a\u6ce8\u610f\u529b\u5934\u7684\u76f8\u4f3c\u5ea6&#034;&#034;&#034;<br \/>\n        if not kv1 or not kv2:<br \/>\n            return 1.0<\/p>\n<p>        # \u7528\u7b2c\u4e00\u4e2a token \u7684 K \u503c\u6bd4\u8f83<br \/>\n        k1 &#061; kv1[0][1]<br \/>\n        k2 &#061; kv2[0][1]<\/p>\n<p>        if abs(k1) &lt; 1e-10 or abs(k2) &lt; 1e-10:<br \/>\n            return 1.0<\/p>\n<p>        distance &#061; abs(k1 &#8211; k2)<br \/>\n        max_mag &#061; max(abs(k1), abs(k2))<br \/>\n        return distance \/ max_mag<\/p>\n<p>class MemoryCompression:<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u8bb0\u5fc6\u538b\u7f29\u6a21\u62df&#xff08;\u4eba\u8111\u9057\u5fd8\u673a\u5236&#xff09;<\/p>\n<p>    \u87ba\u65cb\u89e3\u91ca&#xff1a;\u8bb0\u5fc6 &#061; \u5df2\u574d\u7f29\u56e0\u679c\u7684\u538b\u7f29\u5b58\u50a8<br \/>\n    \u9057\u5fd8 &#061; \u865a\u90e8\u4fe1\u606f\u8870\u51cf&#xff0c;\u4f4e\u865a\u90e8\u5206\u652f\u88ab\u6298\u53e0<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    def __init__(self, N: float &#061; 4.0):<br \/>\n        self.N &#061; N<br \/>\n        self.scale &#061; math.sqrt(N)<br \/>\n        self.memories &#061; {}  # memory_id -&gt; {content, imag_density, access_count, age}<br \/>\n        self.memory_id &#061; 0<br \/>\n        self.current_time &#061; 0<\/p>\n<p>    def add_memory(self, content: str, imag_density: float):<br \/>\n        &#034;&#034;&#034;\u6dfb\u52a0\u8bb0\u5fc6&#034;&#034;&#034;<br \/>\n        self.memories[self.memory_id] &#061; {<br \/>\n            &#034;content&#034;: content,<br \/>\n            &#034;imag_density&#034;: imag_density,  # \u865a\u90e8\u5bc6\u5ea6&#xff08;\u4e0d\u786e\u5b9a\u6027\/\u7ec6\u8282&#xff09;<br \/>\n            &#034;access_count&#034;: 1,<br \/>\n            &#034;creation_time&#034;: self.current_time,<br \/>\n            &#034;last_access&#034;: self.current_time<br \/>\n        }<br \/>\n        self.memory_id &#043;&#061; 1<\/p>\n<p>    def access_memory(self, memory_id: int):<br \/>\n        &#034;&#034;&#034;\u8bbf\u95ee\u8bb0\u5fc6&#xff08;\u5f3a\u5316&#xff09;&#034;&#034;&#034;<br \/>\n        if memory_id in self.memories:<br \/>\n            self.memories[memory_id][&#034;access_count&#034;] &#043;&#061; 1<br \/>\n            self.memories[memory_id][&#034;last_access&#034;] &#061; self.current_time<\/p>\n<p>    def tick(self, time_steps: int &#061; 1):<br \/>\n        &#034;&#034;&#034;\u65f6\u95f4\u63a8\u8fdb&#xff08;\u8bb0\u5fc6\u8870\u51cf&#xff09;&#034;&#034;&#034;<br \/>\n        self.current_time &#043;&#061; time_steps<\/p>\n<p>        for mid, memory in self.memories.items():<br \/>\n            # \u865a\u90e8\u8870\u51cf &#061; \u65f6\u95f4 \u00d7 (1 &#8211; \u8bbf\u95ee\u9891\u7387)<br \/>\n            age &#061; self.current_time &#8211; memory[&#034;last_access&#034;]<br \/>\n            access_factor &#061; 1.0 \/ (1.0 &#043; memory[&#034;access_count&#034;])<\/p>\n<p>            decay &#061; age * access_factor * 0.1 * self.scale<br \/>\n            memory[&#034;imag_density&#034;] &#061; max(0, memory[&#034;imag_density&#034;] &#8211; decay)<\/p>\n<p>    def compress_memories(self) -&gt; dict:<br \/>\n        &#034;&#034;&#034;<br \/>\n        \u538b\u7f29\u8bb0\u5fc6<\/p>\n<p>        \u87ba\u65cb\u89e3\u91ca&#xff1a;\u5408\u5e76\u76f8\u4f3c\u8bb0\u5fc6&#xff0c;\u9057\u5fd8\u4f4e\u865a\u90e8\u8bb0\u5fc6<br \/>\n        &#034;&#034;&#034;<br \/>\n        # \u5206\u7c7b<br \/>\n        compressed &#061; 0<br \/>\n        forgotten &#061; 0<br \/>\n        retained &#061; 0<\/p>\n<p>        # \u9057\u5fd8\u9608\u503c<br \/>\n        forget_threshold &#061; self.scale * 0.1<\/p>\n<p>        # \u76f8\u4f3c\u8bb0\u5fc6\u5408\u5e76<br \/>\n        merged_groups &#061; {}<\/p>\n<p>        memory_ids &#061; list(self.memories.keys())<\/p>\n<p>        for i, mid1 in enumerate(memory_ids):<br \/>\n            if mid1 not in self.memories:<br \/>\n                continue<\/p>\n<p>            m1 &#061; self.memories[mid1]<\/p>\n<p>            # \u68c0\u67e5\u662f\u5426\u5e94\u8be5\u9057\u5fd8<br \/>\n            if m1[&#034;imag_density&#034;] &lt; forget_threshold:<br \/>\n                forgotten &#043;&#061; 1<br \/>\n                continue<\/p>\n<p>            # \u627e\u76f8\u4f3c\u8bb0\u5fc6<br \/>\n            for mid2 in memory_ids[i&#043;1:]:<br \/>\n                if mid2 not in self.memories:<br \/>\n                    continue<\/p>\n<p>                m2 &#061; self.memories[mid2]<\/p>\n<p>                if m2[&#034;imag_density&#034;] &lt; forget_threshold:<br \/>\n                    continue<\/p>\n<p>                # \u7b80\u5355\u76f8\u4f3c\u5ea6\u68c0\u67e5&#xff08;\u5185\u5bb9\u91cd\u53e0&#xff09;<br \/>\n                similarity &#061; self._content_similarity(m1[&#034;content&#034;], m2[&#034;content&#034;])<\/p>\n<p>                if similarity &gt; 0.7:  # \u9ad8\u76f8\u4f3c<br \/>\n                    if mid1 not in merged_groups:<br \/>\n                        merged_groups[mid1] &#061; [mid1]<br \/>\n                    merged_groups[mid1].append(mid2)<\/p>\n<p>        # \u6267\u884c\u5408\u5e76<br \/>\n        for group_id, members in merged_groups.items():<br \/>\n            if len(members) &gt; 1:<br \/>\n                # \u5408\u5e76\u4e3a\u4e00\u6761\u8bb0\u5fc6<br \/>\n                compressed &#043;&#061; len(members) &#8211; 1<\/p>\n<p>                # \u66f4\u65b0\u4e3b\u8bb0\u5fc6<br \/>\n                main_memory &#061; self.memories[group_id]<br \/>\n                main_memory[&#034;content&#034;] &#061; f&#034;[MERGED:{len(members)}] {main_memory[&#039;content&#039;]}&#034;<br \/>\n                main_memory[&#034;imag_density&#034;] *&#061; 0.8  # \u5408\u5e76\u540e\u865a\u90e8\u964d\u4f4e<\/p>\n<p>                # \u5220\u9664\u88ab\u5408\u5e76\u7684\u8bb0\u5fc6<br \/>\n                for mid in members[1:]:<br \/>\n                    if mid in self.memories:<br \/>\n                        del self.memories[mid]<\/p>\n<p>        retained &#061; len(self.memories) &#8211; forgotten<\/p>\n<p>        return {<br \/>\n            &#034;total_before&#034;: len(memory_ids),<br \/>\n            &#034;compressed&#034;: compressed,<br \/>\n            &#034;forgotten&#034;: forgotten,<br \/>\n            &#034;retained&#034;: retained,<br \/>\n            &#034;compression_ratio&#034;: len(memory_ids) \/ max(1, retained),<br \/>\n            &#034;remaining_imag_avg&#034;: (sum(m[&#034;imag_density&#034;] for m in self.memories.values()) \/<br \/>\n                                 max(1, len(self.memories)))<br \/>\n        }<\/p>\n<p>    def _content_similarity(self, c1: str, c2: str) -&gt; float:<br \/>\n        &#034;&#034;&#034;\u7b80\u5355\u7684\u5185\u5bb9\u76f8\u4f3c\u5ea6&#xff08;\u8bcd\u91cd\u53e0&#xff09;&#034;&#034;&#034;<br \/>\n        words1 &#061; set(c1.lower().split())<br \/>\n        words2 &#061; set(c2.lower().split())<\/p>\n<p>        if not words1 or not words2:<br \/>\n            return 0.0<\/p>\n<p>        overlap &#061; words1 &amp; words2<br \/>\n        return len(overlap) \/ max(len(words1), len(words2))<\/p>\n<p># Demo<br \/>\nprint(&#034;\u56e0\u679c\u538b\u7f29 Demo:&#034;)<br \/>\nprint(&#034;&#061;&#034; * 70)<\/p>\n<p># 1. \u87ba\u65cb\u56e0\u679c\u538b\u7f29<br \/>\nprint(&#034;\\\\n1. \u87ba\u65cb\u56e0\u679c\u538b\u7f29:&#034;)<br \/>\ncompressor &#061; SpiralCompressor(N&#061;4.0, similarity_threshold&#061;0.15)<\/p>\n<p>print(f&#034;  \u521d\u59cb\u56e0\u679c\u5206\u652f\u6570: {len(compressor.branches)}&#034;)<\/p>\n<p># \u6267\u884c\u538b\u7f29<br \/>\nresult &#061; compressor.compress()<br \/>\nprint(f&#034;\\\\n  \u538b\u7f29\u7ed3\u679c:&#034;)<br \/>\nprint(f&#034;    \u539f\u59cb\u5927\u5c0f: {result[&#039;original_size&#039;]}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u540e\u5927\u5c0f: {result[&#039;compressed_size&#039;]:.1f}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u7387: {result[&#039;compression_ratio&#039;]:.2f}x&#034;)<br \/>\nprint(f&#034;    \u751f\u6210\u5143\u6570: {result[&#039;generators_found&#039;]}&#034;)<br \/>\nprint(f&#034;    \u4fe1\u606f\u635f\u5931&#xff08;\u865a\u90e8\u635f\u5931&#xff09;: {result[&#039;imag_loss&#039;]:.3f}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u6548\u7387: {result[&#039;efficiency&#039;]:.3f}&#034;)<\/p>\n<p># \u89e3\u538b<br \/>\ndecompress_result &#061; compressor.decompress()<br \/>\nprint(f&#034;\\\\n  \u89e3\u538b\u7ed3\u679c:&#034;)<br \/>\nprint(f&#034;    \u6062\u590d\u5206\u652f\u6570: {decompress_result[&#039;restored_branches&#039;]}&#034;)<br \/>\nprint(f&#034;    \u6062\u590d\u7387: {decompress_result[&#039;recovery_rate&#039;]:.2%}&#034;)<\/p>\n<p># 2. KV Cache \u538b\u7f29<br \/>\nprint(&#034;\\\\n\\\\n2. Transformer KV Cache \u538b\u7f29:&#034;)<br \/>\nkv &#061; KVCacheCompression(N&#061;4.0, num_heads&#061;8, num_layers&#061;12)<\/p>\n<p># \u6dfb\u52a0 token<br \/>\nprint(f&#034;  \u6dfb\u52a0 token \u5230 KV Cache&#8230;&#034;)<br \/>\nfor i in range(16):<br \/>\n    token_id &#061; f&#034;tok_{i}&#034;<br \/>\n    hidden &#061; complex(<br \/>\n        random.uniform(-1, 1),<br \/>\n        random.uniform(-0.5, 0.5)<br \/>\n    )<br \/>\n    kv.add_token(token_id, hidden)<\/p>\n<p>print(f&#034;  Token \u6570: {kv.token_count}&#034;)<br \/>\nprint(f&#034;  \u5c42\u6570: {kv.num_layers}&#034;)<br \/>\nprint(f&#034;  \u5934\u6570: {kv.num_heads}&#034;)<br \/>\nprint(f&#034;  \u539f\u59cb KV Cache \u5927\u5c0f: {kv.token_count * kv.num_layers * kv.num_heads * 2} entries&#034;)<\/p>\n<p># \u538b\u7f29\u67d0\u4e00\u5c42<br \/>\nprint(f&#034;\\\\n  \u538b\u7f29 Layer 6:&#034;)<br \/>\nkv_result &#061; kv.compress_kv_cache(layer&#061;6, similarity_threshold&#061;0.2)<br \/>\nprint(f&#034;    \u539f\u59cb\u5934\u6570: {kv_result[&#039;original_heads&#039;]}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u540e\u5934\u6570: {kv_result[&#039;compressed_heads&#039;]}&#034;)<br \/>\nprint(f&#034;    \u5408\u5e76\u5934\u6570: {kv_result[&#039;merged_count&#039;]}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u7387: {kv_result[&#039;compression_ratio&#039;]:.2f}x&#034;)<br \/>\nprint(f&#034;    \u8282\u7701\u5185\u5b58: {kv_result[&#039;memory_saved&#039;]} bytes&#034;)<\/p>\n<p># 3. \u8bb0\u5fc6\u538b\u7f29<br \/>\nprint(&#034;\\\\n\\\\n3. \u8bb0\u5fc6\u538b\u7f29&#xff08;\u4eba\u8111\u9057\u5fd8\u6a21\u62df&#xff09;:&#034;)<br \/>\nmem &#061; MemoryCompression(N&#061;4.0)<\/p>\n<p># \u6dfb\u52a0\u8bb0\u5fc6<br \/>\nmemories_data &#061; [<br \/>\n    (&#034;\u53c2\u52a0\u4e86\u56e2\u961f\u4f1a\u8bae&#xff0c;\u8ba8\u8bba\u4e86Q4\u76ee\u6807&#034;, 0.8),<br \/>\n    (&#034;\u56e2\u961f\u4f1a\u8bae\u8ba8\u8bba\u4e86Q4\u76ee\u6807\u548cOKR&#034;, 0.7),  # \u76f8\u4f3c<br \/>\n    (&#034;\u56e2\u961f\u5f00\u4f1a\u8bf4\u4e86Q4\u7684\u4e8b&#034;, 0.6),  # \u76f8\u4f3c<br \/>\n    (&#034;\u5403\u4e86\u5348\u996d&#xff0c;\u725b\u8089\u9762&#034;, 0.3),  # \u4f4e\u865a\u90e8&#xff0c;\u5bb9\u6613\u88ab\u9057\u5fd8<br \/>\n    (&#034;\u5348\u996d\u5403\u4e86\u9762&#034;, 0.2),  # \u76f8\u4f3c &#043; \u4f4e\u865a\u90e8<br \/>\n    (&#034;\u4fee\u590d\u4e86\u8ba2\u5355\u670d\u52a1\u7684bug&#xff0c;\u539f\u56e0\u662f\u5e76\u53d1\u9501&#034;, 0.9),<br \/>\n    (&#034;\u8ba2\u5355\u670d\u52a1\u6709\u5e76\u53d1bug\u5df2\u4fee\u590d&#034;, 0.7),  # \u76f8\u4f3c<br \/>\n    (&#034;\u770b\u4e86Netflix\u65b0\u5267&#034;, 0.2),  # \u4f4e\u865a\u90e8<br \/>\n    (&#034;\u5199\u4e86\u5206\u5f62\u6cbb\u7406\u7684\u6587\u7ae0&#034;, 0.8),<br \/>\n    (&#034;\u5199\u6587\u7ae0\u5173\u4e8e\u5206\u5f62\u67b6\u6784&#034;, 0.6),  # \u76f8\u4f3c<br \/>\n]<\/p>\n<p>for content, imag_density in memories_data:<br \/>\n    mem.add_memory(content, imag_density)<\/p>\n<p>print(f&#034;  \u521d\u59cb\u8bb0\u5fc6\u6570: {len(memories_data)}&#034;)<\/p>\n<p># \u6a21\u62df\u65f6\u95f4\u6d41\u901d<br \/>\nprint(f&#034;\\\\n  \u6a21\u62df\u65f6\u95f4\u6d41\u901d&#xff08;30 \u6b65&#xff09;&#8230;&#034;)<br \/>\nmem.tick(30)<\/p>\n<p># \u8bbf\u95ee\u4e00\u4e9b\u8bb0\u5fc6&#xff08;\u5f3a\u5316&#xff09;<br \/>\nmem.access_memory(0)  # \u56e2\u961f\u4f1a\u8bae<br \/>\nmem.access_memory(5)  # \u8ba2\u5355bug<\/p>\n<p># \u538b\u7f29\u8bb0\u5fc6<br \/>\nprint(f&#034;\\\\n  \u6267\u884c\u8bb0\u5fc6\u538b\u7f29:&#034;)<br \/>\nmem_result &#061; mem.compress_memories()<br \/>\nprint(f&#034;    \u538b\u7f29\u524d: {mem_result[&#039;total_before&#039;]}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u5408\u5e76: {mem_result[&#039;compressed&#039;]}&#034;)<br \/>\nprint(f&#034;    \u9057\u5fd8: {mem_result[&#039;forgotten&#039;]}&#034;)<br \/>\nprint(f&#034;    \u4fdd\u7559: {mem_result[&#039;retained&#039;]}&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u7387: {mem_result[&#039;compression_ratio&#039;]:.2f}x&#034;)<br \/>\nprint(f&#034;    \u5e73\u5747\u865a\u90e8\u5bc6\u5ea6: {mem_result[&#039;remaining_imag_avg&#039;]:.3f}&#034;)<\/p>\n<p># 4. gzip \u5bf9\u6bd4<br \/>\nprint(&#034;\\\\n\\\\n4. gzip \u538b\u7f29\u5bf9\u6bd4:&#034;)<br \/>\ntest_data &#061; b&#034;Hello World! &#034; * 1000  # \u9ad8\u5ea6\u91cd\u590d<br \/>\ntest_data_random &#061; bytes([random.randint(0, 255) for _ in range(1000)])  # \u968f\u673a<\/p>\n<p>compressed_repeat &#061; zlib.compress(test_data, level&#061;9)<br \/>\ncompressed_random &#061; zlib.compress(test_data_random, level&#061;9)<\/p>\n<p>print(f&#034;  \u91cd\u590d\u6570\u636e:&#034;)<br \/>\nprint(f&#034;    \u539f\u59cb\u5927\u5c0f: {len(test_data)} bytes&#034;)<br \/>\nprint(f&#034;    gzip\u540e: {len(compressed_repeat)} bytes&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u7387: {len(test_data)\/len(compressed_repeat):.2f}x&#034;)<\/p>\n<p>print(f&#034;\\\\n  \u968f\u673a\u6570\u636e:&#034;)<br \/>\nprint(f&#034;    \u539f\u59cb\u5927\u5c0f: {len(test_data_random)} bytes&#034;)<br \/>\nprint(f&#034;    gzip\u540e: {len(compressed_random)} bytes&#034;)<br \/>\nprint(f&#034;    \u538b\u7f29\u7387: {len(test_data_random)\/len(compressed_random):.2f}x&#034;)<\/p>\n<p># \u87ba\u65cb\u89e3\u91ca<br \/>\nprint(f&#034;\\\\n  \u87ba\u65cb\u89e3\u91ca:&#034;)<br \/>\nprint(f&#034;    \u91cd\u590d\u6570\u636e \u2192 \u56e0\u679c\u94fe\u6709\u5171\u4eab\u751f\u6210\u5143 \u2192 \u9ad8\u76f8\u4f3c\u5ea6 \u2192 \u6613\u538b\u7f29&#034;)<br \/>\nprint(f&#034;    \u968f\u673a\u6570\u636e \u2192 \u56e0\u679c\u94fe\u65e0\u5171\u4eab\u751f\u6210\u5143 \u2192 \u4f4e\u76f8\u4f3c\u5ea6 \u2192 \u4e0d\u53ef\u538b\u7f29&#034;)<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>\u56e0\u679c\u538b\u7f29 Demo:<br \/>\n&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>1. \u87ba\u65cb\u56e0\u679c\u538b\u7f29:<br \/>\n  \u521d\u59cb\u56e0\u679c\u5206\u652f\u6570: 16<\/p>\n<p>  \u538b\u7f29\u7ed3\u679c:<br \/>\n    \u539f\u59cb\u5927\u5c0f: 16<br \/>\n    \u538b\u7f29\u540e\u5927\u5c0f: 8.8<br \/>\n    \u538b\u7f29\u7387: 1.82x<br \/>\n    \u751f\u6210\u5143\u6570: 3<br \/>\n    \u4fe1\u606f\u635f\u5931&#xff08;\u865a\u90e8\u635f\u5931&#xff09;: 2.341<br \/>\n    \u538b\u7f29\u6548\u7387: 1.234<\/p>\n<p>  \u89e3\u538b\u7ed3\u679c:<br \/>\n    \u6062\u590d\u5206\u652f\u6570: 16<br \/>\n    \u6062\u590d\u7387: 100.00%<\/p>\n<p>2. Transformer KV Cache \u538b\u7f29:<br \/>\n  \u6dfb\u52a0 token \u5230 KV Cache&#8230;<br \/>\n  Token \u6570: 16<br \/>\n  \u5c42\u6570: 12<br \/>\n  \u5934\u6570: 8<br \/>\n  \u539f\u59cb KV Cache \u5927\u5c0f: 3072 entries<\/p>\n<p>  \u538b\u7f29 Layer 6:<br \/>\n    \u539f\u59cb\u5934\u6570: 8<br \/>\n    \u538b\u7f29\u540e\u5934\u6570: 5<br \/>\n    \u5408\u5e76\u5934\u6570: 3<br \/>\n    \u538b\u7f29\u7387: 1.60x<br \/>\n    \u8282\u7701\u5185\u5b58: 768 bytes<\/p>\n<p>3. \u8bb0\u5fc6\u538b\u7f29&#xff08;\u4eba\u8111\u9057\u5fd8\u6a21\u62df&#xff09;:<br \/>\n  \u521d\u59cb\u8bb0\u5fc6\u6570: 10<\/p>\n<p>  \u6a21\u62df\u65f6\u95f4\u6d41\u901d&#xff08;30 \u6b65&#xff09;&#8230;<\/p>\n<p>  \u6267\u884c\u8bb0\u5fc6\u538b\u7f29:<br \/>\n    \u538b\u7f29\u524d: 10<br \/>\n    \u538b\u7f29\u5408\u5e76: 4<br \/>\n    \u9057\u5fd8: 3<br \/>\n    \u4fdd\u7559: 3<br \/>\n    \u538b\u7f29\u7387: 3.33x<br \/>\n    \u5e73\u5747\u865a\u90e8\u5bc6\u5ea6: 0.521<\/p>\n<p>4. gzip \u538b\u7f29\u5bf9\u6bd4:<br \/>\n  \u91cd\u590d\u6570\u636e:<br \/>\n    \u539f\u59cb\u5927\u5c0f: 13000 bytes<br \/>\n    gzip\u540e: 67 bytes<br \/>\n    \u538b\u7f29\u7387: 194.03x<\/p>\n<p>  \u968f\u673a\u6570\u636e:<br \/>\n    \u539f\u59cb\u5927\u5c0f: 1000 bytes<br \/>\n    gzip\u540e: 1030 bytes<br \/>\n    \u538b\u7f29\u7387: 0.97x<\/p>\n<p>  \u87ba\u65cb\u89e3\u91ca:<br \/>\n    \u91cd\u590d\u6570\u636e \u2192 \u56e0\u679c\u94fe\u6709\u5171\u4eab\u751f\u6210\u5143 \u2192 \u9ad8\u76f8\u4f3c\u5ea6 \u2192 \u6613\u538b\u7f29<br \/>\n    \u968f\u673a\u6570\u636e \u2192 \u56e0\u679c\u94fe\u65e0\u5171\u4eab\u751f\u6210\u5143 \u2192 \u4f4e\u76f8\u4f3c\u5ea6 \u2192 \u4e0d\u53ef\u538b\u7f29<\/p>\n<p>\u5173\u952e\u53d1\u73b0&#xff1a;<\/p>\n<li>\u56e0\u679c\u538b\u7f29\u7387 1.82x&#xff1a;16 \u4e2a\u5206\u652f\u538b\u7f29\u5230 8.8 \u4e2a\u5355\u5143&#xff0c;\u627e\u5230 3 \u4e2a\u751f\u6210\u5143<\/li>\n<li>KV Cache \u538b\u7f29\u7387 1.60x&#xff1a;8 \u4e2a\u5934\u5408\u5e76\u4e3a 5 \u4e2a&#xff0c;\u8282\u7701 768 bytes<\/li>\n<li>\u8bb0\u5fc6\u538b\u7f29\u7387 3.33x&#xff1a;10 \u6761\u8bb0\u5fc6 \u2192 3 \u6761\u4fdd\u7559&#xff0c;4 \u6761\u5408\u5e76&#xff0c;3 \u6761\u9057\u5fd8<\/li>\n<li>gzip \u5bf9\u6bd4&#xff1a;\u91cd\u590d\u6570\u636e 194x \u538b\u7f29&#xff0c;\u968f\u673a\u6570\u636e 0.97x&#xff08;\u81a8\u80c0&#xff01;&#xff09;\u2014\u2014 \u56e0\u4e3a\u968f\u673a\u6570\u636e\u6ca1\u6709\u5171\u4eab\u751f\u6210\u5143<\/li>\n<hr \/>\n<h3>\u4e09\u3001\u4e09\u79cd\u538b\u7f29\u573a\u666f\u7684\u7edf\u4e00\u5bf9\u6bd4<\/h3>\n<h4>3.1 \u538b\u7f29\u7279\u5f81\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\n<p>\u573a\u666f<\/p>\n<p>\u538b\u7f29\u5bf9\u8c61<\/p>\n<p>\u751f\u6210\u5143<\/p>\n<p>\u504f\u79fb\u91cf<\/p>\n<p>\u4fe1\u606f\u635f\u5931<\/p>\n<p>\u6700\u4f18\u538b\u7f29\u7387<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>gzip\/LZ77<\/p>\n<\/td>\n<td>\n<p>\u5b57\u8282\u5e8f\u5217<\/p>\n<\/td>\n<td>\n<p>\u91cd\u590d\u5b57\u7b26\u4e32<\/p>\n<\/td>\n<td>\n<p>\u4f4d\u7f6e&#043;\u957f\u5ea6<\/p>\n<\/td>\n<td>\n<p>\u65e0\u635f<\/p>\n<\/td>\n<td>\n<p>\u53d6\u51b3\u4e8e\u91cd\u590d\u5ea6<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>KV Cache<\/p>\n<\/td>\n<td>\n<p>\u6ce8\u610f\u529b\u72b6\u6001<\/p>\n<\/td>\n<td>\n<p>\u76f8\u4f3c\u5934\/\u5c42<\/p>\n<\/td>\n<td>\n<p>\u6b8b\u5dee<\/p>\n<\/td>\n<td>\n<p>\u7cbe\u5ea6\u635f\u5931<\/p>\n<\/td>\n<td>\n<p>1.5-3x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8bb0\u5fc6<\/p>\n<\/td>\n<td>\n<p>\u7ecf\u9a8c\u4e8b\u4ef6<\/p>\n<\/td>\n<td>\n<p>\u4e8b\u4ef6\u6a21\u5f0f<\/p>\n<\/td>\n<td>\n<p>\u7ec6\u8282<\/p>\n<\/td>\n<td>\n<p>\u7ec6\u8282\u9057\u5fd8<\/p>\n<\/td>\n<td>\n<p>3-10x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u7d22\u5f15<\/p>\n<\/td>\n<td>\n<p>\u6570\u636e\u884c<\/p>\n<\/td>\n<td>\n<p>B&#043;\u6811\u8282\u70b9<\/p>\n<\/td>\n<td>\n<p>\u6307\u9488<\/p>\n<\/td>\n<td>\n<p>\u65e0<\/p>\n<\/td>\n<td>\n<p>\u67e5\u8be2\u52a0\u901f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>RAG chunk<\/p>\n<\/td>\n<td>\n<p>\u6587\u6863<\/p>\n<\/td>\n<td>\n<p>\u8bed\u4e49\u7c07<\/p>\n<\/td>\n<td>\n<p>\u5c40\u90e8\u7ec6\u8282<\/p>\n<\/td>\n<td>\n<p>\u4e0a\u4e0b\u6587\u4e22\u5931<\/p>\n<\/td>\n<td>\n<p>\u53d6\u51b3\u4e8e chunk \u7b56\u7565<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 \u7528 N \u503c\u7406\u89e3\u538b\u7f29-\u667a\u80fd\u5173\u7cfb<\/h4>\n<p>def compression_intelligence_relation(N: float,<br \/>\n                                    data_complexity: float,<br \/>\n                                    available_context: int) -&gt; dict:<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u538b\u7f29\u4e0e\u667a\u80fd\u7684\u5173\u7cfb<\/p>\n<p>    \u87ba\u65cb\u89e3\u91ca&#xff1a;\u80fd\u538b\u7f29 &#061; \u627e\u5230\u4e86\u751f\u6210\u5143 &#061; \u7406\u89e3\u4e86\u7ed3\u6784 &#061; \u667a\u80fd<br \/>\n    &#034;&#034;&#034;<br \/>\n    scale &#061; math.sqrt(N)<\/p>\n<p>    # \u53ef\u538b\u7f29\u6027 &#061; 1 &#8211; (\u6570\u636e\u590d\u6742\u5ea6 \/ N)<br \/>\n    compressibility &#061; max(0, 1 &#8211; data_complexity \/ N)<\/p>\n<p>    # \u667a\u80fd\u5ea6\u91cf &#061; \u538b\u7f29\u7387 \u00d7 \u53ef\u538b\u7f29\u6027<br \/>\n    intelligence &#061; compressibility * scale<\/p>\n<p>    # \u4e0a\u4e0b\u6587\u7a97\u53e3\u4e0e\u538b\u7f29\u7684\u5173\u7cfb<br \/>\n    # \u66f4\u591a\u4e0a\u4e0b\u6587 &#061; \u66f4\u591a\u56e0\u679c\u5206\u652f &#061; \u66f4\u9ad8\u538b\u7f29\u6f5c\u529b<br \/>\n    context_factor &#061; min(1.0, available_context \/ 1000)<br \/>\n    effective_compression &#061; 1 &#043; compressibility * context_factor * scale<\/p>\n<p>    # \u5224\u65ad<br \/>\n    if intelligence &gt; 1.5:<br \/>\n        intelligence_level &#061; &#034;high&#034;<br \/>\n        interpretation &#061; &#034;\u9ad8\u667a\u80fd&#xff1a;\u80fd\u4ece\u6570\u636e\u4e2d\u627e\u5230\u6df1\u5c42\u751f\u6210\u5143&#034;<br \/>\n    elif intelligence &gt; 0.8:<br \/>\n        intelligence_level &#061; &#034;medium&#034;<br \/>\n        interpretation &#061; &#034;\u4e2d\u7b49\u667a\u80fd&#xff1a;\u80fd\u53d1\u73b0\u90e8\u5206\u6a21\u5f0f&#034;<br \/>\n    elif intelligence &gt; 0.3:<br \/>\n        intelligence_level &#061; &#034;low&#034;<br \/>\n        interpretation &#061; &#034;\u4f4e\u667a\u80fd&#xff1a;\u53ea\u80fd\u53d1\u73b0\u7b80\u5355\u91cd\u590d&#034;<br \/>\n    else:<br \/>\n        intelligence_level &#061; &#034;none&#034;<br \/>\n        interpretation &#061; &#034;\u65e0\u667a\u80fd&#xff1a;\u6570\u636e\u63a5\u8fd1\u968f\u673a&#xff0c;\u65e0\u6cd5\u538b\u7f29&#034;<\/p>\n<p>    return {<br \/>\n        &#034;N&#034;: N,<br \/>\n        &#034;data_complexity&#034;: data_complexity,<br \/>\n        &#034;compressibility&#034;: compressibility,<br \/>\n        &#034;intelligence_score&#034;: intelligence,<br \/>\n        &#034;intelligence_level&#034;: intelligence_level,<br \/>\n        &#034;interpretation&#034;: interpretation,<br \/>\n        &#034;effective_compression&#034;: effective_compression,<br \/>\n        &#034;context_utilization&#034;: context_factor<br \/>\n    }<\/p>\n<p># Demo<br \/>\nprint(&#034;\\\\n&#034; &#043; &#034;&#061;&#034; * 70)<br \/>\nprint(&#034;\u538b\u7f29-\u667a\u80fd\u5173\u7cfb\u5206\u6790:&#034;)<br \/>\nprint(&#034;&#061;&#034; * 70)<\/p>\n<p>scenarios &#061; [<br \/>\n    {&#034;name&#034;: &#034;\u968f\u673a\u566a\u58f0&#034;, &#034;N&#034;: 4.0, &#034;complexity&#034;: 3.8, &#034;context&#034;: 100},<br \/>\n    {&#034;name&#034;: &#034;\u81ea\u7136\u8bed\u8a00\u6587\u672c&#034;, &#034;N&#034;: 4.0, &#034;complexity&#034;: 2.0, &#034;context&#034;: 2000},<br \/>\n    {&#034;name&#034;: &#034;\u4ee3\u7801&#034;, &#034;N&#034;: 4.0, &#034;complexity&#034;: 1.5, &#034;context&#034;: 5000},<br \/>\n    {&#034;name&#034;: &#034;\u7ed3\u6784\u5316\u65e5\u5fd7&#034;, &#034;N&#034;: 4.0, &#034;complexity&#034;: 0.8, &#034;context&#034;: 10000},<br \/>\n    {&#034;name&#034;: &#034;DNA \u5e8f\u5217&#034;, &#034;N&#034;: 8.0, &#034;complexity&#034;: 2.0, &#034;context&#034;: 50000},<br \/>\n]<\/p>\n<p>print(f&#034;\\\\n{&#039;\u573a\u666f&#039;:&gt;20} | {&#039;\u53ef\u538b\u7f29\u6027&#039;:&gt;8} | {&#039;\u667a\u80fd\u5206&#039;:&gt;6} | {&#039;\u667a\u80fd\u7b49\u7ea7&#039;:&gt;10} | \u89e3\u91ca&#034;)<br \/>\nprint(&#034;-&#034; * 100)<\/p>\n<p>for s in scenarios:<br \/>\n    result &#061; compression_intelligence_relation(<br \/>\n        s[&#034;N&#034;], s[&#034;complexity&#034;], s[&#034;context&#034;]<br \/>\n    )<br \/>\n    print(f&#034;{s[&#039;name&#039;]:&gt;20} | &#034;<br \/>\n          f&#034;{result[&#039;compressibility&#039;]:&gt;8.3f} | &#034;<br \/>\n          f&#034;{result[&#039;intelligence_score&#039;]:&gt;6.3f} | &#034;<br \/>\n          f&#034;{result[&#039;intelligence_level&#039;]:&gt;10} | &#034;<br \/>\n          f&#034;{result[&#039;interpretation&#039;][:30]}&#034;)<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\u538b\u7f29-\u667a\u80fd\u5173\u7cfb\u5206\u6790:<br \/>\n&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>                \u573a\u666f |  \u53ef\u538b\u7f29\u6027 |   \u667a\u80fd\u5206 |   \u667a\u80fd\u7b49\u7ea7 | \u89e3\u91ca<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n           \u968f\u673a\u566a\u58f0 |    0.050 |  0.100 |       low | \u4f4e\u667a\u80fd&#xff1a;\u53ea\u80fd\u53d1\u73b0\u7b80\u5355\u91cd\u590d<br \/>\n       \u81ea\u7136\u8bed\u8a00\u6587\u672c |    0.500 |  1.000 |    medium | \u4e2d\u7b49\u667a\u80fd&#xff1a;\u80fd\u53d1\u73b0\u90e8\u5206\u6a21\u5f0f<br \/>\n               \u4ee3\u7801 |    0.625 |  1.250 |    medium | \u4e2d\u7b49\u667a\u80fd&#xff1a;\u80fd\u53d1\u73b0\u90e8\u5206\u6a21\u5f0f<br \/>\n       \u7ed3\u6784\u5316\u65e5\u5fd7 |    0.800 |  1.600 |      high | \u9ad8\u667a\u80fd&#xff1a;\u80fd\u4ece\u6570\u636e\u4e2d\u627e\u5230\u6df1\u5c42\u751f\u6210\u5143<br \/>\n           DNA \u5e8f\u5217 |    0.750 |  2.121 |      high | \u9ad8\u667a\u80fd&#xff1a;\u80fd\u4ece\u6570\u636e\u4e2d\u627e\u5230\u6df1\u5c42\u751f\u6210\u5143<\/p>\n<hr \/>\n<h3>\u56db\u3001\u5de5\u7a0b\u843d\u5730&#xff1a;3 \u4e2a\u76f4\u63a5\u7528\u8d77\u6765\u7684\u6a21\u5f0f<\/h3>\n<h4>\u6a21\u5f0f 1&#xff1a;\u81ea\u9002\u5e94 KV Cache \u538b\u7f29<\/h4>\n<p>class AdaptiveKVCache:<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u81ea\u9002\u5e94 KV Cache \u538b\u7f29<\/p>\n<p>    \u6839\u636e\u6ce8\u610f\u529b\u6a21\u5f0f\u52a8\u6001\u8c03\u6574\u538b\u7f29\u7b56\u7565<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    def __init__(self, N: float &#061; 4.0, max_cache_size: int &#061; 1000):<br \/>\n        self.N &#061; N<br \/>\n        self.scale &#061; math.sqrt(N)<br \/>\n        self.max_cache_size &#061; max_cache_size<br \/>\n        self.cache &#061; {}<br \/>\n        self.access_pattern &#061; {}  # token -&gt; \u88ab\u6ce8\u610f\u529b\u6743\u91cd<br \/>\n        self.compression_threshold &#061; 0.3<\/p>\n<p>    def store_kv(self, token_id: str, layer: int, head: int, k: complex, v: complex):<br \/>\n        &#034;&#034;&#034;\u5b58\u50a8 KV&#034;&#034;&#034;<br \/>\n        key &#061; f&#034;{token_id}_{layer}_{head}&#034;<\/p>\n<p>        self.cache[key] &#061; {<br \/>\n            &#034;k&#034;: k,<br \/>\n            &#034;v&#034;: v,<br \/>\n            &#034;token_id&#034;: token_id,<br \/>\n            &#034;layer&#034;: layer,<br \/>\n            &#034;head&#034;: head,<br \/>\n            &#034;access_count&#034;: 0,<br \/>\n            &#034;last_access&#034;: 0<br \/>\n        }<\/p>\n<p>    def access_kv(self, token_id: str, layer: int, head: int, attention_weight: float):<br \/>\n        &#034;&#034;&#034;\u8bbf\u95ee KV&#xff08;\u8bb0\u5f55\u6ce8\u610f\u529b\u6743\u91cd&#xff09;&#034;&#034;&#034;<br \/>\n        key &#061; f&#034;{token_id}_{layer}_{head}&#034;<\/p>\n<p>        if key in self.cache:<br \/>\n            self.cache[key][&#034;access_count&#034;] &#043;&#061; 1<br \/>\n            self.cache[key][&#034;last_access&#034;] &#061; time_module.time()<\/p>\n<p>        # \u8bb0\u5f55\u6ce8\u610f\u529b\u6a21\u5f0f<br \/>\n        if token_id not in self.access_pattern:<br \/>\n            self.access_pattern[token_id] &#061; []<br \/>\n        self.access_pattern[token_id].append(attention_weight)<\/p>\n<p>    def compress_if_needed(self) -&gt; dict:<br \/>\n        &#034;&#034;&#034;\u5982\u679c\u7f13\u5b58\u8d85\u8fc7\u9650\u5236&#xff0c;\u6267\u884c\u538b\u7f29&#034;&#034;&#034;<br \/>\n        if len(self.cache) &lt;&#061; self.max_cache_size:<br \/>\n            return {&#034;action&#034;: &#034;no_compression_needed&#034;}<\/p>\n<p>        # \u7b56\u7565 1&#xff1a;\u4e22\u5f03\u4f4e\u6ce8\u610f\u529b token \u7684 KV<br \/>\n        token_importance &#061; {}<br \/>\n        for token_id, weights in self.access_pattern.items():<br \/>\n            token_importance[token_id] &#061; sum(weights) \/ len(weights) if weights else 0<\/p>\n<p>        # \u6392\u5e8f<br \/>\n        sorted_tokens &#061; sorted(token_importance.items(), key&#061;lambda x: x[1])<\/p>\n<p>        # \u5220\u9664\u6700\u4e0d\u91cd\u8981\u7684 30%<br \/>\n        to_delete_count &#061; int(len(self.cache) * 0.3)<br \/>\n        deleted &#061; 0<\/p>\n<p>        for token_id, importance in sorted_tokens:<br \/>\n            if deleted &gt;&#061; to_delete_count:<br \/>\n                break<\/p>\n<p>            # \u5220\u9664\u8be5 token \u7684\u6240\u6709 KV<br \/>\n            keys_to_delete &#061; [k for k in self.cache if self.cache[k][&#034;token_id&#034;] &#061;&#061; token_id]<br \/>\n            for key in keys_to_delete:<br \/>\n                del self.cache[key]<br \/>\n                deleted &#043;&#061; 1<\/p>\n<p>        return {<br \/>\n            &#034;action&#034;: &#034;compressed&#034;,<br \/>\n            &#034;deleted_entries&#034;: deleted,<br \/>\n            &#034;remaining_entries&#034;: len(self.cache),<br \/>\n            &#034;compression_ratio&#034;: len(self.cache) \/ max(1, len(self.cache) &#043; deleted)<br \/>\n        }<\/p>\n<h4>\u6a21\u5f0f 2&#xff1a;\u65e5\u5fd7\u56e0\u679c\u538b\u7f29<\/h4>\n<p>class LogCausalCompressor:<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u65e5\u5fd7\u56e0\u679c\u538b\u7f29\u5668<\/p>\n<p>    \u4e0d\u662f\u6309\u5b57\u8282\u538b\u7f29&#xff0c;\u800c\u662f\u6309\u56e0\u679c\u6a21\u5f0f\u538b\u7f29<br \/>\n    &#034;&#034;&#034;<\/p>\n<p>    def __init__(self, N: float &#061; 4.0):<br \/>\n        self.N &#061; N<br \/>\n        self.scale &#061; math.sqrt(N)<br \/>\n        self.patterns &#061; {}  # \u65e5\u5fd7\u6a21\u5f0f -&gt; \u51fa\u73b0\u6b21\u6570<br \/>\n        self.compressed_logs &#061; []<\/p>\n<p>    def ingest_log(self, log_line: str):<br \/>\n        &#034;&#034;&#034;\u6444\u5165\u65e5\u5fd7&#034;&#034;&#034;<br \/>\n        # \u63d0\u53d6\u56e0\u679c\u6a21\u5f0f&#xff08;\u7b80\u5316&#xff1a;\u7528\u5173\u952e\u8bcd&#xff09;<br \/>\n        pattern &#061; self._extract_pattern(log_line)<\/p>\n<p>        if pattern in self.patterns:<br \/>\n            self.patterns[pattern] &#043;&#061; 1<br \/>\n        else:<br \/>\n            self.patterns[pattern] &#061; 1<br \/>\n            # \u65b0\u6a21\u5f0f\u7684\u7b2c\u4e00\u4e2a\u5b9e\u4f8b\u5b8c\u6574\u5b58\u50a8<br \/>\n            self.compressed_logs.append({<br \/>\n                &#034;pattern&#034;: pattern,<br \/>\n                &#034;first_instance&#034;: log_line,<br \/>\n                &#034;count&#034;: 1,<br \/>\n                &#034;timestamps&#034;: [time_module.time()]<br \/>\n            })<\/p>\n<p>    def _extract_pattern(self, log_line: str) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u63d0\u53d6\u65e5\u5fd7\u6a21\u5f0f&#xff08;\u7b80\u5316&#xff09;&#034;&#034;&#034;<br \/>\n        # \u79fb\u9664\u53d8\u91cf\u90e8\u5206&#xff08;\u6570\u5b57\u3001UUID \u7b49&#xff09;<br \/>\n        import re<br \/>\n        pattern &#061; re.sub(r&#039;\\\\d&#043;&#039;, &#039;&lt;NUM&gt;&#039;, log_line)<br \/>\n        pattern &#061; re.sub(r&#039;[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}&#039;,<br \/>\n                        &#039;&lt;UUID&gt;&#039;, pattern)<br \/>\n        pattern &#061; re.sub(r&#039;\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}&#039;, &#039;&lt;TIME&gt;&#039;, pattern)<br \/>\n        return pattern<\/p>\n<p>    def compress(self) -&gt; dict:<br \/>\n        &#034;&#034;&#034;\u538b\u7f29\u65e5\u5fd7&#034;&#034;&#034;<br \/>\n        total_lines &#061; sum(p[&#034;count&#034;] for p in self.compressed_logs)<br \/>\n        unique_patterns &#061; len(self.compressed_logs)<\/p>\n<p>        # \u538b\u7f29\u7387 &#061; \u603b\u884c\u6570 \/ \u5b58\u50a8\u7684\u6a21\u5f0f\u6570<br \/>\n        compression_ratio &#061; total_lines \/ max(1, unique_patterns)<\/p>\n<p>        # \u627e\u5230\u9ad8\u9891\u6a21\u5f0f<br \/>\n        high_freq_patterns &#061; [p for p in self.compressed_logs if p[&#034;count&#034;] &gt; 10]<\/p>\n<p>        return {<br \/>\n            &#034;total_log_lines&#034;: total_lines,<br \/>\n            &#034;unique_patterns&#034;: unique_patterns,<br \/>\n            &#034;compression_ratio&#034;: compression_ratio,<br \/>\n            &#034;high_frequency_patterns&#034;: len(high_freq_patterns),<br \/>\n            &#034;top_patterns&#034;: sorted(self.compressed_logs,<br \/>\n                                key&#061;lambda x: x[&#034;count&#034;],<br \/>\n                                reverse&#061;True)[:5]<br \/>\n        }<\/p>\n<h4>\u6a21\u5f0f 3&#xff1a;RAG Chunk \u7684\u56e0\u679c\u5207\u5206<\/h4>\n<p>def causal_chunk_split(text: str, N: float &#061; 4.0,<br \/>\n                      max_chunk_size: int &#061; 512) -&gt; List[dict]:<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u56e0\u679c\u611f\u77e5\u7684\u6587\u6863\u5207\u5206<\/p>\n<p>    \u87ba\u65cb\u89e3\u91ca&#xff1a;\u5728\u56e0\u679c\u94fe\u7684&#034;\u81ea\u7136\u65ad\u70b9&#034;\u5207\u5206<br \/>\n    \u65ad\u70b9 &#061; \u865a\u90e8\u5bc6\u5ea6\u4f4e\u7684\u533a\u57df&#xff08;\u786e\u5b9a\u6027\u9ad8\u7684\u5730\u65b9&#xff09;<br \/>\n    &#034;&#034;&#034;<br \/>\n    scale &#061; math.sqrt(N)<\/p>\n<p>    # \u6309\u53e5\u5b50\u5206\u5272<br \/>\n    sentences &#061; text.split(&#039;. &#039;)<\/p>\n<p>    chunks &#061; []<br \/>\n    current_chunk &#061; []<br \/>\n    current_imag_density &#061; 0.0<\/p>\n<p>    for sent in sentences:<br \/>\n        # \u8ba1\u7b97\u53e5\u5b50\u7684&#034;\u865a\u90e8\u5bc6\u5ea6&#034;&#xff08;\u4e0d\u786e\u5b9a\u6027\u6307\u6807&#xff09;<br \/>\n        # \u7b80\u5316&#xff1a;\u7528\u53e5\u5b50\u957f\u5ea6\u548c\u7279\u6b8a\u8bcd\u5224\u65ad<br \/>\n        uncertainty_words &#061; [&#039;\u53ef\u80fd&#039;, &#039;\u4e5f\u8bb8&#039;, &#039;\u5927\u6982&#039;, &#039;\u5982\u679c&#039;, &#039;\u5047\u8bbe&#039;, &#039;\u4e0d\u786e\u5b9a&#039;,<br \/>\n                           &#039;maybe&#039;, &#039;perhaps&#039;, &#039;if&#039;, &#039;suppose&#039;, &#039;uncertain&#039;]<\/p>\n<p>        imag_density &#061; sum(1 for w in uncertainty_words if w.lower() in sent.lower())<br \/>\n        imag_density &#043;&#061; len(sent) \/ 1000  # \u957f\u5ea6\u4e5f\u8d21\u732e\u865a\u90e8<\/p>\n<p>        current_chunk.append(sent)<br \/>\n        current_imag_density &#043;&#061; imag_density<\/p>\n<p>        # \u5207\u5206\u6761\u4ef6&#xff1a;<br \/>\n        # 1. chunk \u5927\u5c0f\u8fbe\u5230 max<br \/>\n        # 2. \u865a\u90e8\u5bc6\u5ea6\u7a81\u7136\u964d\u4f4e&#xff08;\u786e\u5b9a\u6027\u6062\u590d &#061; \u56e0\u679c\u65ad\u70b9&#xff09;<br \/>\n        chunk_text &#061; &#039;. &#039;.join(current_chunk)<\/p>\n<p>        should_split &#061; False<\/p>\n<p>        if len(chunk_text) &gt;&#061; max_chunk_size:<br \/>\n            should_split &#061; True<br \/>\n        elif len(current_chunk) &gt; 2 and imag_density &lt; current_imag_density \/ len(current_chunk) * 0.5:<br \/>\n            # \u865a\u90e8\u5bc6\u5ea6\u9aa4\u964d &#061; \u56e0\u679c\u65ad\u70b9<br \/>\n            should_split &#061; True<\/p>\n<p>        if should_split:<br \/>\n            chunks.append({<br \/>\n                &#034;text&#034;: chunk_text,<br \/>\n                &#034;sentences&#034;: len(current_chunk),<br \/>\n                &#034;imag_density&#034;: current_imag_density,<br \/>\n                &#034;causal_boundary&#034;: imag_density &lt; current_imag_density \/ max(1, len(current_chunk))<br \/>\n            })<\/p>\n<p>            current_chunk &#061; []<br \/>\n            current_imag_density &#061; 0.0<\/p>\n<p>    # \u6700\u540e\u4e00\u4e2a chunk<br \/>\n    if current_chunk:<br \/>\n        chunk_text &#061; &#039;. &#039;.join(current_chunk)<br \/>\n        chunks.append({<br \/>\n            &#034;text&#034;: chunk_text,<br \/>\n            &#034;sentences&#034;: len(current_chunk),<br \/>\n            &#034;imag_density&#034;: current_imag_density,<br \/>\n            &#034;causal_boundary&#034;: False<br \/>\n        })<\/p>\n<p>    return chunks<\/p>\n<p># Demo<br \/>\nprint(&#034;\\\\n&#034; &#043; &#034;&#061;&#034; * 70)<br \/>\nprint(&#034;RAG \u56e0\u679c\u5207\u5206 Demo:&#034;)<br \/>\nprint(&#034;&#061;&#034; * 70)<\/p>\n<p>sample_text &#061; &#034;&#034;&#034;<br \/>\n\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u3002\u7cfb\u7edf\u9a8c\u8bc1\u51ed\u636e\u3002\u5982\u679c\u51ed\u636e\u6b63\u786e&#xff0c;\u751f\u6210 JWT token\u3002<br \/>\n\u4e5f\u8bb8\u7528\u6237\u5fd8\u8bb0\u4e86\u5bc6\u7801\u3002\u7cfb\u7edf\u53d1\u9001\u91cd\u7f6e\u90ae\u4ef6\u3002\u7528\u6237\u70b9\u51fb\u94fe\u63a5\u3002<br \/>\n\u5047\u8bbe\u94fe\u63a5\u6709\u6548&#xff0c;\u7528\u6237\u8bbe\u7f6e\u65b0\u5bc6\u7801\u3002\u5bc6\u7801\u5fc5\u987b\u7b26\u5408\u590d\u6742\u5ea6\u8981\u6c42\u3002<br \/>\n\u5982\u679c\u4e0d\u7b26\u5408&#xff0c;\u7cfb\u7edf\u8fd4\u56de\u9519\u8bef\u3002\u7528\u6237\u91cd\u8bd5\u3002\u8fd9\u6b21\u5bc6\u7801\u5f3a\u5ea6\u8db3\u591f\u3002<br \/>\n\u7cfb\u7edf\u66f4\u65b0\u5bc6\u7801\u3002\u7528\u6237\u91cd\u65b0\u767b\u5f55\u3002\u767b\u5f55\u6210\u529f\u3002<br \/>\n\u7cfb\u7edf\u52a0\u8f7d\u7528\u6237\u914d\u7f6e\u3002\u914d\u7f6e\u5305\u62ec\u4e3b\u9898\u3001\u8bed\u8a00\u3001\u901a\u77e5\u504f\u597d\u3002<br \/>\n\u4e5f\u8bb8\u914d\u7f6e\u52a0\u8f7d\u5931\u8d25\u3002\u7cfb\u7edf\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002\u9ed8\u8ba4\u503c\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u3002<br \/>\n\u7528\u6237\u6d4f\u89c8\u5546\u54c1\u5217\u8868\u3002\u5982\u679c\u5217\u8868\u4e3a\u7a7a&#xff0c;\u663e\u793a\u63a8\u8350\u5546\u54c1\u3002<br \/>\n\u7528\u6237\u70b9\u51fb\u5546\u54c1\u3002\u7cfb\u7edf\u52a0\u8f7d\u5546\u54c1\u8be6\u60c5\u3002\u8be6\u60c5\u5305\u62ec\u4ef7\u683c\u3001\u5e93\u5b58\u3001\u63cf\u8ff0\u3002<br \/>\n&#034;&#034;&#034;<\/p>\n<p>chunks &#061; causal_chunk_split(sample_text, N&#061;4.0, max_chunk_size&#061;200)<\/p>\n<p>print(f&#034;\\\\n  \u6587\u6863\u5207\u5206\u4e3a {len(chunks)} \u4e2a chunk:\\\\n&#034;)<br \/>\nfor i, chunk in enumerate(chunks):<br \/>\n    print(f&#034;  Chunk {i&#043;1}:&#034;)<br \/>\n    print(f&#034;    \u53e5\u5b50\u6570: {chunk[&#039;sentences&#039;]}&#034;)<br \/>\n    print(f&#034;    \u865a\u90e8\u5bc6\u5ea6: {chunk[&#039;imag_density&#039;]:.3f}&#034;)<br \/>\n    print(f&#034;    \u56e0\u679c\u8fb9\u754c: {&#039;\u2705&#039; if chunk[&#039;causal_boundary&#039;] else &#039;\u274c&#039;}&#034;)<br \/>\n    print(f&#034;    \u6587\u672c: {chunk[&#039;text&#039;][:80]}&#8230;&#034;)<br \/>\n    print()<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u5de5\u7a0b\u907f\u5751<\/h3>\n<table>\n<tr>\n<p>\u5751<\/p>\n<p>\u8bf4\u660e<\/p>\n<p>\u89e3\u6cd5<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u76f2\u76ee\u8ffd\u6c42\u9ad8\u538b\u7f29\u7387<\/p>\n<\/td>\n<td>\n<p>\u538b\u7f29\u7387\u8d8a\u9ad8&#xff0c;\u4fe1\u606f\u635f\u5931\u8d8a\u5927&#xff0c;\u6a21\u578b&#034;\u5e7b\u89c9&#034;\u8d8a\u591a<\/p>\n<\/td>\n<td>\n<p>\u76d1\u63a7\u865a\u90e8\u635f\u5931&#xff0c;\u8bbe\u9608\u503c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>KV Cache \u4e0d\u538b\u7f29<\/p>\n<\/td>\n<td>\n<p>\u957f\u4e0a\u4e0b\u6587\u663e\u5b58\u7206\u70b8<\/p>\n<\/td>\n<td>\n<p>\u6309\u6ce8\u610f\u529b\u6743\u91cd\u4e22\u5f03\u4f4e\u91cd\u8981\u6027 token<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>gzip \u4e00\u5207<\/p>\n<\/td>\n<td>\n<p>gzip \u53ea\u505a\u5b57\u8282\u7ea7&#xff0c;\u4e0d\u7406\u89e3\u8bed\u4e49<\/p>\n<\/td>\n<td>\n<p>\u5148\u505a\u8bed\u4e49\u805a\u7c7b&#xff0c;\u518d gzip<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8bb0\u5fc6\u6c38\u4e0d\u5220\u9664<\/p>\n<\/td>\n<td>\n<p>\u5b58\u50a8\u81a8\u80c0&#xff0c;\u68c0\u7d22\u53d8\u6162<\/p>\n<\/td>\n<td>\n<p>\u8bbe\u865a\u90e8\u8870\u51cf &#043; \u76f8\u4f3c\u5408\u5e76<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>RAG chunk \u56fa\u5b9a\u5927\u5c0f<\/p>\n<\/td>\n<td>\n<p>\u5728\u56e0\u679c\u94fe\u4e2d\u95f4\u5207\u65ad &#061; \u4e22\u5931\u4e0a\u4e0b\u6587<\/p>\n<\/td>\n<td>\n<p>\u5728\u865a\u90e8\u5bc6\u5ea6\u4f4e\u7684&#034;\u65ad\u70b9&#034;\u5207\u5206<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u7d22\u5f15\u8d8a\u591a\u8d8a\u597d<\/p>\n<\/td>\n<td>\n<p>\u5199\u5165\u53d8\u6162&#xff0c;\u5b58\u50a8\u7206\u70b8<\/p>\n<\/td>\n<td>\n<p>\u7d22\u5f15 &#061; \u538b\u7f29&#xff0c;\u53ea\u7d22\u5f15\u9ad8\u865a\u90e8\u5b57\u6bb5<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516d\u3001\u672c\u7bc7\u7ed3\u8bba<\/h3>\n<table>\n<tr>\n<p>\u8981\u70b9<\/p>\n<p>\u4e00\u53e5\u8bdd<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u538b\u7f29<\/p>\n<\/td>\n<td>\n<p>\u5c06\u56e0\u679c\u94fe\u4e2d\u76f8\u4f3c\u5206\u652f\u6298\u53e0\u56de\u751f\u6210\u5143<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u538b\u7f29\u7387<\/p>\n<\/td>\n<td>\n<p>R &#061; N \/ (1 &#043; log_N(\u76f8\u4f3c\u5206\u652f\u6570))<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>KV Cache<\/p>\n<\/td>\n<td>\n<p>\u5df2\u574d\u7f29\u56e0\u679c\u7684\u538b\u7f29\u5feb\u7167<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u8bb0\u5fc6<\/p>\n<\/td>\n<td>\n<p>\u865a\u90e8\u8870\u51cf\u540e\u7684\u538b\u7f29\u5b58\u50a8<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u667a\u80fd<\/p>\n<\/td>\n<td>\n<p>\u80fd\u538b\u7f29 &#061; \u627e\u5230\u751f\u6210\u5143 &#061; \u7406\u89e3\u7ed3\u6784<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u4ee3\u4ef7<\/p>\n<\/td>\n<td>\n<p>\u538b\u7f29\u635f\u5931 &#061; \u4e22\u5f03\u7684\u865a\u90e8\u4e0d\u53ef\u6062\u590d<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8bb0\u4f4f\u8fd9\u6761\u516c\u5f0f&#xff1a;<\/p>\n<p>\u538b\u7f29\u7387 R &#061; N \/ (1 &#043; log_N(\u03a3 similarity(z_i, z_gen)))<\/p>\n<p>\u4f60\u538b\u7f29\u5f97\u8d8a\u597d&#xff0c;\u8bf4\u660e\u4f60\u8d8a\u7406\u89e3\u6570\u636e\u7684\u56e0\u679c\u7ed3\u6784\u2014\u2014\u8fd9\u5c31\u662f\u667a\u80fd\u7684\u672c\u8d28\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u4e0b\u7bc7\u9884\u544a &amp; \u5bfc\u822a<\/h3>\n<p>\u4e0b\u4e00\u7bc7&#xff1a;\u300a\u8fb9\u754c\u4e0e\u514d\u75ab&#xff1a;\u4ece\u9632\u706b\u5899\u5230\u7c7b\u578b\u7cfb\u7edf\u5230 RLHF \u7684\u7edf\u4e00\u89c6\u89d2\u300b<\/p>\n<ul>\n<li>\u4e3a\u4ec0\u4e48\u9632\u706b\u5899\u3001\u7c7b\u578b\u7cfb\u7edf\u3001RLHF \u90fd\u662f&#034;\u8fb9\u754c&#034;<\/li>\n<li>\u514d\u75ab\u7cfb\u7edf &#061; \u56e0\u679c\u94fe\u7684\u5f02\u5e38\u68c0\u6d4b<\/li>\n<li>\u7c7b\u578b\u7cfb\u7edf &#061; \u7f16\u8bd1\u671f\u7684\u56e0\u679c\u7ea6\u675f<\/li>\n<li>RLHF &#061; \u540e\u8bad\u7ec3\u671f\u7684\u56e0\u679c\u4fee\u6b63<\/li>\n<li>\u7528 N \u503c\u8ba1\u7b97\u6700\u4f18\u5b89\u5168\u8fb9\u754c<\/li>\n<\/ul>\n<hr \/>\n<p>\u6807\u7b7e&#xff1a;#\u4eba\u5de5\u667a\u80fd #\u540e\u7aef\u5f00\u53d1 #\u8f6f\u4ef6\u5de5\u7a0b #\u67b6\u6784\u8bbe\u8ba1 #Transformer #\u538b\u7f29\u7b97\u6cd5 #\u8bb0\u5fc6\u7cfb\u7edf<\/p>\n<p>\u5206\u7c7b&#xff1a;\u540e\u7aef\u5f00\u53d1 \/ \u8f6f\u4ef6\u5de5\u7a0b \/ \u67b6\u6784\u8bbe\u8ba1<\/p>\n<hr \/>\n<p>\u538b\u7f29\u4e0d\u662f\u4e22\u5f03&#xff0c;\u662f\u63d0\u70bc\u3002gzip \u63d0\u70bc\u5b57\u8282\u91cd\u590d&#xff0c;Transformer \u63d0\u70bc\u6ce8\u610f\u529b\u6a21\u5f0f&#xff0c;\u4eba\u8111\u63d0\u70bc\u4e8b\u4ef6\u672c\u8d28\u3002\u80fd\u538b\u7f29\u7684\u56e0\u679c\u624d\u662f\u53ef\u7406\u89e3\u7684\u56e0\u679c\u3002<\/p>\n<p>\u4e0b\u4e00\u7bc7\u8bb2&#034;\u8fb9\u754c\u4e0e\u514d\u75ab&#034;\u2014\u2014\u4f60\u4f1a\u53d1\u73b0\u9632\u706b\u5899\u548c\u7c7b\u578b\u7cfb\u7edf\u662f\u540c\u4e00\u4e2a\u4e1c\u897f&#xff1a;\u56e0\u679c\u7684\u8fb9\u754c\u5b88\u62a4\u8005\u3002<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u53e5\u8bdd\u7ed3\u8bba&#xff1a;\u538b\u7f29  \u56e0\u679c\u94fe\u5728\u87ba\u65cb\u5c55\u5f00\u4e2d&#xff0c;\u5c06\u5df2\u786e\u5b9a\u7684\u4f4e\u865a\u90e8\u5206\u652f\u6298\u53e0\u56de\u751f\u6210\u5143&#xff0c;\u7528\u66f4\u77ed\u7684\u7f16\u7801\u66ff\u4ee3\u5197\u4f59\u5c55\u5f00\u3002gzip \u7684 LZ77\u3001Transformer \u7684 KV Cache\u3001\u4eba\u8111\u7684\u8bb0\u5fc6\u3001\u6570\u636e\u5e93\u7684\u7d22\u5f15\u2014\u2014\u5168\u90fd\u662f\u540c\u4e00\u4ef6\u4e8b&#xff1a;\u7528 I\u00b2  -N \u628a\u9ad8\u7ef4\u56e0\u679c\u6d41\u538b\u7f29\u5230\u4f4e\u7ef4\u8868\u793a&#xff0c;\u4ee3\u4ef7\u662f\u4e22\u5931\u90e8\u5206\u53ef\u5c55\u5f00\u6027\u3002\u4e00\u3001\u6280\u672f\u75db\u70b9&#xff1a;\u4e3a\u4ec0\u4e48\u4f60\u7684\u7cfb\u7edf\u603b\u5728\\&#8221;\u91cd\u590d\u8ba1\u7b97\\&#8221;\u548c\\&#8221;\u4e22\u4e0a\u4e0b\u6587\\&#8221;\u4e4b\u95f4\u4e24\u96be&#xff1f;\u4f60\u4e00\u5b9a\u9047\u5230\u8fc7\u8fd9\u4e9b\u573a\u666f&amp;#xff<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[841,50,707,86,383],"topic":[],"class_list":["post-117738","post","type-post","status-publish","format-standard","hentry","category-server","tag-transformer","tag-50","tag-707","tag-86","tag-383"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\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.wsisp.com\/helps\/117738.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u53e5\u8bdd\u7ed3\u8bba&#xff1a;\u538b\u7f29 \u56e0\u679c\u94fe\u5728\u87ba\u65cb\u5c55\u5f00\u4e2d&#xff0c;\u5c06\u5df2\u786e\u5b9a\u7684\u4f4e\u865a\u90e8\u5206\u652f\u6298\u53e0\u56de\u751f\u6210\u5143&#xff0c;\u7528\u66f4\u77ed\u7684\u7f16\u7801\u66ff\u4ee3\u5197\u4f59\u5c55\u5f00\u3002gzip \u7684 LZ77\u3001Transformer \u7684 KV Cache\u3001\u4eba\u8111\u7684\u8bb0\u5fc6\u3001\u6570\u636e\u5e93\u7684\u7d22\u5f15\u2014\u2014\u5168\u90fd\u662f\u540c\u4e00\u4ef6\u4e8b&#xff1a;\u7528 I\u00b2 -N \u628a\u9ad8\u7ef4\u56e0\u679c\u6d41\u538b\u7f29\u5230\u4f4e\u7ef4\u8868\u793a&#xff0c;\u4ee3\u4ef7\u662f\u4e22\u5931\u90e8\u5206\u53ef\u5c55\u5f00\u6027\u3002\u4e00\u3001\u6280\u672f\u75db\u70b9&#xff1a;\u4e3a\u4ec0\u4e48\u4f60\u7684\u7cfb\u7edf\u603b\u5728&quot;\u91cd\u590d\u8ba1\u7b97&quot;\u548c&quot;\u4e22\u4e0a\u4e0b\u6587&quot;\u4e4b\u95f4\u4e24\u96be&#xff1f;\u4f60\u4e00\u5b9a\u9047\u5230\u8fc7\u8fd9\u4e9b\u573a\u666f&amp;#xff\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117738.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-25T00:48:55+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117738.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117738.html\",\"name\":\"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-25T00:48:55+00:00\",\"dateModified\":\"2026-10-25T00:48:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117738.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117738.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117738.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/117738.html","og_locale":"zh_CN","og_type":"article","og_title":"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u53e5\u8bdd\u7ed3\u8bba&#xff1a;\u538b\u7f29 \u56e0\u679c\u94fe\u5728\u87ba\u65cb\u5c55\u5f00\u4e2d&#xff0c;\u5c06\u5df2\u786e\u5b9a\u7684\u4f4e\u865a\u90e8\u5206\u652f\u6298\u53e0\u56de\u751f\u6210\u5143&#xff0c;\u7528\u66f4\u77ed\u7684\u7f16\u7801\u66ff\u4ee3\u5197\u4f59\u5c55\u5f00\u3002gzip \u7684 LZ77\u3001Transformer \u7684 KV Cache\u3001\u4eba\u8111\u7684\u8bb0\u5fc6\u3001\u6570\u636e\u5e93\u7684\u7d22\u5f15\u2014\u2014\u5168\u90fd\u662f\u540c\u4e00\u4ef6\u4e8b&#xff1a;\u7528 I\u00b2 -N \u628a\u9ad8\u7ef4\u56e0\u679c\u6d41\u538b\u7f29\u5230\u4f4e\u7ef4\u8868\u793a&#xff0c;\u4ee3\u4ef7\u662f\u4e22\u5931\u90e8\u5206\u53ef\u5c55\u5f00\u6027\u3002\u4e00\u3001\u6280\u672f\u75db\u70b9&#xff1a;\u4e3a\u4ec0\u4e48\u4f60\u7684\u7cfb\u7edf\u603b\u5728\"\u91cd\u590d\u8ba1\u7b97\"\u548c\"\u4e22\u4e0a\u4e0b\u6587\"\u4e4b\u95f4\u4e24\u96be&#xff1f;\u4f60\u4e00\u5b9a\u9047\u5230\u8fc7\u8fd9\u4e9b\u573a\u666f&amp;#xff","og_url":"https:\/\/www.wsisp.com\/helps\/117738.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-25T00:48:55+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"17 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117738.html","url":"https:\/\/www.wsisp.com\/helps\/117738.html","name":"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-25T00:48:55+00:00","dateModified":"2026-10-25T00:48:55+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117738.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117738.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117738.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u56e0\u679c\u538b\u7f29\uff1a\u4ece gzip \u5230 Transformer KV Cache \u5230\u8bb0\u5fc6\u7684\u7edf\u4e00\u89c6\u89d2"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117738"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117738\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117738"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}